Fix Wikipedia empty banner

This commit is contained in:
Nazar-Kutz 2020-06-30 10:21:54 +03:00
parent a3b5419b7a
commit 93ae98625b
3 changed files with 80 additions and 28 deletions

View file

@ -548,10 +548,13 @@ public abstract class OsmandPlugin {
protected void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { 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; return false;
} }
protected void newDownloadIndexes(Fragment fragment) {
}
public List<String> indexingFiles(IProgress progress) { public List<String> indexingFiles(IProgress progress) {
return null; 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; boolean processed = false;
for (OsmandPlugin plugin : getEnabledPlugins()) { for (OsmandPlugin plugin : getEnabledPlugins()) {
processed = plugin.nothingFoundInSearch(searchFragment, phrase) || processed; processed = plugin.searchFinished(searchFragment, phrase, isResultEmpty) || processed;
} }
return processed; return processed;
} }
public static void onNewDownloadIndexes(Fragment fragment) {
for (OsmandPlugin plugin : getEnabledPlugins()) {
plugin.newDownloadIndexes(fragment);
}
}
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()) {

View file

@ -80,6 +80,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode; 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;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.poi.PoiUIFilter; 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.ObjectType.SEARCH_STARTED;
import static net.osmand.search.core.SearchCoreFactory.SEARCH_AMENITY_TYPE_PRIORITY; 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); 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()); app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
} }
private void showProgressBar() { public void showProgressBar() {
updateClearButtonVisibility(false); updateClearButtonVisibility(false);
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
} }
private void hideProgressBar() { public void hideProgressBar() {
updateClearButtonVisibility(true); updateClearButtonVisibility(true);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }
@ -1174,7 +1176,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
if (getResultCollection() != null) { if (getResultCollection() != null) {
updateSearchResult(getResultCollection(), false); updateSearchResult(getResultCollection(), false);
onNothingFound(searchUICore.getPhrase()); onSearchFinished(searchUICore.getPhrase());
} }
break; break;
} }
@ -1703,7 +1705,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) { if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) {
hideProgressBar(); hideProgressBar();
SearchPhrase phrase = object.requiredSearchPhrase; SearchPhrase phrase = object.requiredSearchPhrase;
onNothingFound(phrase); onSearchFinished(phrase);
} }
} }
}); });
@ -1971,8 +1973,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
} }
private void onNothingFound(SearchPhrase phrase) { private void onSearchFinished(SearchPhrase phrase) {
if (!OsmandPlugin.onNothingFoundInSearch(this, phrase)) { if (!OsmandPlugin.onSearchFinished(this, phrase, isResultEmpty())) {
addMoreButton(searchUICore.isSearchMoreAvailable(phrase)); addMoreButton(searchUICore.isSearchMoreAvailable(phrase));
} }
} }
@ -2317,6 +2319,21 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
updateFabHeight(); updateFabHeight();
} }
@Override
public void newDownloadIndexes() {
OsmandPlugin.onNewDownloadIndexes(this);
}
@Override
public void downloadInProgress() {
}
@Override
public void downloadHasFinished() {
}
public interface SearchResultListener { public interface SearchResultListener {
void searchStarted(SearchPhrase phrase); void searchStarted(SearchPhrase phrase);
void publish(SearchResultCollection res, boolean append); void publish(SearchResultCollection res, boolean append);

View file

@ -5,6 +5,7 @@ import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
@ -18,6 +19,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
@ -289,17 +291,45 @@ public class WikipediaPlugin extends OsmandPlugin {
} }
@Override @Override
protected boolean nothingFoundInSearch(final QuickSearchDialogFragment searchFragment, SearchPhrase phrase) { protected boolean searchFinished(final QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) {
if (isSearchByWiki(phrase)) { if (isResultEmpty && isSearchByWiki(phrase)) {
if (!Version.isPaidVersion(app)) { if (!Version.isPaidVersion(app)) {
searchFragment.addSearchListItem(new QuickSearchFreeBannerListItem(app)); searchFragment.addSearchListItem(new QuickSearchFreeBannerListItem(app));
} else { } else {
final DownloadIndexesThread downloadThread = app.getDownloadThread();
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
if (settings.isInternetConnectionAvailable()) {
downloadThread.runReloadIndexFiles();
}
searchFragment.showProgressBar();
} else {
addEmptyWikiBanner(searchFragment, phrase);
}
}
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); QuickSearchBannerListItem banner = new QuickSearchBannerListItem(app);
banner.addButton(QuickSearchListAdapter.getIncreaseSearchButtonTitle(app, phrase), banner.addButton(QuickSearchListAdapter.getIncreaseSearchButtonTitle(app, phrase),
null, QuickSearchBannerListItem.INVALID_ID, new View.OnClickListener() { null, QuickSearchBannerListItem.INVALID_ID, new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
searchFragment.increaseSearchRadius(); fragment.increaseSearchRadius();
} }
}); });
if (hasMapsToDownload()) { if (hasMapsToDownload()) {
@ -311,11 +341,7 @@ public class WikipediaPlugin extends OsmandPlugin {
} }
}); });
} }
searchFragment.addSearchListItem(banner); fragment.addSearchListItem(banner);
}
return true;
}
return false;
} }
private boolean isSearchByWiki(SearchPhrase phrase) { private boolean isSearchByWiki(SearchPhrase phrase) {