From c4214d0afcfc8e10dc074b2eb757dd45f45b20c2 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Fri, 26 Jun 2020 09:42:53 +0300 Subject: [PATCH] Move check in Search to Wikipedia Plugin --- .../layout/search_banner_button_list_item.xml | 42 ++++++++++ OsmAnd/res/layout/search_banner_list_item.xml | 74 +++++++++++++++++ OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 22 +++++- .../search/QuickSearchDialogFragment.java | 70 +++++++--------- .../plus/search/QuickSearchListAdapter.java | 79 ++++++++++++++++--- .../listitems/QuickSearchBannerListItem.java | 62 +++++++++++++++ .../listitems/QuickSearchListItemType.java | 1 + .../listitems/QuickSearchMoreListItem.java | 16 +--- .../plus/wikipedia/WikipediaPlugin.java | 62 +++++++++++---- 9 files changed, 345 insertions(+), 83 deletions(-) create mode 100644 OsmAnd/res/layout/search_banner_button_list_item.xml create mode 100644 OsmAnd/res/layout/search_banner_list_item.xml create mode 100644 OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchBannerListItem.java diff --git a/OsmAnd/res/layout/search_banner_button_list_item.xml b/OsmAnd/res/layout/search_banner_button_list_item.xml new file mode 100644 index 0000000000..65d048029f --- /dev/null +++ b/OsmAnd/res/layout/search_banner_button_list_item.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/search_banner_list_item.xml b/OsmAnd/res/layout/search_banner_list_item.xml new file mode 100644 index 0000000000..b8ea21a518 --- /dev/null +++ b/OsmAnd/res/layout/search_banner_list_item.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 0b4c69cd91..edc8938ab5 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -41,6 +41,7 @@ import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.fragments.BaseSettingsFragment; @@ -48,6 +49,7 @@ import net.osmand.plus.skimapsplugin.SkiMapsPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.wikipedia.WikipediaPlugin; +import net.osmand.search.core.SearchPhrase; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -373,7 +375,13 @@ public abstract class OsmandPlugin { private static void checkPaidPlugin(@NonNull OsmandApplication app, @NonNull Set enabledPlugins, @NonNull OsmandPlugin plugin) { allPlugins.add(plugin); - plugin.setActive(Version.isPaidVersion(app)); + boolean active = Version.isPaidVersion(app); + plugin.setActive(active); + if (active) { + enabledPlugins.add(plugin.getId()); + } else { + enabledPlugins.remove(plugin.getId()); + } } private static void checkMarketPlugin(@NonNull OsmandApplication app, @NonNull Set enabledPlugins, @NonNull OsmandPlugin plugin) { @@ -540,6 +548,10 @@ public abstract class OsmandPlugin { protected void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { } + protected boolean nothingFoundInSearch(QuickSearchDialogFragment searchFragment, SearchPhrase phrase) { + return false; + } + public List indexingFiles(IProgress progress) { return null; } @@ -797,6 +809,14 @@ public abstract class OsmandPlugin { } } + public static boolean onNothingFoundInSearch(QuickSearchDialogFragment searchFragment, SearchPhrase phrase) { + boolean processed = false; + for (OsmandPlugin plugin : getEnabledPlugins()) { + processed = plugin.nothingFoundInSearch(searchFragment, phrase) || processed; + } + return processed; + } + public static Collection getPluginsCardsList() { HashSet collection = new HashSet<>(); for (OsmandPlugin plugin : getEnabledPlugins()) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index fc506863a5..b281e80161 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -87,7 +87,6 @@ import net.osmand.plus.poi.RearrangePoiFiltersFragment; import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI; import net.osmand.plus.search.listitems.QuickSearchButtonListItem; -import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchMoreListItem; @@ -96,7 +95,6 @@ import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; -import net.osmand.plus.wikipedia.WikipediaPlugin; import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.core.ObjectType; @@ -119,7 +117,6 @@ import static net.osmand.plus.search.SendSearchQueryBottomSheet.MISSING_SEARCH_Q import static net.osmand.search.core.ObjectType.POI_TYPE; import static net.osmand.search.core.ObjectType.SEARCH_STARTED; import static net.osmand.search.core.SearchCoreFactory.SEARCH_AMENITY_TYPE_PRIORITY; -import static net.osmand.plus.search.listitems.QuickSearchMoreListItem.*; public class QuickSearchDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener { @@ -852,7 +849,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC cancelPrev = false; hidden = false; if (interruptedSearch) { - addNotFoundButton(true, SearchMoreType.STANDARD); + addMoreButton(true); interruptedSearch = false; } } @@ -1975,65 +1972,56 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } private void onNothingFound(SearchPhrase phrase) { - WikipediaPlugin wikiPlugin = OsmandPlugin.getEnabledPlugin(WikipediaPlugin.class); - if (WikipediaPlugin.isSearchByWiki(phrase)) { - if (wikiPlugin == null) { - mainSearchFragment.addListItem(new QuickSearchFreeBannerListItem(app)); - } else { - addNotFoundButton(searchUICore.isSearchMoreAvailable(phrase), SearchMoreType.WIKIPEDIA); - } - } else { - addNotFoundButton(searchUICore.isSearchMoreAvailable(phrase), SearchMoreType.STANDARD); + if (!OsmandPlugin.onNothingFoundInSearch(this, phrase)) { + addMoreButton(searchUICore.isSearchMoreAvailable(phrase)); } } - private void addNotFoundButton(boolean searchMoreAvailable, final SearchMoreType type) { + private void addMoreButton(boolean searchMoreAvailable) { if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) { - final WikipediaPlugin wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class); QuickSearchMoreListItem moreListItem = - new QuickSearchMoreListItem(app, null, type, new SearchMoreItemOnClickListener() { + new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() { @Override public void onPrimaryButtonClick() { - if (!interruptedSearch) { - SearchSettings settings = searchUICore.getSearchSettings(); - searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1)); - } - runCoreSearch(searchQuery, false, true); + increaseSearchRadius(); } @Override public void onSecondaryButtonClick() { - if (type == SearchMoreType.WIKIPEDIA) { - if (wikiPlugin != null) { - wikiPlugin.showDownloadWikiScreen(); - } - } else if (type == SearchMoreType.STANDARD) { - final OsmandSettings settings = app.getSettings(); - if (!settings.isInternetConnectionAvailable()) { - Toast.makeText(app, R.string.internet_not_available, Toast.LENGTH_LONG).show(); - return; - } - startOnlineSearch(); - mainSearchFragment.getAdapter().clear(); - updateTabbarVisibility(false); - runCoreSearch(searchQuery, false, true); + final OsmandSettings settings = app.getSettings(); + if (!settings.isInternetConnectionAvailable()) { + Toast.makeText(app, R.string.internet_not_available, Toast.LENGTH_LONG).show(); + return; } + startOnlineSearch(); + mainSearchFragment.getAdapter().clear(); + updateTabbarVisibility(false); + runCoreSearch(searchQuery, false, true); } }); moreListItem.setInterruptedSearch(interruptedSearch); moreListItem.setEmptySearch(isResultEmpty()); moreListItem.setSearchMoreAvailable(searchMoreAvailable); - if (type == SearchMoreType.STANDARD) { - moreListItem.setSecondaryButtonVisible(isOnlineSearch()); - } else if (type == SearchMoreType.WIKIPEDIA) { - moreListItem.setSecondaryButtonVisible( - wikiPlugin != null && wikiPlugin.hasMapsToDownload()); - } + moreListItem.setSecondaryButtonVisible(isOnlineSearch()); mainSearchFragment.addListItem(moreListItem); updateSendEmptySearchBottomBar(isResultEmpty() && !interruptedSearch); } } + public void increaseSearchRadius() { + if (!interruptedSearch) { + SearchSettings settings = searchUICore.getSearchSettings(); + searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1)); + } + runCoreSearch(searchQuery, false, true); + } + + public void addSearchListItem(QuickSearchListItem item) { + if (mainSearchFragment != null) { + mainSearchFragment.addListItem(item); + } + } + private void updateSearchResult(SearchResultCollection res, boolean append) { if (!paused && mainSearchFragment != null) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index 8982d58a50..051d983f29 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -9,9 +9,11 @@ import android.widget.ArrayAdapter; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.ListView; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.view.ContextThemeWrapper; import androidx.core.view.ViewCompat; import androidx.fragment.app.FragmentActivity; @@ -27,6 +29,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; +import net.osmand.plus.search.listitems.QuickSearchBannerListItem; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItemType; @@ -43,6 +46,7 @@ import java.util.Calendar; import java.util.List; import static net.osmand.search.core.ObjectType.POI_TYPE; +import static net.osmand.plus.search.listitems.QuickSearchBannerListItem.ButtonItem; public class QuickSearchListAdapter extends ArrayAdapter { @@ -200,7 +204,55 @@ public class QuickSearchListAdapter extends ArrayAdapter { final QuickSearchListItem listItem = getItem(position); QuickSearchListItemType type = listItem.getType(); LinearLayout view; - if (type == QuickSearchListItemType.FREE_VERSION_BANNER) { + if (type == QuickSearchListItemType.BANNER) { + QuickSearchBannerListItem banner = (QuickSearchBannerListItem) listItem; + if (convertView == null) { + view = (LinearLayout) inflater.inflate(R.layout.search_banner_list_item, null); + } else { + view = (LinearLayout) convertView; + } + + ((TextView) view.findViewById(R.id.empty_search_description)).setText(R.string.nothing_found_descr); + + SearchUICore searchUICore = app.getSearchUICore().getCore(); + SearchPhrase searchPhrase = searchUICore.getPhrase(); + + String textTitle; + int minimalSearchRadius = searchUICore.getMinimalSearchRadius(searchPhrase); + if (searchUICore.isSearchMoreAvailable(searchPhrase) && minimalSearchRadius != Integer.MAX_VALUE) { + double rd = OsmAndFormatter.calculateRoundedDist(minimalSearchRadius, app); + textTitle = app.getString(R.string.nothing_found_in_radius) + " " + + OsmAndFormatter.getFormattedDistance((float) rd, app, false); + } else { + textTitle = app.getString(R.string.search_nothing_found); + } + ((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle); + + ListView buttonsList = view.findViewById(R.id.buttons_list); + ArrayAdapter adapter = new ArrayAdapter( + app, R.layout.search_banner_button_list_item, banner.getButtonItems()) { + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + View v = inflater.inflate(R.layout.search_banner_button_list_item, null); + ButtonItem buttonItem = getItem(position); + if (buttonItem != null) { + TextView title = v.findViewById(R.id.title); + title.setText(buttonItem.getTitle()); + ImageView icon = v.findViewById(R.id.icon); + if (buttonItem.getIconId() != -1) { + icon.setImageResource(buttonItem.getIconId()); + icon.setVisibility(View.VISIBLE); + } else { + icon.setVisibility(View.GONE); + } + v.setOnClickListener(buttonItem.getListener()); + } + return v; + } + }; + buttonsList.setAdapter(adapter); + } else if (type == QuickSearchListItemType.FREE_VERSION_BANNER) { if (convertView == null) { view = (LinearLayout) inflater.inflate( R.layout.read_wikipedia_ofline_banner, null); @@ -254,15 +306,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { ((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle); View primaryButton = view.findViewById(R.id.primary_button); - SearchWord word = searchPhrase.getLastSelectedWord(); - if (word != null && word.getType() != null && word.getType().equals(POI_TYPE)) { - float rd = (float) OsmAndFormatter.calculateRoundedDist(searchUICore.getNextSearchRadius(searchPhrase), app); - String textIncreaseRadiusTo = app.getString(R.string.increase_search_radius_to, - OsmAndFormatter.getFormattedDistance(rd, app, false)); - ((TextView) view.findViewById(R.id.title)).setText(textIncreaseRadiusTo); - } else { - ((TextView) view.findViewById(R.id.title)).setText(app.getString(R.string.increase_search_radius)); - } + ((TextView) view.findViewById(R.id.title)).setText(getIncreaseSearchButtonTitle(app, searchPhrase)); primaryButton.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE); primaryButton.setOnClickListener(new View.OnClickListener() { @@ -275,8 +319,6 @@ public class QuickSearchListAdapter extends ArrayAdapter { View secondaryButton = view.findViewById(R.id.secondary_button); secondaryButton.setVisibility(searchMoreItem.isSecondaryButtonVisible() ? View.VISIBLE : View.GONE); - TextView tvSecondaryButtonTitle = view.findViewById(R.id.secondary_button_title); - tvSecondaryButtonTitle.setText(searchMoreItem.getSecondaryButtonTitle()); secondaryButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -469,6 +511,19 @@ public class QuickSearchListAdapter extends ArrayAdapter { return view; } + public static String getIncreaseSearchButtonTitle(OsmandApplication app, SearchPhrase searchPhrase) { + SearchWord word = searchPhrase.getLastSelectedWord(); + SearchUICore searchUICore = app.getSearchUICore().getCore(); + if (word != null && word.getType() != null && word.getType().equals(POI_TYPE)) { + float rd = (float) OsmAndFormatter.calculateRoundedDist( + searchUICore.getNextSearchRadius(searchPhrase), app); + return app.getString(R.string.increase_search_radius_to, + OsmAndFormatter.getFormattedDistance(rd, app, false)); + } else { + return app.getString(R.string.increase_search_radius); + } + } + public void toggleCheckbox(int position, CheckBox ch) { QuickSearchListItemType type = getItem(position).getType(); if (type == QuickSearchListItemType.SELECT_ALL) { diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchBannerListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchBannerListItem.java new file mode 100644 index 0000000000..6231e2c98d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchBannerListItem.java @@ -0,0 +1,62 @@ +package net.osmand.plus.search.listitems; + +import android.view.View; + +import net.osmand.plus.OsmandApplication; + +import java.util.ArrayList; +import java.util.List; + +public class QuickSearchBannerListItem extends QuickSearchListItem { + + private List buttons; + + public QuickSearchBannerListItem(OsmandApplication app) { + super(app, null); + buttons = new ArrayList<>(); + } + + public QuickSearchListItemType getType() { + return QuickSearchListItemType.BANNER; + } + + public void addButton(String title, String description, int iconId, + View.OnClickListener listener) { + buttons.add(new ButtonItem(title, description, iconId, listener)); + } + + public List getButtonItems() { + return buttons; + } + + public static class ButtonItem { + private String title; + private String description; + private int iconId; + private View.OnClickListener listener; + + public ButtonItem(String title, String description, int iconId, + View.OnClickListener listener) { + this.title = title; + this.description = description; + this.iconId = iconId; + this.listener = listener; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public int getIconId() { + return iconId; + } + + public View.OnClickListener getListener() { + return listener; + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java index 23ca0c5f3d..3c6dcf4527 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItemType.java @@ -5,6 +5,7 @@ public enum QuickSearchListItemType { HEADER, BUTTON, SEARCH_MORE, + BANNER, FREE_VERSION_BANNER, SELECT_ALL, TOP_SHADOW, diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java index 4f7a063b24..9109320184 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchMoreListItem.java @@ -15,19 +15,13 @@ public class QuickSearchMoreListItem extends QuickSearchListItem { private String findMore; private String restartSearch; private String increaseRadius; - private SearchMoreType type; private boolean secondaryButtonVisibility; - public enum SearchMoreType { - STANDARD, WIKIPEDIA - } - - public QuickSearchMoreListItem(OsmandApplication app, String name, SearchMoreType type, + public QuickSearchMoreListItem(OsmandApplication app, String name, @Nullable SearchMoreItemOnClickListener onClickListener) { super(app, null); this.name = name; this.onClickListener = onClickListener; - this.type = type; findMore = app.getString(R.string.search_POI_level_btn).toUpperCase(); restartSearch = app.getString(R.string.restart_search).toUpperCase(); increaseRadius = app.getString(R.string.increase_search_radius).toUpperCase(); @@ -52,14 +46,6 @@ public class QuickSearchMoreListItem extends QuickSearchListItem { } } - public String getSecondaryButtonTitle() { - if (type == SearchMoreType.WIKIPEDIA) { - return app.getString(R.string.search_download_wikipedia_maps); - } else { - return ""; - } - } - public boolean isInterruptedSearch() { return interruptedSearch; } diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java index 8e69cd093d..c1686527eb 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java @@ -13,6 +13,7 @@ import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.download.DownloadActivity; @@ -20,6 +21,10 @@ import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.plus.search.QuickSearchDialogFragment; +import net.osmand.plus.search.QuickSearchListAdapter; +import net.osmand.plus.search.listitems.QuickSearchBannerListItem; +import net.osmand.plus.search.listitems.QuickSearchFreeBannerListItem; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.DownloadedRegionsLayer; import net.osmand.plus.views.OsmandMapTileView; @@ -256,18 +261,17 @@ public class WikipediaPlugin extends OsmandPlugin { return preferredLanguage; } - public void showDownloadWikiScreen() { - if (mapActivity == null) { - return; + public void showDownloadWikiMapsScreen() { + if (mapActivity != null) { + OsmandMapTileView mv = mapActivity.getMapView(); + DownloadedRegionsLayer dl = mv.getLayerByClass(DownloadedRegionsLayer.class); + String filter = dl.getFilter(new StringBuilder()); + final Intent intent = new Intent(app, app.getAppCustomization().getDownloadIndexActivity()); + intent.putExtra(DownloadActivity.FILTER_KEY, filter); + intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.WIKIPEDIA_FILE.getTag()); + intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); + mapActivity.startActivity(intent); } - OsmandMapTileView mv = mapActivity.getMapView(); - DownloadedRegionsLayer dl = mv.getLayerByClass(DownloadedRegionsLayer.class); - String filter = dl.getFilter(new StringBuilder()); - final Intent intent = new Intent(app, app.getAppCustomization().getDownloadIndexActivity()); - intent.putExtra(DownloadActivity.FILTER_KEY, filter); - intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.WIKIPEDIA_FILE.getTag()); - intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); - mapActivity.startActivity(intent); } public boolean hasMapsToDownload() { @@ -275,8 +279,8 @@ public class WikipediaPlugin extends OsmandPlugin { if (mapActivity == null) { return false; } - int mapsToDownloadCount = DownloadResources.findIndexItemsAt(app, - mapActivity.getMapLocation(), DownloadActivityType.WIKIPEDIA_FILE, + int mapsToDownloadCount = DownloadResources.findIndexItemsAt( + app, mapActivity.getMapLocation(), DownloadActivityType.WIKIPEDIA_FILE, false, 1).size(); return mapsToDownloadCount > 0; } catch (IOException e) { @@ -284,7 +288,37 @@ public class WikipediaPlugin extends OsmandPlugin { } } - public static boolean isSearchByWiki(SearchPhrase phrase) { + @Override + protected boolean nothingFoundInSearch(final QuickSearchDialogFragment searchFragment, SearchPhrase phrase) { + if (isSearchByWiki(phrase)) { + if (!Version.isPaidVersion(app)) { + searchFragment.addSearchListItem(new QuickSearchFreeBannerListItem(app)); + } else { + QuickSearchBannerListItem banner = new QuickSearchBannerListItem(app); + banner.addButton(QuickSearchListAdapter.getIncreaseSearchButtonTitle(app, phrase), + null, -1, new View.OnClickListener() { + @Override + public void onClick(View v) { + searchFragment.increaseSearchRadius(); + } + }); + if (hasMapsToDownload()) { + banner.addButton(app.getString(R.string.search_download_wikipedia_maps), + null, R.drawable.ic_world_globe_dark, new View.OnClickListener() { + @Override + public void onClick(View v) { + showDownloadWikiMapsScreen(); + } + }); + } + searchFragment.addSearchListItem(banner); + } + return true; + } + return false; + } + + private boolean isSearchByWiki(SearchPhrase phrase) { if (phrase.isLastWord(ObjectType.POI_TYPE)) { Object obj = phrase.getLastSelectedWord().getResult().object; if (obj instanceof PoiUIFilter) {