diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index edc8938ab5..ba68c274e8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -548,10 +548,13 @@ public abstract class OsmandPlugin { protected void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { } - protected boolean nothingFoundInSearch(QuickSearchDialogFragment searchFragment, SearchPhrase phrase) { + protected boolean searchFinished(QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) { return false; } + protected void newDownloadIndexes(Fragment fragment) { + } + public List indexingFiles(IProgress progress) { return null; } @@ -809,14 +812,20 @@ public abstract class OsmandPlugin { } } - public static boolean onNothingFoundInSearch(QuickSearchDialogFragment searchFragment, SearchPhrase phrase) { + public static boolean onSearchFinished(QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) { boolean processed = false; for (OsmandPlugin plugin : getEnabledPlugins()) { - processed = plugin.nothingFoundInSearch(searchFragment, phrase) || processed; + processed = plugin.searchFinished(searchFragment, phrase, isResultEmpty) || processed; } return processed; } + public static void onNewDownloadIndexes(Fragment fragment) { + for (OsmandPlugin plugin : getEnabledPlugins()) { + plugin.newDownloadIndexes(fragment); + } + } + 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 b281e80161..d27c76f227 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -80,6 +80,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode; +import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.poi.PoiUIFilter; @@ -118,7 +119,8 @@ 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; -public class QuickSearchDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener { +public class QuickSearchDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener, + DownloadIndexesThread.DownloadEvents { private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(QuickSearchDialogFragment.class); @@ -1072,12 +1074,12 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo()); } - private void showProgressBar() { + public void showProgressBar() { updateClearButtonVisibility(false); progressBar.setVisibility(View.VISIBLE); } - private void hideProgressBar() { + public void hideProgressBar() { updateClearButtonVisibility(true); progressBar.setVisibility(View.GONE); } @@ -1174,7 +1176,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } if (getResultCollection() != null) { updateSearchResult(getResultCollection(), false); - onNothingFound(searchUICore.getPhrase()); + onSearchFinished(searchUICore.getPhrase()); } break; } @@ -1703,7 +1705,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) { hideProgressBar(); SearchPhrase phrase = object.requiredSearchPhrase; - onNothingFound(phrase); + onSearchFinished(phrase); } } }); @@ -1971,8 +1973,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } } - private void onNothingFound(SearchPhrase phrase) { - if (!OsmandPlugin.onNothingFoundInSearch(this, phrase)) { + private void onSearchFinished(SearchPhrase phrase) { + if (!OsmandPlugin.onSearchFinished(this, phrase, isResultEmpty())) { addMoreButton(searchUICore.isSearchMoreAvailable(phrase)); } } @@ -2317,6 +2319,21 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC updateFabHeight(); } + @Override + public void newDownloadIndexes() { + OsmandPlugin.onNewDownloadIndexes(this); + } + + @Override + public void downloadInProgress() { + + } + + @Override + public void downloadHasFinished() { + + } + public interface SearchResultListener { void searchStarted(SearchPhrase phrase); void publish(SearchResultCollection res, boolean append); diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java index 28ab7c49a3..e992e6de46 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaPlugin.java @@ -5,6 +5,7 @@ import android.view.View; import android.widget.ArrayAdapter; import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; @@ -18,6 +19,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; +import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; @@ -289,35 +291,59 @@ public class WikipediaPlugin extends OsmandPlugin { } @Override - protected boolean nothingFoundInSearch(final QuickSearchDialogFragment searchFragment, SearchPhrase phrase) { - if (isSearchByWiki(phrase)) { + protected boolean searchFinished(final QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) { + if (isResultEmpty && isSearchByWiki(phrase)) { if (!Version.isPaidVersion(app)) { searchFragment.addSearchListItem(new QuickSearchFreeBannerListItem(app)); } else { - QuickSearchBannerListItem banner = new QuickSearchBannerListItem(app); - banner.addButton(QuickSearchListAdapter.getIncreaseSearchButtonTitle(app, phrase), - null, QuickSearchBannerListItem.INVALID_ID, new View.OnClickListener() { - @Override - public void onClick(View v) { - searchFragment.increaseSearchRadius(); + final DownloadIndexesThread downloadThread = app.getDownloadThread(); + if (!downloadThread.getIndexes().isDownloadedFromInternet) { + if (settings.isInternetConnectionAvailable()) { + downloadThread.runReloadIndexFiles(); } - }); - 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.showProgressBar(); + } else { + addEmptyWikiBanner(searchFragment, phrase); } - searchFragment.addSearchListItem(banner); } return true; } return false; } + @Override + protected void newDownloadIndexes(Fragment fragment) { + if (fragment instanceof QuickSearchDialogFragment) { + final QuickSearchDialogFragment f = (QuickSearchDialogFragment) fragment; + SearchPhrase phrase = app.getSearchUICore().getCore().getPhrase(); + if (f.isResultEmpty() && isSearchByWiki(phrase)) { + f.hideProgressBar(); + addEmptyWikiBanner(f, phrase); + } + } + } + + private void addEmptyWikiBanner(final QuickSearchDialogFragment fragment, SearchPhrase phrase) { + QuickSearchBannerListItem banner = new QuickSearchBannerListItem(app); + banner.addButton(QuickSearchListAdapter.getIncreaseSearchButtonTitle(app, phrase), + null, QuickSearchBannerListItem.INVALID_ID, new View.OnClickListener() { + @Override + public void onClick(View v) { + fragment.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(); + } + }); + } + fragment.addSearchListItem(banner); + } + private boolean isSearchByWiki(SearchPhrase phrase) { if (phrase.isLastWord(ObjectType.POI_TYPE)) { Object obj = phrase.getLastSelectedWord().getResult().object;