From 81449c9c2de548a9fb64f710149fa7cc2a5596af Mon Sep 17 00:00:00 2001 From: Chumva Date: Thu, 3 May 2018 15:27:47 +0300 Subject: [PATCH] renamed show image settings and refactored writeOutHTML --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 8 ++++---- .../SettingsDevelopmentActivity.java | 2 +- ...java => WikiArticleBaseDialogFragment.java} | 7 +++---- .../wikipedia/WikipediaDialogFragment.java | 9 ++++----- .../WikivoyageShowPicturesDialogFragment.java | 8 ++++---- .../plus/wikivoyage/WikivoyageUtils.java | 2 +- .../WikivoyageArticleDialogFragment.java | 18 +++++++----------- ...voyageOptionsBottomSheetDialogFragment.java | 6 +++--- 8 files changed, 27 insertions(+), 33 deletions(-) rename OsmAnd/src/net/osmand/plus/wikipedia/{ArticleBaseDialogFragment.java => WikiArticleBaseDialogFragment.java} (93%) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index fbe4f3e981..0b7f387a4a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -717,8 +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 WIKIVOYAGE_SHOW_IMAGES_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal(); - public final CommonPreference WIKIVOYAGE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikivoyageShowImages.OFF, WikivoyageShowImages.values()).makeGlobal(); + public final CommonPreference WIKI_ARTICLE_SHOW_IMAGES_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal(); + public final CommonPreference WIKI_ARTICLE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikiArticleShowImages.OFF, WikiArticleShowImages.values()).makeGlobal(); public final CommonPreference SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile(); @@ -3315,14 +3315,14 @@ public class OsmandSettings { EMPTY } - public enum WikivoyageShowImages { + public enum WikiArticleShowImages { ON(R.string.shared_string_on), OFF(R.string.shared_string_off), WIFI(R.string.shared_string_wifi_only); public final int name; - WikivoyageShowImages(int name) { + WikiArticleShowImages(int name) { this.name = name; } } diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index 190452c22a..bece3ea19a 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -76,7 +76,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(false); settings.WEBGL_SUPPORTED.set(true); settings.METRIC_SYSTEM_CHANGED_MANUALLY.set(false); - settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(false); + settings.WIKI_ARTICLE_SHOW_IMAGES_ASKED.set(false); getMyApplication().showToastMessage(R.string.shared_string_ok); return true; diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/ArticleBaseDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleBaseDialogFragment.java similarity index 93% rename from OsmAnd/src/net/osmand/plus/wikipedia/ArticleBaseDialogFragment.java rename to OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleBaseDialogFragment.java index b1cff7cdf7..c5b09a9463 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/ArticleBaseDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleBaseDialogFragment.java @@ -20,7 +20,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -public abstract class ArticleBaseDialogFragment extends WikivoyageBaseDialogFragment { +public abstract class WikiArticleBaseDialogFragment extends WikivoyageBaseDialogFragment { protected static final String HEADER_INNER = "\n" + "\n" + @@ -88,7 +88,7 @@ public abstract class ArticleBaseDialogFragment extends WikivoyageBaseDialogFrag protected void updateWebSettings() { - OsmandSettings.WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get(); + OsmandSettings.WikiArticleShowImages showImages = getSettings().WIKI_ARTICLE_SHOW_IMAGES.get(); WebSettings webSettings = contentWebView.getSettings(); switch (showImages) { case ON: @@ -113,8 +113,7 @@ public abstract class ArticleBaseDialogFragment extends WikivoyageBaseDialogFrag return "file:///android_asset/"; } - protected void writeOutHTML(StringBuilder sb) { - File file = new File(getMyApplication().getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), "page.html"); + protected void writeOutHTML(StringBuilder sb, File file) { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(file)); diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java index 1b18ac6cac..94d93d39b4 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java @@ -31,7 +31,6 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.helpers.FileNameTranslationHelper; -import net.osmand.plus.wikipedia.ArticleBaseDialogFragment; import net.osmand.util.Algorithms; import java.util.HashMap; @@ -40,7 +39,7 @@ import java.util.Set; import java.util.TreeSet; -public class WikipediaDialogFragment extends ArticleBaseDialogFragment { +public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment { public static final String TAG = "WikipediaDialogFragment"; @@ -267,13 +266,13 @@ public class WikipediaDialogFragment extends ArticleBaseDialogFragment { if (app != null) { int itemId = item.getItemId(); if (itemId == MENU_ITEM_SHOW_ID) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.ON); + app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.ON); return true; } else if (itemId == MENU_ITEM_WIFI_ID) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.WIFI); + app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.WIFI); return true; } else if (itemId == MENU_ITEM_NO_ID) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.OFF); + app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.OFF); return true; } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java index 6811e23da9..4a15189776 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java @@ -16,7 +16,7 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings.WikivoyageShowImages; +import net.osmand.plus.OsmandSettings.WikiArticleShowImages; import net.osmand.plus.R; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -38,7 +38,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm public void onClick(View v) { OsmandApplication app = getMyApplication(); if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.OFF); + app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.OFF); } sendResult(); dismiss(); @@ -52,7 +52,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm public void onClick(View v) { OsmandApplication app = getMyApplication(); if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.WIFI); + app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.WIFI); } sendResult(); dismiss(); @@ -65,7 +65,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm public void onClick(View v) { OsmandApplication app = getMyApplication(); if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.ON); + app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.ON); } sendResult(); dismiss(); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java index 70f500d176..42bb7f8f5a 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageUtils.java @@ -8,7 +8,7 @@ import net.osmand.plus.OsmandSettings; public class WikivoyageUtils { public static void setupNetworkPolicy(OsmandSettings settings, RequestCreator rc) { - switch (settings.WIKIVOYAGE_SHOW_IMAGES.get()) { + switch (settings.WIKI_ARTICLE_SHOW_IMAGES.get()) { case ON: break; case OFF: diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index fdf0c96d5f..98cd31fe51 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -13,7 +13,6 @@ import android.support.v4.app.FragmentManager.BackStackEntry; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.Toolbar; import android.text.TextUtils; -import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuItem; @@ -32,7 +31,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.helpers.FileNameTranslationHelper; -import net.osmand.plus.wikipedia.ArticleBaseDialogFragment; +import net.osmand.plus.wikipedia.WikiArticleBaseDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageWebViewClient; import net.osmand.plus.wikivoyage.data.TravelArticle; @@ -40,10 +39,7 @@ import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.util.Algorithms; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; -import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -51,10 +47,10 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import static net.osmand.plus.OsmandSettings.WikivoyageShowImages.OFF; +import static net.osmand.plus.OsmandSettings.WikiArticleShowImages.OFF; -public class WikivoyageArticleDialogFragment extends ArticleBaseDialogFragment { +public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragment { public static final String TAG = "WikivoyageArticleDialogFragment"; @@ -211,14 +207,14 @@ public class WikivoyageArticleDialogFragment extends ArticleBaseDialogFragment { public void onResume() { super.onResume(); OsmandSettings settings = getMyApplication().getSettings(); - if (!settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.get()) { + if (!settings.WIKI_ARTICLE_SHOW_IMAGES_ASKED.get()) { FragmentActivity activity = getActivity(); FragmentManager fm = getFragmentManager(); if (activity != null && fm != null) { WikivoyageShowPicturesDialogFragment fragment = new WikivoyageShowPicturesDialogFragment(); fragment.setTargetFragment(this, WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE); fragment.show(fm, WikivoyageShowPicturesDialogFragment.TAG); - settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(true); + settings.WIKI_ARTICLE_SHOW_IMAGES_ASKED.set(true); } } } @@ -337,7 +333,7 @@ public class WikivoyageArticleDialogFragment extends ArticleBaseDialogFragment { } } String url = TravelArticle.getImageUrl(imageTitle, false); - if (!TextUtils.isEmpty(imageTitle) && getSettings().WIKIVOYAGE_SHOW_IMAGES.get() != OFF && + if (!TextUtils.isEmpty(imageTitle) && getSettings().WIKI_ARTICLE_SHOW_IMAGES.get() != OFF && !url.startsWith(EMPTY_URL)) { sb.append("
"); } @@ -349,7 +345,7 @@ public class WikivoyageArticleDialogFragment extends ArticleBaseDialogFragment { sb.append(article.getContent()); sb.append(FOOTER_INNER); if (OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) != null) { - writeOutHTML(sb); + writeOutHTML(sb, new File(getMyApplication().getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), "page.html")); } return sb.toString(); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java index f5e9500bb9..98d6bfd5d5 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java @@ -15,7 +15,7 @@ import android.webkit.WebView; import net.osmand.PicassoUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.WikivoyageShowImages; +import net.osmand.plus.OsmandSettings.WikiArticleShowImages; import net.osmand.plus.R; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; @@ -40,7 +40,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD @Override public void createMenuItems(Bundle savedInstanceState) { final OsmandApplication app = getMyApplication(); - final OsmandSettings.CommonPreference showImagesPref = app.getSettings().WIKIVOYAGE_SHOW_IMAGES; + final OsmandSettings.CommonPreference showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES; final TravelDbHelper dbHelper = app.getTravelDbHelper(); items.add(new TitleItem(getString(R.string.shared_string_options))); @@ -75,7 +75,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END); - for (final WikivoyageShowImages showImages : WikivoyageShowImages.values()) { + for (final WikiArticleShowImages showImages : WikiArticleShowImages.values()) { MenuItem item = popup.getMenu().add(getString(showImages.name)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override