Move check in Search to Wikipedia Plugin

This commit is contained in:
Nazar-Kutz 2020-06-26 09:42:53 +03:00
parent 2ffb95568d
commit c4214d0afc
9 changed files with 345 additions and 83 deletions

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half"
android:tint="?attr/color_dialog_buttons"
osmand:srcCompat="@drawable/ic_world_globe_dark" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_online_address"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_sub_text_size"
osmand:textAllCapsCompat="true"
osmand:typeface="@string/font_roboto_medium" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/empty_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="24dp"
android:paddingTop="24dp"
android:visibility="visible">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
osmand:srcCompat="@drawable/ic_empty_state_search"
android:tint="#ec572e"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/empty_search_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/nothing_found_in_radius" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/empty_search_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="4dp"
android:text="@string/nothing_found_descr"
android:textColor="?android:attr/textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"/>
</LinearLayout>
<ListView
android:id="@+id/buttons_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -41,6 +41,7 @@ import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; 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.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.fragments.BaseSettingsFragment; 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.srtmplugin.SRTMPlugin;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.wikipedia.WikipediaPlugin; import net.osmand.plus.wikipedia.WikipediaPlugin;
import net.osmand.search.core.SearchPhrase;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -373,7 +375,13 @@ public abstract class OsmandPlugin {
private static void checkPaidPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) { private static void checkPaidPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
allPlugins.add(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<String> enabledPlugins, @NonNull OsmandPlugin plugin) { private static void checkMarketPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
@ -540,6 +548,10 @@ 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) {
return false;
}
public List<String> indexingFiles(IProgress progress) { public List<String> indexingFiles(IProgress progress) {
return null; 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<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

@ -87,7 +87,6 @@ import net.osmand.plus.poi.RearrangePoiFiltersFragment;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI; import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI;
import net.osmand.plus.search.listitems.QuickSearchButtonListItem; 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.QuickSearchHeaderListItem;
import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItem;
import net.osmand.plus.search.listitems.QuickSearchMoreListItem; 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.settings.backend.OsmandSettings;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
import net.osmand.plus.wikipedia.WikipediaPlugin;
import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore;
import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.SearchUICore.SearchResultCollection;
import net.osmand.search.core.ObjectType; 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.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;
import static net.osmand.plus.search.listitems.QuickSearchMoreListItem.*;
public class QuickSearchDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener { public class QuickSearchDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener {
@ -852,7 +849,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
cancelPrev = false; cancelPrev = false;
hidden = false; hidden = false;
if (interruptedSearch) { if (interruptedSearch) {
addNotFoundButton(true, SearchMoreType.STANDARD); addMoreButton(true);
interruptedSearch = false; interruptedSearch = false;
} }
} }
@ -1975,65 +1972,56 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
private void onNothingFound(SearchPhrase phrase) { private void onNothingFound(SearchPhrase phrase) {
WikipediaPlugin wikiPlugin = OsmandPlugin.getEnabledPlugin(WikipediaPlugin.class); if (!OsmandPlugin.onNothingFoundInSearch(this, phrase)) {
if (WikipediaPlugin.isSearchByWiki(phrase)) { addMoreButton(searchUICore.isSearchMoreAvailable(phrase));
if (wikiPlugin == null) {
mainSearchFragment.addListItem(new QuickSearchFreeBannerListItem(app));
} else {
addNotFoundButton(searchUICore.isSearchMoreAvailable(phrase), SearchMoreType.WIKIPEDIA);
}
} else {
addNotFoundButton(searchUICore.isSearchMoreAvailable(phrase), SearchMoreType.STANDARD);
} }
} }
private void addNotFoundButton(boolean searchMoreAvailable, final SearchMoreType type) { private void addMoreButton(boolean searchMoreAvailable) {
if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) { if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) {
final WikipediaPlugin wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
QuickSearchMoreListItem moreListItem = QuickSearchMoreListItem moreListItem =
new QuickSearchMoreListItem(app, null, type, new SearchMoreItemOnClickListener() { new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() {
@Override @Override
public void onPrimaryButtonClick() { public void onPrimaryButtonClick() {
if (!interruptedSearch) { increaseSearchRadius();
SearchSettings settings = searchUICore.getSearchSettings();
searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
}
runCoreSearch(searchQuery, false, true);
} }
@Override @Override
public void onSecondaryButtonClick() { public void onSecondaryButtonClick() {
if (type == SearchMoreType.WIKIPEDIA) { final OsmandSettings settings = app.getSettings();
if (wikiPlugin != null) { if (!settings.isInternetConnectionAvailable()) {
wikiPlugin.showDownloadWikiScreen(); Toast.makeText(app, R.string.internet_not_available, Toast.LENGTH_LONG).show();
} return;
} 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);
} }
startOnlineSearch();
mainSearchFragment.getAdapter().clear();
updateTabbarVisibility(false);
runCoreSearch(searchQuery, false, true);
} }
}); });
moreListItem.setInterruptedSearch(interruptedSearch); moreListItem.setInterruptedSearch(interruptedSearch);
moreListItem.setEmptySearch(isResultEmpty()); moreListItem.setEmptySearch(isResultEmpty());
moreListItem.setSearchMoreAvailable(searchMoreAvailable); moreListItem.setSearchMoreAvailable(searchMoreAvailable);
if (type == SearchMoreType.STANDARD) { moreListItem.setSecondaryButtonVisible(isOnlineSearch());
moreListItem.setSecondaryButtonVisible(isOnlineSearch());
} else if (type == SearchMoreType.WIKIPEDIA) {
moreListItem.setSecondaryButtonVisible(
wikiPlugin != null && wikiPlugin.hasMapsToDownload());
}
mainSearchFragment.addListItem(moreListItem); mainSearchFragment.addListItem(moreListItem);
updateSendEmptySearchBottomBar(isResultEmpty() && !interruptedSearch); 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) { private void updateSearchResult(SearchResultCollection res, boolean append) {
if (!paused && mainSearchFragment != null) { if (!paused && mainSearchFragment != null) {

View file

@ -9,9 +9,11 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -27,6 +29,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; 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.QuickSearchHeaderListItem;
import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.search.listitems.QuickSearchListItem;
import net.osmand.plus.search.listitems.QuickSearchListItemType; import net.osmand.plus.search.listitems.QuickSearchListItemType;
@ -43,6 +46,7 @@ import java.util.Calendar;
import java.util.List; import java.util.List;
import static net.osmand.search.core.ObjectType.POI_TYPE; import static net.osmand.search.core.ObjectType.POI_TYPE;
import static net.osmand.plus.search.listitems.QuickSearchBannerListItem.ButtonItem;
public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> { public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
@ -200,7 +204,55 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
final QuickSearchListItem listItem = getItem(position); final QuickSearchListItem listItem = getItem(position);
QuickSearchListItemType type = listItem.getType(); QuickSearchListItemType type = listItem.getType();
LinearLayout view; 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<ButtonItem> adapter = new ArrayAdapter<ButtonItem>(
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) { if (convertView == null) {
view = (LinearLayout) inflater.inflate( view = (LinearLayout) inflater.inflate(
R.layout.read_wikipedia_ofline_banner, null); R.layout.read_wikipedia_ofline_banner, null);
@ -254,15 +306,7 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle); ((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle);
View primaryButton = view.findViewById(R.id.primary_button); View primaryButton = view.findViewById(R.id.primary_button);
SearchWord word = searchPhrase.getLastSelectedWord(); ((TextView) view.findViewById(R.id.title)).setText(getIncreaseSearchButtonTitle(app, searchPhrase));
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));
}
primaryButton.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE); primaryButton.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE);
primaryButton.setOnClickListener(new View.OnClickListener() { primaryButton.setOnClickListener(new View.OnClickListener() {
@ -275,8 +319,6 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
View secondaryButton = view.findViewById(R.id.secondary_button); View secondaryButton = view.findViewById(R.id.secondary_button);
secondaryButton.setVisibility(searchMoreItem.isSecondaryButtonVisible() ? secondaryButton.setVisibility(searchMoreItem.isSecondaryButtonVisible() ?
View.VISIBLE : View.GONE); View.VISIBLE : View.GONE);
TextView tvSecondaryButtonTitle = view.findViewById(R.id.secondary_button_title);
tvSecondaryButtonTitle.setText(searchMoreItem.getSecondaryButtonTitle());
secondaryButton.setOnClickListener(new View.OnClickListener() { secondaryButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -469,6 +511,19 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
return view; 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) { public void toggleCheckbox(int position, CheckBox ch) {
QuickSearchListItemType type = getItem(position).getType(); QuickSearchListItemType type = getItem(position).getType();
if (type == QuickSearchListItemType.SELECT_ALL) { if (type == QuickSearchListItemType.SELECT_ALL) {

View file

@ -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<ButtonItem> 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<ButtonItem> 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;
}
}
}

View file

@ -5,6 +5,7 @@ public enum QuickSearchListItemType {
HEADER, HEADER,
BUTTON, BUTTON,
SEARCH_MORE, SEARCH_MORE,
BANNER,
FREE_VERSION_BANNER, FREE_VERSION_BANNER,
SELECT_ALL, SELECT_ALL,
TOP_SHADOW, TOP_SHADOW,

View file

@ -15,19 +15,13 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
private String findMore; private String findMore;
private String restartSearch; private String restartSearch;
private String increaseRadius; private String increaseRadius;
private SearchMoreType type;
private boolean secondaryButtonVisibility; private boolean secondaryButtonVisibility;
public enum SearchMoreType { public QuickSearchMoreListItem(OsmandApplication app, String name,
STANDARD, WIKIPEDIA
}
public QuickSearchMoreListItem(OsmandApplication app, String name, SearchMoreType type,
@Nullable SearchMoreItemOnClickListener onClickListener) { @Nullable SearchMoreItemOnClickListener onClickListener) {
super(app, null); super(app, null);
this.name = name; this.name = name;
this.onClickListener = onClickListener; this.onClickListener = onClickListener;
this.type = type;
findMore = app.getString(R.string.search_POI_level_btn).toUpperCase(); findMore = app.getString(R.string.search_POI_level_btn).toUpperCase();
restartSearch = app.getString(R.string.restart_search).toUpperCase(); restartSearch = app.getString(R.string.restart_search).toUpperCase();
increaseRadius = app.getString(R.string.increase_search_radius).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() { public boolean isInterruptedSearch() {
return interruptedSearch; return interruptedSearch;
} }

View file

@ -13,6 +13,7 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity; 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;
@ -20,6 +21,10 @@ import net.osmand.plus.download.DownloadActivityType;
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;
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.settings.backend.OsmandSettings;
import net.osmand.plus.views.DownloadedRegionsLayer; import net.osmand.plus.views.DownloadedRegionsLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
@ -256,18 +261,17 @@ public class WikipediaPlugin extends OsmandPlugin {
return preferredLanguage; return preferredLanguage;
} }
public void showDownloadWikiScreen() { public void showDownloadWikiMapsScreen() {
if (mapActivity == null) { if (mapActivity != null) {
return; 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() { public boolean hasMapsToDownload() {
@ -275,8 +279,8 @@ public class WikipediaPlugin extends OsmandPlugin {
if (mapActivity == null) { if (mapActivity == null) {
return false; return false;
} }
int mapsToDownloadCount = DownloadResources.findIndexItemsAt(app, int mapsToDownloadCount = DownloadResources.findIndexItemsAt(
mapActivity.getMapLocation(), DownloadActivityType.WIKIPEDIA_FILE, app, mapActivity.getMapLocation(), DownloadActivityType.WIKIPEDIA_FILE,
false, 1).size(); false, 1).size();
return mapsToDownloadCount > 0; return mapsToDownloadCount > 0;
} catch (IOException e) { } 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)) { if (phrase.isLastWord(ObjectType.POI_TYPE)) {
Object obj = phrase.getLastSelectedWord().getResult().object; Object obj = phrase.getLastSelectedWord().getResult().object;
if (obj instanceof PoiUIFilter) { if (obj instanceof PoiUIFilter) {