From 4ea5ab16db2b8fb1f007c018522241fcb480ded3 Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 12 Apr 2018 17:29:42 +0300 Subject: [PATCH] add options for icons cache and history --- OsmAnd/res/values/strings.xml | 5 +- .../src/net/osmand/plus/OsmandSettings.java | 2 + .../WikivoyageArticleDialogFragment.java | 4 +- ...sImagesCasheBottomSheetDialogFragment.java | 74 +++++++++++++++++++ .../WikivoyageExploreDialogFragment.java | 10 +++ .../search/SearchRecyclerViewAdapter.java | 3 +- 6 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/wikivoyage/explore/OptionsImagesCasheBottomSheetDialogFragment.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 6d00d5cf6c..6ef916f89b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,9 @@ Travel maps Wikivoyage Article removed + Images cache + Delete search history + Show images Search: Country, City, Province Read Saved articles @@ -311,7 +314,7 @@ Sea depth contour lines and nautical point maps. Thank you for purchasing nautical depth contours Nautical depth contours - + Worldwide Wikivoyage articles Southern hemisphere nautical depth points Northern hemisphere nautical depth points diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 4f8f2de103..68af0772d2 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -717,6 +717,8 @@ public class OsmandSettings { public final CommonPreference SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", false).makeProfile(); public final CommonPreference SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", false).makeProfile(); + public final CommonPreference SHOW_WEBVIEW_IMAGES = new BooleanPreference("show_webview_images", false); + public final CommonPreference SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile(); public final CommonPreference COORDS_INPUT_USE_RIGHT_SIDE = new BooleanPreference("coords_input_use_right_side", true).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 6edf4e53fa..de23079453 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -119,7 +119,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen contentWebView = (WebView) mainView.findViewById(R.id.content_web_view); contentWebView.getSettings().setJavaScriptEnabled(true); - + contentWebView.getSettings().setLoadsImagesAutomatically(getSettings().SHOW_WEBVIEW_IMAGES.get()); return mainView; } @@ -230,7 +230,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen StringBuilder sb = new StringBuilder(HEADER_INNER); String articleTitle = article.getImageTitle(); - if (!TextUtils.isEmpty(articleTitle)) { + if (!TextUtils.isEmpty(articleTitle)&&!getSettings().SHOW_WEBVIEW_IMAGES.get()) { String url = WikivoyageArticle.getImageUrl(articleTitle, false); sb.append("
"); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/OptionsImagesCasheBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/OptionsImagesCasheBottomSheetDialogFragment.java new file mode 100644 index 0000000000..a03d18bba3 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/OptionsImagesCasheBottomSheetDialogFragment.java @@ -0,0 +1,74 @@ +package net.osmand.plus.wikivoyage.explore; + +import android.os.Bundle; +import android.view.View; + +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; + +public class OptionsImagesCasheBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + + public final static String TAG = "OptionsImagesCasheBottomSheetDialogFragment"; + + @Override + public void createMenuItems(Bundle savedInstanceState) { + + items.add(new TitleItem(getString(R.string.shared_string_options))); + + boolean showWebviewImages = getMyApplication().getSettings().SHOW_WEBVIEW_IMAGES.get(); + + BaseBottomSheetItem showWebviewImagesItem = new BottomSheetItemWithCompoundButton.Builder() + .setChecked(showWebviewImages) + .setIcon(getContentIcon(R.drawable.ic_type_img)) + .setTitle(getString(R.string.wikivoyage_show_images)) + .setLayoutId(R.layout.bottom_sheet_item_with_switch) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandSettings settings = getMyApplication().getSettings(); + settings.SHOW_WEBVIEW_IMAGES.set(!settings.SHOW_WEBVIEW_IMAGES.get()); + dismiss(); + } + }) + .create(); + items.add(showWebviewImagesItem); + + BaseBottomSheetItem clearCacheItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(R.string.shared_string_clear)) + .setTitle(getString(R.string.wikivoyage_images_cache)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + dismiss(); + } + }) + .create(); + items.add(clearCacheItem); + + items.add(new DividerHalfItem(getContext())); + + BaseBottomSheetItem clearHistoryItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_history)) + .setTitle(getString(R.string.shared_string_delete_search_history)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + WikivoyageLocalDataHelper.getInstance(getMyApplication()).clearHistory(); + dismiss(); + } + }) + .create(); + items.add(clearHistoryItem); + } +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreDialogFragment.java index 7cb8ca66f1..5a4188c8a9 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageExploreDialogFragment.java @@ -20,6 +20,7 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.LockableViewPager; import net.osmand.plus.R; +import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment; import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment; @@ -53,6 +54,15 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen } }); + mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OptionsImagesCasheBottomSheetDialogFragment fragment = new OptionsImagesCasheBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); + fragment.show(getChildFragmentManager(), OptionsImagesCasheBottomSheetDialogFragment.TAG); + } + }); + final LockableViewPager viewPager = (LockableViewPager) mainView.findViewById(R.id.view_pager); viewPager.setOffscreenPageLimit(2); viewPager.setSwipeLocked(true); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java index a3f2b5679f..16a7d9fa98 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/SearchRecyclerViewAdapter.java @@ -74,7 +74,8 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter