Move custom poi filters to plugin
This commit is contained in:
parent
15a964f4bd
commit
ba5bb6dc9c
4 changed files with 44 additions and 38 deletions
|
@ -207,6 +207,10 @@ public abstract class OsmandPlugin {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected List<PoiUIFilter> getCustomPoiFilters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin was installed
|
||||
*/
|
||||
|
@ -550,7 +554,7 @@ public abstract class OsmandPlugin {
|
|||
protected void newDownloadIndexes(Fragment fragment) {
|
||||
}
|
||||
|
||||
protected void prepareExtraTopPoiFilters(PoiUIFilter ... filters) {
|
||||
protected void prepareExtraTopPoiFilters(Set<PoiUIFilter> poiUIFilter) {
|
||||
}
|
||||
|
||||
protected String getMapObjectsLocale(Amenity amenity, String preferredLocale) {
|
||||
|
@ -820,26 +824,26 @@ public abstract class OsmandPlugin {
|
|||
|
||||
public static boolean onSearchFinished(QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) {
|
||||
boolean processed = false;
|
||||
for (OsmandPlugin plugin : getAvailablePlugins()) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
processed = plugin.searchFinished(searchFragment, phrase, isResultEmpty) || processed;
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
public static void onNewDownloadIndexes(Fragment fragment) {
|
||||
for (OsmandPlugin plugin : getAvailablePlugins()) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
plugin.newDownloadIndexes(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onPrepareExtraTopPoiFilters(PoiUIFilter ... filters) {
|
||||
for (OsmandPlugin plugin : getAvailablePlugins()) {
|
||||
plugin.prepareExtraTopPoiFilters(filters);
|
||||
public static void onPrepareExtraTopPoiFilters(Set<PoiUIFilter> poiUIFilters) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
plugin.prepareExtraTopPoiFilters(poiUIFilters);
|
||||
}
|
||||
}
|
||||
|
||||
public static String onGetMapObjectPreferredLang(MapObject object, String preferredMapLang, String preferredMapAppLang) {
|
||||
for (OsmandPlugin plugin : getAvailablePlugins()) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
String locale = plugin.getMapObjectPreferredLang(object, preferredMapLang);
|
||||
if (locale != null) {
|
||||
return locale;
|
||||
|
@ -849,7 +853,7 @@ public abstract class OsmandPlugin {
|
|||
}
|
||||
|
||||
public static String onGetMapObjectsLocale(Amenity amenity, String preferredLocale) {
|
||||
for (OsmandPlugin plugin : getAvailablePlugins()) {
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
String locale = plugin.getMapObjectsLocale(amenity, preferredLocale);
|
||||
if (locale != null) {
|
||||
return locale;
|
||||
|
@ -858,6 +862,12 @@ public abstract class OsmandPlugin {
|
|||
return preferredLocale;
|
||||
}
|
||||
|
||||
public static void registerCustomPoiFilters(List<PoiUIFilter> poiUIFilters) {
|
||||
for (OsmandPlugin p : getEnabledPlugins()) {
|
||||
poiUIFilters.addAll(p.getCustomPoiFilters());
|
||||
}
|
||||
}
|
||||
|
||||
public static Collection<DashFragmentData> getPluginsCardsList() {
|
||||
HashSet<DashFragmentData> collection = new HashSet<>();
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
|
@ -879,8 +889,6 @@ public abstract class OsmandPlugin {
|
|||
return installed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean onMapActivityKeyUp(MapActivity mapActivity, int keyCode) {
|
||||
for (OsmandPlugin p : getEnabledPlugins()) {
|
||||
if (p.mapActivityKeyUp(mapActivity, keyCode))
|
||||
|
|
|
@ -111,10 +111,6 @@ public class PoiFiltersHelper {
|
|||
return customPOIFilter;
|
||||
}
|
||||
|
||||
public void prepareExtraTopPoiFilters(PoiUIFilter ... filters) {
|
||||
OsmandPlugin.onPrepareExtraTopPoiFilters(filters);
|
||||
}
|
||||
|
||||
public PoiUIFilter getTopWikiPoiFilter() {
|
||||
if (topWikiPoiFilter == null) {
|
||||
String wikiFilterId = PoiUIFilter.STD_PREFIX + "osmwiki";
|
||||
|
@ -244,6 +240,7 @@ public class PoiFiltersHelper {
|
|||
PoiUIFilter f = new PoiUIFilter(t, application, "");
|
||||
top.add(f);
|
||||
}
|
||||
OsmandPlugin.registerCustomPoiFilters(top);
|
||||
this.cacheTopStandardFilters = top;
|
||||
}
|
||||
List<PoiUIFilter> result = new ArrayList<>();
|
||||
|
@ -459,11 +456,9 @@ public class PoiFiltersHelper {
|
|||
}
|
||||
|
||||
public void addSelectedPoiFilter(PoiUIFilter filter) {
|
||||
if (filter.isTopWikiFilter()) {
|
||||
prepareExtraTopPoiFilters(filter);
|
||||
}
|
||||
Set<PoiUIFilter> selectedPoiFilters = new TreeSet<>(this.selectedPoiFilters);
|
||||
selectedPoiFilters.add(filter);
|
||||
OsmandPlugin.onPrepareExtraTopPoiFilters(selectedPoiFilters);
|
||||
saveSelectedPoiFilters(selectedPoiFilters);
|
||||
this.selectedPoiFilters = selectedPoiFilters;
|
||||
}
|
||||
|
@ -553,12 +548,10 @@ public class PoiFiltersHelper {
|
|||
for (String f : application.getSettings().getSelectedPoiFilters()) {
|
||||
PoiUIFilter filter = getFilterById(f);
|
||||
if (filter != null) {
|
||||
if (filter.isTopWikiFilter()) {
|
||||
prepareExtraTopPoiFilters(filter);
|
||||
}
|
||||
selectedPoiFilters.add(filter);
|
||||
}
|
||||
}
|
||||
OsmandPlugin.onPrepareExtraTopPoiFilters(selectedPoiFilters);
|
||||
this.selectedPoiFilters = selectedPoiFilters;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,8 @@ import androidx.core.os.ConfigurationCompat;
|
|||
import androidx.core.os.LocaleListCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -26,6 +24,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
|
|||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -40,7 +39,6 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
|
||||
private OsmandApplication app;
|
||||
private ApplicationMode appMode;
|
||||
private OsmandSettings settings;
|
||||
private WikipediaPlugin wikiPlugin;
|
||||
|
||||
private List<BottomSheetItemWithCompoundButton> languageItems;
|
||||
|
@ -52,8 +50,7 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
app = requiredMyApplication();
|
||||
settings = app.getSettings();
|
||||
appMode = settings.getApplicationMode();
|
||||
appMode = app.getSettings().getApplicationMode();
|
||||
wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
|
||||
initLanguagesData();
|
||||
}
|
||||
|
@ -185,7 +182,6 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
super.onRightBottomButtonClick();
|
||||
List<String> localesForSaving = new ArrayList<>();
|
||||
for (WikiLanguageItem language : languages) {
|
||||
if (language.isChecked()) {
|
||||
|
|
|
@ -48,10 +48,12 @@ import static net.osmand.osm.MapPoiTypes.WIKI_LANG;
|
|||
|
||||
public class WikipediaPlugin extends OsmandPlugin {
|
||||
|
||||
public static final String ID = "osmand.wikipedia";
|
||||
|
||||
private MapActivity mapActivity;
|
||||
private OsmandSettings settings;
|
||||
|
||||
public static final String ID = "osmand.wikipedia";
|
||||
private PoiUIFilter topWikiPoiFilter;
|
||||
|
||||
public WikipediaPlugin(OsmandApplication app) {
|
||||
super(app);
|
||||
|
@ -144,6 +146,18 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
.setListener(listener).createItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PoiUIFilter> getCustomPoiFilters() {
|
||||
List<PoiUIFilter> poiFilters = new ArrayList<>();
|
||||
if (topWikiPoiFilter == null) {
|
||||
AbstractPoiType poiType = app.getPoiTypes().getOsmwiki();
|
||||
topWikiPoiFilter = new PoiUIFilter(poiType, app, "");
|
||||
}
|
||||
poiFilters.add(topWikiPoiFilter);
|
||||
|
||||
return poiFilters;
|
||||
}
|
||||
|
||||
public void updateWikipediaState() {
|
||||
if (isShowAllLanguages() || hasLanguagesFilter()) {
|
||||
refreshWikiOnMap();
|
||||
|
@ -359,8 +373,8 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void prepareExtraTopPoiFilters(PoiUIFilter... filters) {
|
||||
for (PoiUIFilter filter : filters) {
|
||||
protected void prepareExtraTopPoiFilters(Set<PoiUIFilter> poiUIFilters) {
|
||||
for (PoiUIFilter filter : poiUIFilters) {
|
||||
if (filter.isTopWikiFilter()) {
|
||||
boolean prepareByDefault = true;
|
||||
if (hasCustomSettings()) {
|
||||
|
@ -388,17 +402,12 @@ public class WikipediaPlugin extends OsmandPlugin {
|
|||
Object obj = phrase.getLastSelectedWord().getResult().object;
|
||||
if (obj instanceof PoiUIFilter) {
|
||||
PoiUIFilter pf = (PoiUIFilter) obj;
|
||||
if (pf.isWikiFilter()) {
|
||||
return true;
|
||||
}
|
||||
return pf.isWikiFilter();
|
||||
} else if (obj instanceof AbstractPoiType) {
|
||||
AbstractPoiType pt = (AbstractPoiType) obj;
|
||||
if (pt.getKeyName().startsWith(WIKI_LANG)) {
|
||||
return true;
|
||||
}
|
||||
return pt.getKeyName().startsWith(WIKI_LANG);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue