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