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