refactor WikipediaPlugin imports
This commit is contained in:
parent
a5ce9587c0
commit
49b3292574
8 changed files with 84 additions and 59 deletions
|
@ -39,6 +39,7 @@ import net.osmand.plus.myplaces.FavoritesActivity;
|
|||
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.quickaction.QuickActionType;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
|
@ -555,6 +556,14 @@ public abstract class OsmandPlugin {
|
|||
protected void newDownloadIndexes(Fragment fragment) {
|
||||
}
|
||||
|
||||
protected void prepareExtraTopPoiFilters(PoiUIFilter ... filters) {
|
||||
}
|
||||
|
||||
protected String getMapObjectsLocale(Set<String> supportedLocales,
|
||||
String preferredLocale) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> indexingFiles(IProgress progress) {
|
||||
return null;
|
||||
}
|
||||
|
@ -821,11 +830,28 @@ public abstract class OsmandPlugin {
|
|||
}
|
||||
|
||||
public static void onNewDownloadIndexes(Fragment fragment) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
for (OsmandPlugin plugin : getAvailablePlugins()) {
|
||||
plugin.newDownloadIndexes(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onPrepareExtraTopPoiFilters(PoiUIFilter ... filters) {
|
||||
for (OsmandPlugin plugin : getAvailablePlugins()) {
|
||||
plugin.prepareExtraTopPoiFilters(filters);
|
||||
}
|
||||
}
|
||||
|
||||
public static String onGetMapObjectsLocale(Set<String> supportedLocales,
|
||||
String preferredLocale) {
|
||||
for (OsmandPlugin plugin : getAvailablePlugins()) {
|
||||
String locale = plugin.getMapObjectsLocale(supportedLocales, preferredLocale);
|
||||
if (locale != null) {
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
return preferredLocale;
|
||||
}
|
||||
|
||||
public static Collection<DashFragmentData> getPluginsCardsList() {
|
||||
HashSet<DashFragmentData> collection = new HashSet<>();
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
|
|
|
@ -44,8 +44,6 @@ import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
|
|||
import net.osmand.plus.wikipedia.WikiArticleHelper;
|
||||
import net.osmand.plus.wikipedia.WikipediaArticleWikiLinkFragment;
|
||||
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
|
||||
import net.osmand.plus.wikipedia.WikipediaPlugin;
|
||||
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
|
||||
|
@ -408,9 +406,8 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
}
|
||||
|
||||
if (amenity.getType().isWiki()) {
|
||||
WikipediaPlugin wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
|
||||
if (!hasWiki && wikiPlugin != null) {
|
||||
String articleLang = wikiPlugin.getWikiArticleLanguage(
|
||||
if (!hasWiki) {
|
||||
String articleLang = OsmandPlugin.onGetMapObjectsLocale(
|
||||
amenity.getSupportedContentLocales(), preferredLang);
|
||||
String lng = amenity.getContentLanguage("content", articleLang, "en");
|
||||
if (Algorithms.isEmpty(lng)) {
|
||||
|
|
|
@ -22,7 +22,6 @@ import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder;
|
|||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.transport.TransportStopRoute;
|
||||
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
|
||||
import net.osmand.plus.wikipedia.WikipediaPlugin;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
|
||||
|
@ -160,12 +159,9 @@ public class AmenityMenuController extends MenuController {
|
|||
public String getNameStr() {
|
||||
String preferredLang = getPreferredMapLang();
|
||||
if (amenity.getType().isWiki()) {
|
||||
WikipediaPlugin wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
|
||||
if (wikiPlugin != null) {
|
||||
preferredLang = wikiPlugin.getWikiArticleLanguage(
|
||||
preferredLang = OsmandPlugin.onGetMapObjectsLocale(
|
||||
amenity.getSupportedContentLocales(), getPreferredMapAppLang());
|
||||
}
|
||||
}
|
||||
String name = amenity.getName(preferredLang, isTransliterateNames());
|
||||
Map<String, String> additionalInfo = amenity.getAdditionalInfo();
|
||||
if (additionalInfo != null) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package net.osmand.plus.poi;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.util.Pair;
|
||||
|
@ -18,7 +16,6 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
|||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteStatement;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.wikipedia.WikipediaPlugin;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.json.JSONArray;
|
||||
|
@ -114,24 +111,8 @@ public class PoiFiltersHelper {
|
|||
return customPOIFilter;
|
||||
}
|
||||
|
||||
public void prepareTopWikiFilter(@NonNull PoiUIFilter wiki) {
|
||||
boolean prepareByDefault = true;
|
||||
WikipediaPlugin wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
|
||||
if (wikiPlugin != null && wikiPlugin.hasCustomSettings()) {
|
||||
prepareByDefault = false;
|
||||
String wikiLang = "wiki:lang:";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String lang : wikiPlugin.getLanguagesToShow()) {
|
||||
if (sb.length() > 1) {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append(wikiLang).append(lang);
|
||||
}
|
||||
wiki.setFilterByName(sb.toString());
|
||||
}
|
||||
if (prepareByDefault) {
|
||||
wiki.setFilterByName(null);
|
||||
}
|
||||
public void prepareExtraTopPoiFilters(PoiUIFilter ... filters) {
|
||||
OsmandPlugin.onPrepareExtraTopPoiFilters(filters);
|
||||
}
|
||||
|
||||
public PoiUIFilter getTopWikiPoiFilter() {
|
||||
|
@ -480,7 +461,7 @@ public class PoiFiltersHelper {
|
|||
|
||||
public void addSelectedPoiFilter(PoiUIFilter filter) {
|
||||
if (filter.isTopWikiFilter()) {
|
||||
prepareTopWikiFilter(filter);
|
||||
prepareExtraTopPoiFilters(filter);
|
||||
}
|
||||
Set<PoiUIFilter> selectedPoiFilters = new TreeSet<>(this.selectedPoiFilters);
|
||||
selectedPoiFilters.add(filter);
|
||||
|
@ -574,7 +555,7 @@ public class PoiFiltersHelper {
|
|||
PoiUIFilter filter = getFilterById(f);
|
||||
if (filter != null) {
|
||||
if (filter.isTopWikiFilter()) {
|
||||
prepareTopWikiFilter(filter);
|
||||
prepareExtraTopPoiFilters(filter);
|
||||
}
|
||||
selectedPoiFilters.add(filter);
|
||||
}
|
||||
|
|
|
@ -1074,12 +1074,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||
}
|
||||
|
||||
public void showProgressBar() {
|
||||
private void showProgressBar() {
|
||||
updateClearButtonVisibility(false);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void hideProgressBar() {
|
||||
private void hideProgressBar() {
|
||||
updateClearButtonVisibility(true);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -2321,17 +2321,23 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
|
||||
@Override
|
||||
public void newDownloadIndexes() {
|
||||
hideProgressBar();
|
||||
OsmandPlugin.onNewDownloadIndexes(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadInProgress() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadHasFinished() {
|
||||
}
|
||||
|
||||
public void reloadIndexFiles() {
|
||||
if (app.getSettings().isInternetConnectionAvailable()) {
|
||||
app.getDownloadThread().runReloadIndexFiles();
|
||||
showProgressBar();
|
||||
}
|
||||
}
|
||||
|
||||
public interface SearchResultListener {
|
||||
|
|
|
@ -45,7 +45,6 @@ import net.osmand.plus.render.RenderingIcons;
|
|||
import net.osmand.plus.routing.IRouteInformationListener;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
||||
import net.osmand.plus.wikipedia.WikipediaPlugin;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -365,12 +364,9 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
|
|||
if (Algorithms.isEmpty(preferredLang)) {
|
||||
preferredLang = app.getLanguage();
|
||||
}
|
||||
WikipediaPlugin wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
|
||||
if (wikiPlugin != null) {
|
||||
preferredLang = wikiPlugin.getWikiArticleLanguage(
|
||||
preferredLang = OsmandPlugin.onGetMapObjectsLocale(
|
||||
a.getSupportedContentLocales(), preferredLang);
|
||||
}
|
||||
}
|
||||
|
||||
return new PointDescription(PointDescription.POINT_TYPE_POI,
|
||||
a.getName(preferredLang, transliterateNames));
|
||||
|
|
|
@ -279,18 +279,15 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
|
|||
return false;
|
||||
}
|
||||
OsmandApplication app = (OsmandApplication) activity.getApplication();
|
||||
WikipediaPlugin wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
|
||||
|
||||
WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment();
|
||||
wikipediaDialogFragment.setAmenity(amenity);
|
||||
if (wikiPlugin != null) {
|
||||
lang = lang != null ? lang : wikiPlugin.getWikiArticleLanguage(
|
||||
lang = lang != null ? lang : OsmandPlugin.onGetMapObjectsLocale(
|
||||
amenity.getSupportedContentLocales(),
|
||||
app.getSettings().MAP_PREFERRED_LOCALE.get());
|
||||
wikipediaDialogFragment.setLanguage(lang);
|
||||
wikipediaDialogFragment.setRetainInstance(true);
|
||||
wikipediaDialogFragment.show(activity.getSupportFragmentManager(), TAG);
|
||||
}
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
|
|
|
@ -242,6 +242,11 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
return app.getString(R.string.shared_string_all_languages);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMapObjectsLocale(Set<String> supportedLocales, String preferredLocale) {
|
||||
return getWikiArticleLanguage(supportedLocales, preferredLocale);
|
||||
}
|
||||
|
||||
public String getWikiArticleLanguage(@NonNull Set<String> availableArticleLangs,
|
||||
String preferredLanguage) {
|
||||
if (!hasCustomSettings()) {
|
||||
|
@ -298,10 +303,7 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
} else {
|
||||
final DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
|
||||
if (settings.isInternetConnectionAvailable()) {
|
||||
downloadThread.runReloadIndexFiles();
|
||||
}
|
||||
searchFragment.showProgressBar();
|
||||
searchFragment.reloadIndexFiles();
|
||||
} else {
|
||||
addEmptyWikiBanner(searchFragment, phrase);
|
||||
}
|
||||
|
@ -317,7 +319,6 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
final QuickSearchDialogFragment f = (QuickSearchDialogFragment) fragment;
|
||||
SearchPhrase phrase = app.getSearchUICore().getCore().getPhrase();
|
||||
if (f.isResultEmpty() && isSearchByWiki(phrase)) {
|
||||
f.hideProgressBar();
|
||||
addEmptyWikiBanner(f, phrase);
|
||||
}
|
||||
}
|
||||
|
@ -344,6 +345,31 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
fragment.addSearchListItem(banner);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareExtraTopPoiFilters(PoiUIFilter ... filters) {
|
||||
for (PoiUIFilter filter : filters) {
|
||||
if (filter.isTopWikiFilter()) {
|
||||
boolean prepareByDefault = true;
|
||||
if (hasCustomSettings()) {
|
||||
prepareByDefault = false;
|
||||
String wikiLang = "wiki:lang:";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String lang : getLanguagesToShow()) {
|
||||
if (sb.length() > 1) {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append(wikiLang).append(lang);
|
||||
}
|
||||
filter.setFilterByName(sb.toString());
|
||||
}
|
||||
if (prepareByDefault) {
|
||||
filter.setFilterByName(null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSearchByWiki(SearchPhrase phrase) {
|
||||
if (phrase.isLastWord(ObjectType.POI_TYPE)) {
|
||||
Object obj = phrase.getLastSelectedWord().getResult().object;
|
||||
|
|
Loading…
Reference in a new issue