Remove unnecessary method; add null-check; extract method from adapter to SearchSettings

This commit is contained in:
Alexander Sytnyk 2017-10-26 10:55:21 +03:00
parent 7fe60dcfe6
commit b8f5cab872
5 changed files with 25 additions and 22 deletions

View file

@ -142,4 +142,15 @@ public class SearchSettings {
s.addressSearch = addressSearch; s.addressSearch = addressSearch;
return s; return s;
} }
public boolean alreadyInOnlineSearch() {
if (searchTypes != null) {
for (ObjectType type : searchTypes) {
if (type == ObjectType.ONLINE_SEARCH) {
return true;
}
}
}
return false;
}
} }

View file

@ -530,10 +530,6 @@ public abstract class OsmandPlugin {
return getEnabledPlugin(OsmandDevelopmentPlugin.class) != null; return getEnabledPlugin(OsmandDevelopmentPlugin.class) != null;
} }
public static boolean isOnlineMapsTurnedOn() {
return getEnabledPlugin(OsmandRasterMapsPlugin.class) != null;
}
public static void addMyPlacesTabPlugins(FavoritesActivity favoritesActivity, List<TabItem> mTabs, Intent intent) { public static void addMyPlacesTabPlugins(FavoritesActivity favoritesActivity, List<TabItem> mTabs, Intent intent) {
for (OsmandPlugin p : getEnabledPlugins()) { for (OsmandPlugin p : getEnabledPlugins()) {
p.addMyPlacesTab(favoritesActivity, mTabs, intent); p.addMyPlacesTab(favoritesActivity, mTabs, intent);

View file

@ -72,6 +72,7 @@ import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
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;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
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;
@ -1081,7 +1082,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
for (SearchResult sr : res.getCurrentSearchResults()) { for (SearchResult sr : res.getCurrentSearchResults()) {
rows.add(new QuickSearchListItem(app, sr)); rows.add(new QuickSearchListItem(app, sr));
} }
if (OsmandPlugin.isOnlineMapsTurnedOn()) { if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark, rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark,
app.getString(R.string.search_online_address), new OnClickListener() { app.getString(R.string.search_online_address), new OnClickListener() {
@Override @Override

View file

@ -23,12 +23,12 @@ 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.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
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;
import net.osmand.plus.search.listitems.QuickSearchMoreListItem; import net.osmand.plus.search.listitems.QuickSearchMoreListItem;
import net.osmand.plus.search.listitems.QuickSearchSelectAllListItem; import net.osmand.plus.search.listitems.QuickSearchSelectAllListItem;
import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchPhrase; import net.osmand.search.core.SearchPhrase;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser; import net.osmand.util.OpeningHoursParser;
@ -235,7 +235,8 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
view.findViewById(R.id.empty_search).setVisibility(View.GONE); view.findViewById(R.id.empty_search).setVisibility(View.GONE);
view.findViewById(R.id.more_divider).setVisibility(View.GONE); view.findViewById(R.id.more_divider).setVisibility(View.GONE);
} }
if (!alreadyInOnlineSearch() && OsmandPlugin.isOnlineMapsTurnedOn()) { if (!app.getSearchUICore().getCore().getSearchSettings().alreadyInOnlineSearch()
&& OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
view.findViewById(R.id.online_search_row).setVisibility(View.VISIBLE); view.findViewById(R.id.online_search_row).setVisibility(View.VISIBLE);
view.findViewById(R.id.increase_radius_row).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.increase_radius_row).setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -430,18 +431,6 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
return view; return view;
} }
private boolean alreadyInOnlineSearch() {
ObjectType[] types = app.getSearchUICore().getCore().getSearchSettings().getSearchTypes();
if (types != null) {
for (ObjectType type : types) {
if (type == ObjectType.ONLINE_SEARCH) {
return true;
}
}
}
return false;
}
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

@ -1,5 +1,7 @@
package net.osmand.plus.search.listitems; package net.osmand.plus.search.listitems;
import android.support.annotation.Nullable;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -13,7 +15,7 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
private String restartSearch; private String restartSearch;
private String increaseRadius; private String increaseRadius;
public QuickSearchMoreListItem(OsmandApplication app, String name, SearchMoreItemOnClickListener onClickListener) { public QuickSearchMoreListItem(OsmandApplication app, String name, @Nullable SearchMoreItemOnClickListener onClickListener) {
super(app, null); super(app, null);
this.name = name; this.name = name;
this.onClickListener = onClickListener; this.onClickListener = onClickListener;
@ -58,11 +60,15 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
} }
public void increaseRadiusOnClick() { public void increaseRadiusOnClick() {
onClickListener.increaseRadiusOnClick(); if (onClickListener != null) {
onClickListener.increaseRadiusOnClick();
}
} }
public void onlineSearchOnClick() { public void onlineSearchOnClick() {
onClickListener.onlineSearchOnClick(); if (onClickListener != null) {
onClickListener.onlineSearchOnClick();
}
} }
public interface SearchMoreItemOnClickListener { public interface SearchMoreItemOnClickListener {