Merge pull request #9266 from osmandapp/WikipediaSearchBanner

Add Wikipedia Banner in search for free app version
This commit is contained in:
vshcherb 2020-07-03 23:18:49 +02:00 committed by GitHub
commit df21ca4f57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 1087 additions and 356 deletions

View file

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:paddingTop="@dimen/content_padding"
app:srcCompat="@drawable/ic_action_subscription_osmand_live" />
</FrameLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_half"
android:layout_marginLeft="@dimen/content_padding_half"
android:layout_weight="1"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:paddingTop="@dimen/content_padding"
android:text="@string/read_wikipedia_offline"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:textStyle="bold"
osmand:typeface="@string/font_roboto_medium" />
<net.osmand.plus.widgets.TextViewEx
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier"
android:paddingTop="@dimen/content_padding_half"
android:paddingBottom="@dimen/content_padding_half"
android:text="@string/read_wikipedia_offline_description"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/btn_get"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:visibility="invisible">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:paddingTop="@dimen/content_padding"
app:srcCompat="@drawable/ic_action_subscription_osmand_live" />
</FrameLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding_half"
android:layout_marginLeft="@dimen/content_padding_half"
android:layout_weight="1"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:visibility="visible">
<net.osmand.plus.widgets.TextViewEx
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:text="@string/get_plugin"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_list_text_size"
android:textStyle="bold"
osmand:typeface="@string/font_roboto_medium" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

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,75 @@
<?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>
<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>

View file

@ -74,7 +74,7 @@
android:visibility="gone"/>
<LinearLayout
android:id="@+id/increase_radius_row"
android:id="@+id/primary_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
@ -100,7 +100,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/online_search_row"
android:id="@+id/secondary_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
@ -121,7 +121,7 @@
android:gravity="center">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/online_search_icon"
android:id="@+id/secondary_button_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
@ -130,6 +130,7 @@
android:tint="?attr/color_dialog_buttons"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/secondary_button_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_online_address"

View file

@ -11,6 +11,8 @@
Thx - Hardy
-->
<string name="plugin_wikipedia_description">Get information about points of interest from Wikipedia. It is your pocket offline guide - just enable Wikipedia plugin and enjoy articles about objects around you.</string>
<string name="search_download_wikipedia_maps">Download Wikipedia maps</string>
<string name="quick_action_remove_next_destination_descr">The current destination point on the route will be deleted. If it will be the Destination, navigation will stop.</string>
<string name="please_provide_point_name_error">Please provide a name for the point</string>
<string name="use_volume_buttons_as_zoom">Volume buttons as zoom</string>

View file

@ -21,6 +21,8 @@ import net.osmand.IProgress;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin;
import net.osmand.data.Amenity;
import net.osmand.data.MapObject;
import net.osmand.map.WorldRegion;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TabActivity.TabItem;
@ -39,14 +41,18 @@ import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.poi.PoiUIFilter;
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;
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;
@ -201,6 +207,10 @@ public abstract class OsmandPlugin {
return Collections.emptyList();
}
protected List<PoiUIFilter> getCustomPoiFilters() {
return Collections.emptyList();
}
/**
* Plugin was installed
*/
@ -258,12 +268,9 @@ public abstract class OsmandPlugin {
Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
allPlugins.clear();
allPlugins.add(new MapillaryPlugin(app));
if (!enabledPlugins.contains(MapillaryPlugin.ID) && !app.getSettings().getPlugins().contains("-" + MapillaryPlugin.ID)) {
enabledPlugins.add(MapillaryPlugin.ID);
app.getSettings().enablePlugin(MapillaryPlugin.ID, true);
}
enableHiddenPlugin(app, enabledPlugins, new MapillaryPlugin(app));
enableHiddenPlugin(app, enabledPlugins, new WikipediaPlugin(app));
allPlugins.add(new OsmandRasterMapsPlugin(app));
allPlugins.add(new OsmandMonitoringPlugin(app));
@ -368,6 +375,14 @@ public abstract class OsmandPlugin {
}
}
private static void enableHiddenPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
allPlugins.add(plugin);
if (!enabledPlugins.contains(plugin.getId()) && !app.getSettings().getPlugins().contains("-" + plugin.getId())) {
enabledPlugins.add(plugin.getId());
app.getSettings().enablePlugin(plugin.getId(), true);
}
}
private static void checkMarketPlugin(@NonNull OsmandApplication app, @NonNull Set<String> enabledPlugins, @NonNull OsmandPlugin plugin) {
if (updateMarketPlugin(app, enabledPlugins, plugin)) {
allPlugins.add(plugin);
@ -532,6 +547,24 @@ public abstract class OsmandPlugin {
protected void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) {
}
protected boolean searchFinished(QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) {
return false;
}
protected void newDownloadIndexes(Fragment fragment) {
}
protected void prepareExtraTopPoiFilters(Set<PoiUIFilter> poiUIFilter) {
}
protected String getMapObjectsLocale(Amenity amenity, String preferredLocale) {
return null;
}
protected String getMapObjectPreferredLang(MapObject object, String defaultLanguage) {
return null;
}
public List<String> indexingFiles(IProgress progress) {
return null;
}
@ -789,6 +822,52 @@ public abstract class OsmandPlugin {
}
}
public static boolean onSearchFinished(QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) {
boolean processed = false;
for (OsmandPlugin plugin : getEnabledPlugins()) {
processed = plugin.searchFinished(searchFragment, phrase, isResultEmpty) || processed;
}
return processed;
}
public static void onNewDownloadIndexes(Fragment fragment) {
for (OsmandPlugin plugin : getEnabledPlugins()) {
plugin.newDownloadIndexes(fragment);
}
}
public static void onPrepareExtraTopPoiFilters(Set<PoiUIFilter> poiUIFilters) {
for (OsmandPlugin plugin : getEnabledPlugins()) {
plugin.prepareExtraTopPoiFilters(poiUIFilters);
}
}
public static String onGetMapObjectPreferredLang(MapObject object, String preferredMapLang, String preferredMapAppLang) {
for (OsmandPlugin plugin : getEnabledPlugins()) {
String locale = plugin.getMapObjectPreferredLang(object, preferredMapLang);
if (locale != null) {
return locale;
}
}
return preferredMapAppLang;
}
public static String onGetMapObjectsLocale(Amenity amenity, String preferredLocale) {
for (OsmandPlugin plugin : getEnabledPlugins()) {
String locale = plugin.getMapObjectsLocale(amenity, preferredLocale);
if (locale != null) {
return locale;
}
}
return preferredLocale;
}
public static void registerCustomPoiFilters(List<PoiUIFilter> poiUIFilters) {
for (OsmandPlugin p : getEnabledPlugins()) {
poiUIFilters.addAll(p.getCustomPoiFilters());
}
}
public static Collection<DashFragmentData> getPluginsCardsList() {
HashSet<DashFragmentData> collection = new HashSet<>();
for (OsmandPlugin plugin : getEnabledPlugins()) {
@ -810,8 +889,6 @@ public abstract class OsmandPlugin {
return installed;
}
public static boolean onMapActivityKeyUp(MapActivity mapActivity, int keyCode) {
for (OsmandPlugin p : getEnabledPlugins()) {
if (p.mapActivityKeyUp(mapActivity, keyCode))

View file

@ -221,10 +221,6 @@ public class ConfigureMapMenu {
} else if (itemId == R.string.layer_gpx_layer && cm.getItem(pos).getSelected()) {
showGpxSelectionDialog(adapter, adapter.getItem(pos));
return false;
} else if (itemId == R.string.shared_string_wikipedia) {
ma.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.WIKIPEDIA,
AndroidUtils.getCenterViewCoordinates(view));
return false;
} else if (itemId == R.string.rendering_category_transport) {
final ContextMenuItem item = adapter.getItem(pos);
TransportLinesMenu.showTransportsDialog(ma, new CallbackWithObject<Boolean>() {
@ -288,18 +284,6 @@ public class ConfigureMapMenu {
} else {
showGpxSelectionDialog(adapter, adapter.getItem(pos));
}
} else if (itemId == R.string.shared_string_wikipedia) {
WikipediaPoiMenu.toggleWikipediaPoi(ma, isChecked, new CallbackWithObject<Boolean>() {
@Override
public boolean processResult(Boolean selected) {
item.setSelected(selected);
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setDescription(selected ?
WikipediaPoiMenu.getLanguagesSummary(ma.getMyApplication()) : null);
adapter.notifyDataSetChanged();
return true;
}
});
} else if (itemId == R.string.rendering_category_transport) {
boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication());
TransportLinesMenu.toggleTransportLines(ma, !selected, new CallbackWithObject<Boolean>() {
@ -436,17 +420,6 @@ public class ConfigureMapMenu {
.setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(l).createItem());
selected = app.getPoiFilters().isTopWikiFilterSelected();
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(WIKIPEDIA_ID)
.setTitleId(R.string.shared_string_wikipedia, activity)
.setDescription(selected ? WikipediaPoiMenu.getLanguagesSummary(app) : null)
.setSelected(selected)
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_plugin_wikipedia)
.setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(l).createItem());
selected = settings.SHOW_MAP_MARKERS.get();
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(MAP_MARKERS_ID)

View file

@ -196,8 +196,14 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
if (intent != null && intent.getExtras() != null) {
String region = getIntent().getStringExtra(REGION_TO_SEARCH);
if (region != null && !region.isEmpty()) {
showDialog(this, SearchDialogFragment.createInstance(region,
getIntent().getBooleanExtra(SHOW_WIKI_KEY, false)));
if (getIntent().getBooleanExtra(SHOW_WIKI_KEY, false)) {
showDialog(this, SearchDialogFragment.createInstance(
region, true, DownloadActivityType.NORMAL_FILE,
DownloadActivityType.WIKIPEDIA_FILE));
} else {
showDialog(this, SearchDialogFragment.createInstance(
region, true, DownloadActivityType.NORMAL_FILE));
}
}
filter = intent.getExtras().getString(FILTER_KEY);
filterCat = intent.getExtras().getString(FILTER_CAT);

View file

@ -402,7 +402,12 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
String filter = getDownloadActivity().getFilterAndClear();
String filterCat = getDownloadActivity().getFilterCatAndClear();
String filterGroup = getDownloadActivity().getFilterGroupAndClear();
if (filter != null) {
if (filter != null && filterCat != null
&& filterCat.equals(DownloadActivityType.WIKIPEDIA_FILE.getTag())) {
getDownloadActivity().showDialog(getActivity(),
SearchDialogFragment.createInstance(filter, false,
DownloadActivityType.WIKIPEDIA_FILE));
} else if (filter != null) {
getDownloadActivity().showDialog(getActivity(),
SearchDialogFragment.createInstance(filter));
} else if (filterCat != null) {

View file

@ -70,8 +70,11 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
public static final String TAG = "SearchDialogFragment";
private static final String SEARCH_TEXT_DLG_KEY = "search_text_dlg_key";
public static final String SHOW_GROUP_KEY = "show_group_key";
public static final String DOWNLOAD_TYPES_TO_SHOW_KEY = "download_types_to_show";
public static final String SHOW_WIKI_KEY = "show_wiki_key";
private boolean showWiki;
private boolean showGroup;
private ArrayList<String> downloadTypesToShow = new ArrayList<>();
private ListView listView;
private SearchListAdapter listAdapter;
private BannerAndDownloadFreeVersion banner;
@ -96,18 +99,22 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
if (savedInstanceState != null) {
searchText = savedInstanceState.getString(SEARCH_TEXT_DLG_KEY);
showWiki = savedInstanceState.getBoolean(SHOW_WIKI_KEY);
showGroup = savedInstanceState.getBoolean(SHOW_GROUP_KEY);
downloadTypesToShow = savedInstanceState.getStringArrayList(DOWNLOAD_TYPES_TO_SHOW_KEY);
}
if (searchText == null) {
Bundle arguments = getArguments();
if (arguments != null) {
searchText = arguments.getString(SEARCH_TEXT_DLG_KEY);
showWiki = arguments.getBoolean(SHOW_WIKI_KEY);
showGroup = arguments.getBoolean(SHOW_GROUP_KEY);
downloadTypesToShow = arguments.getStringArrayList(DOWNLOAD_TYPES_TO_SHOW_KEY);
}
}
if (searchText == null) {
searchText = "";
showWiki = false;
showGroup = true;
downloadTypesToShow = new ArrayList<>();
downloadTypesToShow.add(DownloadActivityType.NORMAL_FILE.getTag());
}
boolean isLightContent = getMyApplication().getSettings().isLightContent();
@ -227,7 +234,8 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString(SEARCH_TEXT_DLG_KEY, searchText);
outState.putBoolean(SHOW_WIKI_KEY, showWiki);
outState.putBoolean(SHOW_GROUP_KEY, showGroup);
outState.putStringArrayList(DOWNLOAD_TYPES_TO_SHOW_KEY, downloadTypesToShow);
super.onSaveInstanceState(outState);
}
@ -254,17 +262,23 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
return (DownloadActivity) getActivity();
}
public static SearchDialogFragment createInstance(String searchText, boolean showWiki) {
public static SearchDialogFragment createInstance(String searchText, boolean showGroup,
DownloadActivityType ... fileTypes) {
ArrayList<String> typesList = new ArrayList<>();
for (DownloadActivityType type : fileTypes) {
typesList.add(type.getTag());
}
Bundle bundle = new Bundle();
bundle.putString(SEARCH_TEXT_DLG_KEY, searchText);
bundle.putBoolean(SHOW_WIKI_KEY, showWiki);
bundle.putBoolean(SHOW_GROUP_KEY, showGroup);
bundle.putStringArrayList(DOWNLOAD_TYPES_TO_SHOW_KEY, typesList);
SearchDialogFragment fragment = new SearchDialogFragment();
fragment.setArguments(bundle);
return fragment;
}
public static SearchDialogFragment createInstance(String searchText) {
return createInstance(searchText, false);
return createInstance(searchText, true, DownloadActivityType.NORMAL_FILE);
}
@Override
@ -484,16 +498,19 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
&& group.getParentGroup().getParentGroup().getType() != DownloadResourceGroupType.WORLD
&& isMatch(conds, false, name)) {
filter.add(group);
if (showGroup) {
filter.add(group);
}
for (DownloadResourceGroup g : group.getGroups()) {
if (g.getType() == DownloadResourceGroupType.REGION_MAPS) {
if (g.getIndividualResources() != null) {
for (IndexItem item : g.getIndividualResources()) {
if (item.getType() == DownloadActivityType.NORMAL_FILE
|| (item.getType() == DownloadActivityType.WIKIPEDIA_FILE
&& showWiki)) {
filter.add(item);
for (String fileTypeTag : downloadTypesToShow) {
DownloadActivityType type = DownloadActivityType.getIndexType(fileTypeTag);
if (type != null && type == item.getType()) {
filter.add(item);
}
}
}
}

View file

@ -44,7 +44,6 @@ import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikipedia.WikipediaArticleWikiLinkFragment;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser;
@ -408,7 +407,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
if (amenity.getType().isWiki()) {
if (!hasWiki) {
String articleLang = WikipediaPoiMenu.getWikiArticleLanguage(app, amenity.getSupportedContentLocales(), preferredLang);
String articleLang = OsmandPlugin.onGetMapObjectsLocale(amenity, preferredLang);
String lng = amenity.getContentLanguage("content", articleLang, "en");
if (Algorithms.isEmpty(lng)) {
lng = "en";

View file

@ -13,7 +13,7 @@ import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiFilter;
import net.osmand.osm.PoiType;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
@ -22,7 +22,6 @@ import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser;
@ -158,15 +157,8 @@ public class AmenityMenuController extends MenuController {
@NonNull
@Override
public String getNameStr() {
String preferredLang = getPreferredMapLang();
if (amenity.getType().isWiki()) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
preferredLang = WikipediaPoiMenu.getWikiArticleLanguage(app,
amenity.getSupportedContentLocales(), getPreferredMapAppLang());
}
}
String preferredLang = OsmandPlugin.onGetMapObjectPreferredLang(amenity,
getPreferredMapAppLang(), getPreferredMapLang());
String name = amenity.getName(preferredLang, isTransliterateNames());
Map<String, String> additionalInfo = amenity.getAdditionalInfo();
if (additionalInfo != null) {

View file

@ -1,7 +1,5 @@
package net.osmand.plus.poi;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
@ -11,13 +9,13 @@ import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.api.SQLiteAPI.SQLiteStatement;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
import org.apache.commons.logging.Log;
import org.json.JSONArray;
@ -37,9 +35,6 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import static net.osmand.plus.wikipedia.WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY;
import static net.osmand.plus.wikipedia.WikipediaPoiMenu.GLOBAL_WIKI_POI_ENABLED_KEY;
public class PoiFiltersHelper {
private static final Log LOG = PlatformUtil.getLog(PoiFiltersHelper.class);
@ -116,31 +111,6 @@ public class PoiFiltersHelper {
return customPOIFilter;
}
public void prepareTopWikiFilter(@NonNull PoiUIFilter wiki) {
boolean prepareByDefault = true;
Bundle wikiSettings = WikipediaPoiMenu.getWikiPoiSettings(application);
if (wikiSettings != null) {
boolean allLanguages = wikiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY);
List<String> languages = wikiSettings
.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY);
if (!allLanguages && languages != null) {
prepareByDefault = false;
String wikiLang = "wiki:lang:";
StringBuilder sb = new StringBuilder();
for (String lang : languages) {
if (sb.length() > 1) {
sb.append(" ");
}
sb.append(wikiLang).append(lang);
}
wiki.setFilterByName(sb.toString());
}
}
if (prepareByDefault) {
wiki.setFilterByName(null);
}
}
public PoiUIFilter getTopWikiPoiFilter() {
if (topWikiPoiFilter == null) {
String wikiFilterId = PoiUIFilter.STD_PREFIX + "osmwiki";
@ -270,6 +240,7 @@ public class PoiFiltersHelper {
PoiUIFilter f = new PoiUIFilter(t, application, "");
top.add(f);
}
OsmandPlugin.registerCustomPoiFilters(top);
this.cacheTopStandardFilters = top;
}
List<PoiUIFilter> result = new ArrayList<>();
@ -485,11 +456,9 @@ public class PoiFiltersHelper {
}
public void addSelectedPoiFilter(PoiUIFilter filter) {
if (filter.isTopWikiFilter()) {
prepareTopWikiFilter(filter);
}
Set<PoiUIFilter> selectedPoiFilters = new TreeSet<>(this.selectedPoiFilters);
selectedPoiFilters.add(filter);
OsmandPlugin.onPrepareExtraTopPoiFilters(selectedPoiFilters);
saveSelectedPoiFilters(selectedPoiFilters);
this.selectedPoiFilters = selectedPoiFilters;
}
@ -579,12 +548,10 @@ public class PoiFiltersHelper {
for (String f : application.getSettings().getSelectedPoiFilters()) {
PoiUIFilter filter = getFilterById(f);
if (filter != null) {
if (filter.isTopWikiFilter()) {
prepareTopWikiFilter(filter);
}
selectedPoiFilters.add(filter);
}
}
OsmandPlugin.onPrepareExtraTopPoiFilters(selectedPoiFilters);
this.selectedPoiFilters = selectedPoiFilters;
}

View file

@ -74,11 +74,13 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
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;
@ -117,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);
@ -1173,7 +1176,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
if (getResultCollection() != null) {
updateSearchResult(getResultCollection(), false);
addMoreButton(searchUICore.isSearchMoreAvailable(searchUICore.getPhrase()));
onSearchFinished(searchUICore.getPhrase());
}
break;
}
@ -1707,7 +1710,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searching = false;
if (resultListener == null || resultListener.searchFinished(object.requiredSearchPhrase)) {
hideProgressBar();
addMoreButton(searchUICore.isSearchMoreAvailable(object.requiredSearchPhrase));
SearchPhrase phrase = object.requiredSearchPhrase;
onSearchFinished(phrase);
}
}
});
@ -1975,21 +1979,23 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
}
private void onSearchFinished(SearchPhrase phrase) {
if (!OsmandPlugin.onSearchFinished(this, phrase, isResultEmpty())) {
addMoreButton(searchUICore.isSearchMoreAvailable(phrase));
}
}
private void addMoreButton(boolean searchMoreAvailable) {
if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) {
QuickSearchMoreListItem moreListItem =
new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() {
@Override
public void increaseRadiusOnClick() {
if (!interruptedSearch) {
SearchSettings settings = searchUICore.getSearchSettings();
searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
}
runCoreSearch(searchQuery, false, true);
public void onPrimaryButtonClick() {
increaseSearchRadius();
}
@Override
public void onlineSearchOnClick() {
public void onSecondaryButtonClick() {
final OsmandSettings settings = app.getSettings();
if (!settings.isInternetConnectionAvailable()) {
Toast.makeText(app, R.string.internet_not_available, Toast.LENGTH_LONG).show();
@ -2003,13 +2009,27 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
});
moreListItem.setInterruptedSearch(interruptedSearch);
moreListItem.setEmptySearch(isResultEmpty());
moreListItem.setOnlineSearch(isOnlineSearch());
moreListItem.setSearchMoreAvailable(searchMoreAvailable);
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) {
@ -2305,6 +2325,29 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
updateFabHeight();
}
@Override
public void newDownloadIndexes() {
if (!searching) {
hideProgressBar();
}
OsmandPlugin.onNewDownloadIndexes(this);
}
@Override
public void downloadInProgress() {
}
@Override
public void downloadHasFinished() {
}
public void reloadIndexFiles() {
if (app.getSettings().isInternetConnectionAvailable()) {
app.getDownloadThread().runReloadIndexFiles();
showProgressBar();
}
}
public interface SearchResultListener {
void searchStarted(SearchPhrase phrase);
void publish(SearchResultCollection res, boolean append);

View file

@ -1,6 +1,5 @@
package net.osmand.plus.search;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
@ -11,13 +10,16 @@ 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.content.res.AppCompatResources;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
import net.osmand.CollatorStringMatcher;
@ -29,6 +31,9 @@ import net.osmand.plus.OsmAndFormatter;
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.QuickSearchFreeBannerListItem;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.search.listitems.QuickSearchHeaderListItem;
import net.osmand.plus.search.listitems.QuickSearchListItem;
@ -45,12 +50,14 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import static net.osmand.plus.search.listitems.QuickSearchBannerListItem.INVALID_ID;
import static net.osmand.search.core.ObjectType.POI_TYPE;
import static net.osmand.plus.search.listitems.QuickSearchBannerListItem.ButtonItem;
public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
private OsmandApplication app;
private Activity activity;
private FragmentActivity activity;
private AccessibilityAssistant accessibilityAssistant;
private LayoutInflater inflater;
@ -74,7 +81,7 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
void reloadData();
}
public QuickSearchListAdapter(OsmandApplication app, Activity activity) {
public QuickSearchListAdapter(OsmandApplication app, FragmentActivity activity) {
super(app, R.layout.search_list_item);
this.app = app;
this.activity = activity;
@ -203,7 +210,67 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
final QuickSearchListItem listItem = getItem(position);
QuickSearchListItemType type = listItem.getType();
LinearLayout view;
if (type == QuickSearchListItemType.SEARCH_MORE) {
if (type == QuickSearchListItemType.BANNER) {
final 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);
ViewGroup buttonContainer = view.findViewById(R.id.buttons_container);
if (buttonContainer != null) {
buttonContainer.removeAllViews();
for (ButtonItem button : banner.getButtonItems()) {
View v = inflater.inflate(R.layout.search_banner_button_list_item, null);
TextView title = v.findViewById(R.id.title);
title.setText(button.getTitle());
ImageView icon = v.findViewById(R.id.icon);
if (button.getIconId() != INVALID_ID) {
icon.setImageResource(button.getIconId());
icon.setVisibility(View.VISIBLE);
} else {
icon.setVisibility(View.GONE);
}
v.setOnClickListener(button.getListener());
buttonContainer.addView(v);
}
}
} else if (type == QuickSearchListItemType.FREE_VERSION_BANNER) {
if (convertView == null) {
view = (LinearLayout) inflater.inflate(
R.layout.read_wikipedia_ofline_banner, null);
} else {
view = (LinearLayout) convertView;
}
View btnGet = view.findViewById(R.id.btn_get);
if (btnGet != null) {
btnGet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChoosePlanDialogFragment.showWikipediaInstance(
activity.getSupportFragmentManager());
}
});
}
} else if (type == QuickSearchListItemType.SEARCH_MORE) {
if (convertView == null) {
view = (LinearLayout) inflater.inflate(R.layout.search_more_list_item, null);
} else {
@ -237,36 +304,27 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
textTitle = app.getString(R.string.search_nothing_found);
}
((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle);
View increaseRadiusRow = view.findViewById(R.id.increase_radius_row);
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));
increaseRadiusRow.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE);
increaseRadiusRow.setOnClickListener(new View.OnClickListener() {
primaryButton.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE);
primaryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((QuickSearchMoreListItem) listItem).increaseRadiusOnClick();
((QuickSearchMoreListItem) listItem).onPrimaryButtonClick();
}
});
if (!searchMoreItem.isOnlineSearch()) {
View onlineSearchRow = view.findViewById(R.id.online_search_row);
onlineSearchRow.setVisibility(View.VISIBLE);
onlineSearchRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
searchMoreItem.onlineSearchOnClick();
}
});
}
View secondaryButton = view.findViewById(R.id.secondary_button);
secondaryButton.setVisibility(searchMoreItem.isSecondaryButtonVisible() ?
View.VISIBLE : View.GONE);
secondaryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
searchMoreItem.onSecondaryButtonClick();
}
});
} else if (type == QuickSearchListItemType.BUTTON) {
if (convertView == null) {
view = (LinearLayout) inflater.inflate(R.layout.search_custom_list_item, null);
@ -451,6 +509,19 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
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) {

View file

@ -0,0 +1,64 @@
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 {
public static final int INVALID_ID = -1;
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

@ -0,0 +1,14 @@
package net.osmand.plus.search.listitems;
import net.osmand.plus.OsmandApplication;
public class QuickSearchFreeBannerListItem extends QuickSearchListItem {
public QuickSearchFreeBannerListItem(OsmandApplication app) {
super(app, null);
}
public QuickSearchListItemType getType() {
return QuickSearchListItemType.FREE_VERSION_BANNER;
}
}

View file

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

View file

@ -10,14 +10,15 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
private String name;
private SearchMoreItemOnClickListener onClickListener;
private boolean emptySearch;
private boolean onlineSearch;
private boolean searchMoreAvailable;
private boolean interruptedSearch;
private String findMore;
private String restartSearch;
private String increaseRadius;
private boolean secondaryButtonVisibility;
public QuickSearchMoreListItem(OsmandApplication app, String name, @Nullable SearchMoreItemOnClickListener onClickListener) {
public QuickSearchMoreListItem(OsmandApplication app, String name,
@Nullable SearchMoreItemOnClickListener onClickListener) {
super(app, null);
this.name = name;
this.onClickListener = onClickListener;
@ -61,14 +62,6 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
this.emptySearch = emptySearch;
}
public boolean isOnlineSearch() {
return onlineSearch;
}
public void setOnlineSearch(boolean onlineSearch) {
this.onlineSearch = onlineSearch;
}
public boolean isSearchMoreAvailable() {
return searchMoreAvailable;
}
@ -77,22 +70,31 @@ public class QuickSearchMoreListItem extends QuickSearchListItem {
this.searchMoreAvailable = searchMoreAvailable;
}
public void increaseRadiusOnClick() {
public void onPrimaryButtonClick() {
if (onClickListener != null) {
onClickListener.increaseRadiusOnClick();
onClickListener.onPrimaryButtonClick();
}
}
public void onlineSearchOnClick() {
public void onSecondaryButtonClick() {
if (onClickListener != null) {
onClickListener.onlineSearchOnClick();
onClickListener.onSecondaryButtonClick();
}
}
public void setSecondaryButtonVisible(boolean secondaryButtonVisibility) {
this.secondaryButtonVisibility = secondaryButtonVisibility;
}
public boolean isSecondaryButtonVisible() {
return secondaryButtonVisibility;
}
public interface SearchMoreItemOnClickListener {
void increaseRadiusOnClick();
void onPrimaryButtonClick();
void onSecondaryButtonClick();
void onlineSearchOnClick();
}
}

View file

@ -29,6 +29,7 @@ import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.PointImageDrawable;
@ -38,7 +39,6 @@ import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.routing.IRouteInformationListener;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
@ -331,20 +331,19 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override
public PointDescription getObjectName(Object o) {
if (o instanceof Amenity) {
Amenity a = (Amenity) o;
Amenity amenity = (Amenity) o;
String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get();
boolean transliterateNames = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
if (a.getType().isWiki()) {
if (amenity.getType().isWiki()) {
if (Algorithms.isEmpty(preferredLang)) {
preferredLang = app.getLanguage();
}
preferredLang = WikipediaPoiMenu.getWikiArticleLanguage(app,
a.getSupportedContentLocales(), preferredLang);
preferredLang = OsmandPlugin.onGetMapObjectsLocale(amenity, preferredLang);
}
return new PointDescription(PointDescription.POINT_TYPE_POI,
a.getName(preferredLang, transliterateNames));
amenity.getName(preferredLang, transliterateNames));
}
return null;
}

View file

@ -11,12 +11,10 @@ import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.os.ConfigurationCompat;
import androidx.core.os.LocaleListCompat;
import androidx.fragment.app.FragmentActivity;
import net.osmand.AndroidUtils;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
@ -26,6 +24,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.backend.ApplicationMode;
import java.util.ArrayList;
import java.util.Collections;
@ -34,16 +33,13 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
import static net.osmand.plus.wikipedia.WikipediaPoiMenu.ENABLED_WIKI_POI_LANGUAGES_KEY;
import static net.osmand.plus.wikipedia.WikipediaPoiMenu.GLOBAL_WIKI_POI_ENABLED_KEY;
public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = SelectWikiLanguagesBottomSheet.class.getSimpleName();
private OsmandApplication app;
private ApplicationMode appMode;
private OsmandSettings settings;
private WikipediaPlugin wikiPlugin;
private List<BottomSheetItemWithCompoundButton> languageItems;
@ -54,8 +50,8 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = requiredMyApplication();
settings = app.getSettings();
appMode = settings.getApplicationMode();
appMode = app.getSettings().getApplicationMode();
wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
initLanguagesData();
}
@ -67,7 +63,8 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
@Override
public void createMenuItems(Bundle savedInstanceState) {
final int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
final int activeColorResId = nightMode ?
R.color.active_color_primary_dark : R.color.active_color_primary_light;
final int profileColorResId = appMode.getIconColorInfo().getColor(nightMode);
final int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
@ -138,23 +135,21 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
preferredLocales.add(app.getLanguage());
preferredLocales.add(Locale.getDefault().getLanguage());
Bundle wikiPoiSettings = WikipediaPoiMenu.getWikiPoiSettings(app);
List<String> enabledWikiPoiLocales = null;
if (wikiPoiSettings != null) {
isGlobalWikiPoiEnabled = wikiPoiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY);
enabledWikiPoiLocales = wikiPoiSettings.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY);
}
if (enabledWikiPoiLocales != null) {
isGlobalWikiPoiEnabled = wikiPlugin.isShowAllLanguages();
if (wikiPlugin.hasLanguagesFilter()) {
List<String> enabledWikiPoiLocales = wikiPlugin.getLanguagesToShow();
for (String locale : app.getPoiTypes().getAllAvailableWikiLocales()) {
boolean checked = enabledWikiPoiLocales.contains(locale);
boolean topDefined = preferredLocales.contains(locale) || checked;
languages.add(new WikiLanguageItem(locale, WikipediaPoiMenu.getTranslation(app, locale), checked, topDefined));
languages.add(new WikiLanguageItem(locale,
wikiPlugin.getWikiLanguageTranslation(locale), checked, topDefined));
}
} else {
isGlobalWikiPoiEnabled = true;
for (String locale : app.getPoiTypes().getAllAvailableWikiLocales()) {
boolean topDefined = preferredLocales.contains(locale);
languages.add(new WikiLanguageItem(locale, WikipediaPoiMenu.getTranslation(app, locale), false, topDefined));
languages.add(new WikiLanguageItem(locale,
wikiPlugin.getWikiLanguageTranslation(locale), false, topDefined));
}
}
@ -162,8 +157,11 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
}
private void setLanguageListEnable(boolean enable) {
int textColorPrimaryId = nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light;
int disableColorId = nightMode ? R.color.active_buttons_and_links_text_disabled_dark : R.color.active_buttons_and_links_text_disabled_light;
int textColorPrimaryId = nightMode ?
R.color.text_color_primary_dark : R.color.text_color_primary_light;
int disableColorId = nightMode ?
R.color.active_buttons_and_links_text_disabled_dark :
R.color.active_buttons_and_links_text_disabled_light;
int profileColorId = appMode.getIconColorInfo().getColor(nightMode);
for (BottomSheetItemWithCompoundButton item : languageItems) {
item.getView().setEnabled(enable);
@ -171,7 +169,8 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
CompoundButton cb = item.getCompoundButton();
if (cb != null) {
cb.setEnabled(enable);
UiUtilities.setupCompoundButton(nightMode, ContextCompat.getColor(app, enable ? profileColorId : disableColorId), cb);
UiUtilities.setupCompoundButton(nightMode, ContextCompat.getColor(app, enable ?
profileColorId : disableColorId), cb);
}
}
}
@ -183,19 +182,15 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
@Override
protected void onRightBottomButtonClick() {
super.onRightBottomButtonClick();
List<String> localesForSaving = new ArrayList<>();
for (WikiLanguageItem language : languages) {
if (language.isChecked()) {
localesForSaving.add(language.getLocale());
}
}
settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsListForProfile(appMode, localesForSaving);
settings.GLOBAL_WIKIPEDIA_POI_ENABLED.setModeValue(appMode, isGlobalWikiPoiEnabled);
MapActivity ma = getMapActivity();
if (ma != null) {
WikipediaPoiMenu.updateWikipediaState(ma);
}
wikiPlugin.setLanguagesToShow(localesForSaving);
wikiPlugin.setShowAllLanguages(isGlobalWikiPoiEnabled);
wikiPlugin.updateWikipediaState();
dismiss();
}
@ -204,7 +199,8 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
if (app == null) {
return null;
}
View buttonView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_title_with_swith_56dp, null);
View buttonView = UiUtilities.getInflater(getContext(), nightMode)
.inflate(R.layout.bottom_sheet_item_title_with_swith_56dp, null);
CompoundButton cb = buttonView.findViewById(R.id.compound_button);
int color = nightMode ? R.color.divider_color_dark : R.color.divider_color_light;
@ -228,16 +224,7 @@ public class SelectWikiLanguagesBottomSheet extends MenuBottomSheetDialogFragmen
}
}
@Nullable
private MapActivity getMapActivity() {
FragmentActivity activity = getActivity();
if (activity instanceof MapActivity) {
return (MapActivity) activity;
}
return null;
}
private class WikiLanguageItem implements Comparable<WikiLanguageItem> {
private static class WikiLanguageItem implements Comparable<WikiLanguageItem> {
private String locale;
private String title;
private boolean checked;

View file

@ -282,8 +282,9 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment();
wikipediaDialogFragment.setAmenity(amenity);
lang = lang != null ? lang : WikipediaPoiMenu.getWikiArticleLanguage(app,
amenity.getSupportedContentLocales(), app.getSettings().MAP_PREFERRED_LOCALE.get());
WikipediaPlugin wikipediaPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
lang = lang != null ? lang : wikipediaPlugin.getMapObjectsLocale(amenity,
app.getSettings().MAP_PREFERRED_LOCALE.get());
wikipediaDialogFragment.setLanguage(lang);
wikipediaDialogFragment.setRetainInstance(true);
wikipediaDialogFragment.show(activity.getSupportFragmentManager(), TAG);

View file

@ -0,0 +1,413 @@
package net.osmand.plus.wikipedia;
import android.content.Intent;
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;
import net.osmand.data.Amenity;
import net.osmand.data.MapObject;
import net.osmand.osm.AbstractPoiType;
import net.osmand.plus.ContextMenuAdapter;
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;
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;
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;
import net.osmand.search.core.ObjectType;
import net.osmand.search.core.SearchPhrase;
import net.osmand.util.Algorithms;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID;
import static net.osmand.osm.MapPoiTypes.WIKI_LANG;
public class WikipediaPlugin extends OsmandPlugin {
public static final String ID = "osmand.wikipedia";
private MapActivity mapActivity;
private OsmandSettings settings;
private PoiUIFilter topWikiPoiFilter;
public WikipediaPlugin(OsmandApplication app) {
super(app);
this.settings = app.getSettings();
}
@Override
public boolean isVisible() {
return false;
}
@Override
public String getId() {
return ID;
}
@Override
public int getLogoResourceId() {
return R.drawable.ic_plugin_wikipedia;
}
@Override
public String getName() {
return app.getString(R.string.shared_string_wikipedia);
}
@Override
public CharSequence getDescription() {
return app.getString(R.string.plugin_wikipedia_description);
}
@Override
public void mapActivityResume(MapActivity activity) {
this.mapActivity = activity;
}
@Override
public void mapActivityPause(MapActivity activity) {
this.mapActivity = null;
}
@Override
protected void registerLayerContextMenuActions(OsmandMapTileView mapView,
ContextMenuAdapter adapter,
final MapActivity mapActivity) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
if (itemId == R.string.shared_string_wikipedia) {
mapActivity.getDashboard().setDashboardVisibility(true,
DashboardOnMap.DashboardType.WIKIPEDIA,
AndroidUtils.getCenterViewCoordinates(view));
}
return false;
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId,
final int pos, boolean isChecked, int[] viewCoordinates) {
if (itemId == R.string.shared_string_wikipedia) {
toggleWikipediaPoi(isChecked, new CallbackWithObject<Boolean>() {
@Override
public boolean processResult(Boolean selected) {
ContextMenuItem item = adapter.getItem(pos);
if (item != null) {
item.setSelected(selected);
item.setColorRes(selected ?
R.color.osmand_orange : ContextMenuItem.INVALID_ID);
item.setDescription(selected ? getLanguagesSummary() : null);
adapter.notifyDataSetChanged();
}
return true;
}
});
}
return false;
}
};
boolean selected = app.getPoiFilters().isTopWikiFilterSelected();
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(WIKIPEDIA_ID)
.setTitleId(R.string.shared_string_wikipedia, mapActivity)
.setDescription(selected ? getLanguagesSummary() : null)
.setSelected(selected)
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_plugin_wikipedia)
.setSecondaryIcon(R.drawable.ic_action_additional_option)
.setListener(listener).createItem());
}
@Override
protected List<PoiUIFilter> getCustomPoiFilters() {
List<PoiUIFilter> poiFilters = new ArrayList<>();
if (topWikiPoiFilter == null) {
AbstractPoiType poiType = app.getPoiTypes().getOsmwiki();
topWikiPoiFilter = new PoiUIFilter(poiType, app, "");
}
poiFilters.add(topWikiPoiFilter);
return poiFilters;
}
public void updateWikipediaState() {
if (isShowAllLanguages() || hasLanguagesFilter()) {
refreshWikiOnMap();
} else {
toggleWikipediaPoi(false, null);
}
}
public String getWikiLanguageTranslation(String locale) {
String translation = app.getLangTranslation(locale);
if (translation.equalsIgnoreCase(locale)) {
translation = getTranslationFromPhrases(locale);
}
return translation;
}
private String getTranslationFromPhrases(String locale) {
String keyName = WIKI_LANG + "_" + locale;
try {
Field f = R.string.class.getField("poi_" + keyName);
Integer in = (Integer) f.get(null);
return app.getString(in);
} catch (Throwable e) {
return locale;
}
}
public boolean hasCustomSettings() {
return !isShowAllLanguages() && getLanguagesToShow() != null;
}
public boolean hasLanguagesFilter() {
return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.get() != null;
}
public boolean isShowAllLanguages() {
return settings.GLOBAL_WIKIPEDIA_POI_ENABLED.get();
}
public void setShowAllLanguages(boolean showAllLanguages) {
settings.GLOBAL_WIKIPEDIA_POI_ENABLED.set(showAllLanguages);
}
public List<String> getLanguagesToShow() {
return settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getStringsList();
}
public void setLanguagesToShow(List<String> languagesToShow) {
settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.setStringsList(languagesToShow);
}
public void toggleWikipediaPoi(boolean enable, CallbackWithObject<Boolean> callback) {
if (enable) {
showWikiOnMap();
} else {
hideWikiFromMap();
}
if (callback != null) {
callback.processResult(enable);
} else if (mapActivity != null) {
mapActivity.getDashboard().refreshContent(true);
}
if (mapActivity != null) {
mapActivity.refreshMap();
}
}
public void refreshWikiOnMap() {
if (mapActivity == null) {
return;
}
app.getPoiFilters().loadSelectedPoiFilters();
mapActivity.getDashboard().refreshContent(true);
mapActivity.refreshMap();
}
private void showWikiOnMap() {
PoiFiltersHelper ph = app.getPoiFilters();
PoiUIFilter wiki = ph.getTopWikiPoiFilter();
ph.loadSelectedPoiFilters();
ph.addSelectedPoiFilter(wiki);
}
private void hideWikiFromMap() {
PoiFiltersHelper ph = app.getPoiFilters();
PoiUIFilter wiki = ph.getTopWikiPoiFilter();
ph.removePoiFilter(wiki);
ph.removeSelectedPoiFilter(wiki);
}
public String getLanguagesSummary() {
if (hasCustomSettings()) {
List<String> translations = new ArrayList<>();
for (String locale : getLanguagesToShow()) {
translations.add(getWikiLanguageTranslation(locale));
}
return android.text.TextUtils.join(", ", translations);
}
return app.getString(R.string.shared_string_all_languages);
}
@Override
protected String getMapObjectsLocale(Amenity amenity, String preferredLocale) {
return getWikiArticleLanguage(amenity.getSupportedContentLocales(), preferredLocale);
}
@Override
protected String getMapObjectPreferredLang(MapObject object, String defaultLanguage) {
if (object instanceof Amenity) {
Amenity amenity = (Amenity) object;
if (amenity.getType().isWiki()) {
return getWikiArticleLanguage(amenity.getSupportedContentLocales(), defaultLanguage);
}
}
return null;
}
public String getWikiArticleLanguage(@NonNull Set<String> availableArticleLangs, String preferredLanguage) {
if (!hasCustomSettings()) {
// Wikipedia with default settings
return preferredLanguage;
}
if (Algorithms.isEmpty(preferredLanguage)) {
preferredLanguage = app.getLanguage();
}
List<String> wikiLangs = getLanguagesToShow();
if (!wikiLangs.contains(preferredLanguage)) {
// return first matched language from enabled Wikipedia languages
for (String language : wikiLangs) {
if (availableArticleLangs.contains(language)) {
return language;
}
}
}
return preferredLanguage;
}
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);
}
}
public boolean hasMapsToDownload() {
try {
if (mapActivity == null) {
return false;
}
int mapsToDownloadCount = DownloadResources.findIndexItemsAt(
app, mapActivity.getMapLocation(), DownloadActivityType.WIKIPEDIA_FILE,
false, 1).size();
return mapsToDownloadCount > 0;
} catch (IOException e) {
return false;
}
}
@Override
protected boolean searchFinished(final QuickSearchDialogFragment searchFragment, SearchPhrase phrase, boolean isResultEmpty) {
if (isResultEmpty && isSearchByWiki(phrase)) {
if (!Version.isPaidVersion(app)) {
searchFragment.addSearchListItem(new QuickSearchFreeBannerListItem(app));
} else {
final DownloadIndexesThread downloadThread = app.getDownloadThread();
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
searchFragment.reloadIndexFiles();
} 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)) {
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);
}
@Override
protected void prepareExtraTopPoiFilters(Set<PoiUIFilter> poiUIFilters) {
for (PoiUIFilter filter : poiUIFilters) {
if (filter.isTopWikiFilter()) {
boolean prepareByDefault = true;
if (hasCustomSettings()) {
prepareByDefault = false;
String wikiLang = "wiki:lang:";
StringBuilder sb = new StringBuilder();
for (String lang : getLanguagesToShow()) {
if (sb.length() > 1) {
sb.append(" ");
}
sb.append(wikiLang).append(lang);
}
filter.setFilterByName(sb.toString());
}
if (prepareByDefault) {
filter.setFilterByName(null);
}
return;
}
}
}
private boolean isSearchByWiki(SearchPhrase phrase) {
if (phrase.isLastWord(ObjectType.POI_TYPE)) {
Object obj = phrase.getLastSelectedWord().getResult().object;
if (obj instanceof PoiUIFilter) {
PoiUIFilter pf = (PoiUIFilter) obj;
return pf.isWikiFilter();
} else if (obj instanceof AbstractPoiType) {
AbstractPoiType pt = (AbstractPoiType) obj;
return pt.getKeyName().startsWith(WIKI_LANG);
}
}
return false;
}
}

View file

@ -1,15 +1,11 @@
package net.osmand.plus.wikipedia;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import net.osmand.CallbackWithObject;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -18,32 +14,23 @@ import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.util.Algorithms;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static net.osmand.osm.MapPoiTypes.WIKI_LANG;
public class WikipediaPoiMenu {
public static final String GLOBAL_WIKI_POI_ENABLED_KEY = "global_wikipedia_poi_enabled_key";
public static final String ENABLED_WIKI_POI_LANGUAGES_KEY = "enabled_wikipedia_poi_languages_key";
private MapActivity mapActivity;
private OsmandApplication app;
private OsmandSettings settings;
private WikipediaPlugin wikiPlugin;
private boolean nightMode;
public WikipediaPoiMenu(MapActivity mapActivity) {
this.mapActivity = mapActivity;
this.app = mapActivity.getMyApplication();
this.settings = app.getSettings();
this.wikiPlugin = OsmandPlugin.getPlugin(WikipediaPlugin.class);
this.nightMode = app.getDaynightHelper().isNightModeForMapControls();
}
@ -65,7 +52,7 @@ public class WikipediaPoiMenu {
app.runInUIThread(new Runnable() {
@Override
public void run() {
toggleWikipediaPoi(mapActivity, !enabled, null);
wikiPlugin.toggleWikipediaPoi(!enabled, null);
}
});
} else if (itemId == languageActionStringId) {
@ -96,7 +83,7 @@ public class WikipediaPoiMenu {
.setLayout(R.layout.list_item_divider)
.createItem());
summary = getLanguagesSummary(app);
summary = wikiPlugin.getLanguagesSummary();
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(languageActionStringId, mapActivity)
.setIcon(R.drawable.ic_action_map_language)
@ -220,141 +207,8 @@ public class WikipediaPoiMenu {
return adapter;
}
public static void updateWikipediaState(MapActivity ma) {
final OsmandApplication app = ma.getMyApplication();
ApplicationMode appMode = app.getSettings().getApplicationMode();
Bundle wikiPoiSetting = getWikiPoiSettingsForProfile(app, appMode);
if (wikiPoiSetting != null) {
refreshWikipediaOnMap(ma);
} else {
toggleWikipediaPoi(ma, false, null);
}
}
public static String getTranslation(OsmandApplication app, String locale) {
String translation = app.getLangTranslation(locale);
if (translation.equalsIgnoreCase(locale)) {
translation = getTranslationFromPhrases(app, locale);
}
return translation;
}
private static String getTranslationFromPhrases(OsmandApplication app, String locale) {
String keyName = WIKI_LANG + "_" + locale;
try {
Field f = R.string.class.getField("poi_" + keyName);
Integer in = (Integer) f.get(null);
return app.getString(in);
} catch (Throwable e) {
return locale;
}
}
public static Bundle getWikiPoiSettings(OsmandApplication app) {
Bundle wikiSettings = getWikiPoiSettingsForProfile(app, app.getSettings().getApplicationMode());
if (wikiSettings == null) {
wikiSettings = getWikiPoiSettingsForProfile(app, app.getSettings().DEFAULT_APPLICATION_MODE.get());
}
return wikiSettings;
}
private static Bundle getWikiPoiSettingsForProfile(OsmandApplication app, ApplicationMode appMode) {
OsmandSettings settings = app.getSettings();
boolean globalWikiPoiEnabled = settings.GLOBAL_WIKIPEDIA_POI_ENABLED.getModeValue(appMode);
List<String> enabledWikiPoiLanguages = settings.WIKIPEDIA_POI_ENABLED_LANGUAGES.getStringsListForProfile(appMode);
if (!globalWikiPoiEnabled && Algorithms.isEmpty(enabledWikiPoiLanguages)) {
return null;
}
Bundle bundle = new Bundle();
bundle.putBoolean(GLOBAL_WIKI_POI_ENABLED_KEY, globalWikiPoiEnabled);
if (enabledWikiPoiLanguages != null) {
bundle.putStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY,
new ArrayList<>(enabledWikiPoiLanguages));
}
return bundle;
}
public static void toggleWikipediaPoi(final MapActivity mapActivity, boolean enable,
CallbackWithObject<Boolean> callback) {
OsmandApplication app = mapActivity.getMyApplication();
if (enable) {
showWikipediaOnMap(app);
} else {
hideWikipediaFromMap(app);
}
if (callback != null) {
callback.processResult(enable);
} else {
mapActivity.getDashboard().refreshContent(true);
}
mapActivity.refreshMap();
}
public static void refreshWikipediaOnMap(MapActivity mapActivity) {
OsmandApplication app = mapActivity.getMyApplication();
app.getPoiFilters().loadSelectedPoiFilters();
mapActivity.getDashboard().refreshContent(true);
mapActivity.refreshMap();
}
private static void showWikipediaOnMap(OsmandApplication app) {
PoiFiltersHelper ph = app.getPoiFilters();
PoiUIFilter wiki = ph.getTopWikiPoiFilter();
ph.loadSelectedPoiFilters();
ph.addSelectedPoiFilter(wiki);
}
private static void hideWikipediaFromMap(OsmandApplication app) {
PoiFiltersHelper ph = app.getPoiFilters();
PoiUIFilter wiki = ph.getTopWikiPoiFilter();
ph.removePoiFilter(wiki);
ph.removeSelectedPoiFilter(wiki);
}
public static String getLanguagesSummary(OsmandApplication app) {
Bundle wikiSetting = getWikiPoiSettings(app);
if (wikiSetting != null) {
boolean globalWikiEnabled = wikiSetting.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY);
List<String> enabledLocales = wikiSetting.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY);
if (!globalWikiEnabled && enabledLocales != null) {
List<String> translations = new ArrayList<>();
for (String locale : enabledLocales) {
translations.add(getTranslation(app, locale));
}
return android.text.TextUtils.join(", ", translations);
}
}
return app.getString(R.string.shared_string_all_languages);
}
public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) {
return new WikipediaPoiMenu(mapActivity).createLayersItems();
}
public static String getWikiArticleLanguage(@NonNull OsmandApplication app,
@NonNull Set<String> availableArticleLangs,
String preferredLanguage) {
Bundle wikiPoiSettings = getWikiPoiSettings(app);
if (!app.getPoiFilters().isTopWikiFilterSelected() || wikiPoiSettings == null) {
// Wikipedia POI setting disabled
return preferredLanguage;
}
if (wikiPoiSettings.getBoolean(GLOBAL_WIKI_POI_ENABLED_KEY)) {
// global Wikipedia POI filter enabled
return preferredLanguage;
}
if (Algorithms.isEmpty(preferredLanguage)) {
preferredLanguage = app.getLanguage();
}
List<String> wikiLangs = wikiPoiSettings.getStringArrayList(ENABLED_WIKI_POI_LANGUAGES_KEY);
if (wikiLangs != null && !wikiLangs.contains(preferredLanguage)) {
// return first matched language from enabled Wikipedia languages
for (String language : wikiLangs) {
if (availableArticleLangs.contains(language)) {
return language;
}
}
}
return preferredLanguage;
}
}