From 1019d10b5bc6a8eb0c289d6827b724dc6e00af05 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Sun, 15 Apr 2018 17:50:10 +0300 Subject: [PATCH] Added show wikivoyage pictures first time dialog --- ...ment_wikivoyage_show_images_first_time.xml | 109 ++++++++++++++++++ OsmAnd/res/values/strings.xml | 6 + .../src/net/osmand/plus/OsmandSettings.java | 1 + .../SettingsDevelopmentActivity.java | 12 +- .../WikivoyageShowPicturesDialogFragment.java | 66 +++++++++++ .../WikivoyageArticleContentsFragment.java | 8 +- .../WikivoyageArticleDialogFragment.java | 54 ++++++--- 7 files changed, 234 insertions(+), 22 deletions(-) create mode 100644 OsmAnd/res/layout/fragment_wikivoyage_show_images_first_time.xml create mode 100644 OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java diff --git a/OsmAnd/res/layout/fragment_wikivoyage_show_images_first_time.xml b/OsmAnd/res/layout/fragment_wikivoyage_show_images_first_time.xml new file mode 100644 index 0000000000..ec891a84cb --- /dev/null +++ b/OsmAnd/res/layout/fragment_wikivoyage_show_images_first_time.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index cc14704027..bff61aa316 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,12 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Don\'t + Do + Only with WiFi + Download Pictures + We can download & show images in the articles and store them on device, so you will access them while offline. + You can always change the setting in Explore > Options. Only WiFi Select travel book Travel book diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 871471ad39..5f01e9c314 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -717,6 +717,7 @@ 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 SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index 4bc30fe322..190452c22a 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -17,6 +17,7 @@ import android.view.View; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.actions.AppModeDialog; @@ -70,10 +71,13 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { @Override public boolean onPreferenceClick(Preference preference) { getMyApplication().getAppInitializer().resetFirstTimeRun(); - getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false); - getMyApplication().getSettings().MAPILLARY_FIRST_DIALOG_SHOWN.set(false); - getMyApplication().getSettings().WEBGL_SUPPORTED.set(true); - getMyApplication().getSettings().METRIC_SYSTEM_CHANGED_MANUALLY.set(false); + OsmandSettings settings = getMyApplication().getSettings(); + settings.FIRST_MAP_IS_DOWNLOADED.set(false); + 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); + getMyApplication().showToastMessage(R.string.shared_string_ok); return true; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java new file mode 100644 index 0000000000..5377bb69c0 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java @@ -0,0 +1,66 @@ +package net.osmand.plus.wikivoyage; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings.WikivoyageShowImages; +import net.osmand.plus.R; +import net.osmand.plus.base.BottomSheetDialogFragment; + +public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragment { + public static final String TAG = WikivoyageShowPicturesDialogFragment.class.getSimpleName(); + + public static final int SHOW_PICTURES_CHANGED = 1; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_wikivoyage_show_images_first_time, container, false); + view.findViewById(R.id.button_no).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.OFF); + } + sendResult(); + dismiss(); + } + }); + view.findViewById(R.id.button_wifi).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.WIFI); + } + sendResult(); + dismiss(); + } + }); + view.findViewById(R.id.button_yes).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.ON); + } + sendResult(); + dismiss(); + } + }); + + return view; + } + + private void sendResult() { + Fragment fragment = getTargetFragment(); + if (fragment != null) { + fragment.onActivityResult(getTargetRequestCode(), SHOW_PICTURES_CHANGED, null); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java index c9c92bbdf0..f705450861 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java @@ -76,7 +76,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag String name = wikivoyageContentItem.getLink().substring(1); sendResults(link, name); dismiss(); - return false; + return true; } }); expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @@ -87,7 +87,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag String name = wikivoyageContentItem.getLink().substring(1); sendResults(link, name); dismiss(); - return false; + return true; } }); LinearLayout container = new LinearLayout(getContext()); @@ -161,7 +161,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag } TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label); txtListChild.setText(childText); - txtListChild.setTextColor(getResolvedColor(nightMode + txtListChild.setTextColor(ContextCompat.getColor(context, nightMode ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)); txtListChild.setCompoundDrawablesWithIntrinsicBounds(itemChildIcon, null, null, null); @@ -208,7 +208,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag } TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label); lblListHeader.setText(headerTitle); - lblListHeader.setTextColor(getResolvedColor(nightMode ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)); + lblListHeader.setTextColor(ContextCompat.getColor(context, nightMode ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light)); lblListHeader.setCompoundDrawablesWithIntrinsicBounds(itemGroupIcon, null, null, null); adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, !nightMode); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 189934afae..390418eccb 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -8,6 +8,7 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v7.widget.PopupMenu; import android.support.v7.widget.Toolbar; @@ -25,9 +26,11 @@ import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.WikivoyageShowImages; import net.osmand.plus.R; import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment; +import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageWebViewClient; import net.osmand.plus.wikivoyage.data.WikivoyageArticle; @@ -150,29 +153,17 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen WikivoyageArticleContentsFragment fragment = new WikivoyageArticleContentsFragment(); fragment.setUsedOnMap(false); fragment.setArguments(args); - fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, 0); + fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, WikivoyageArticleContentsFragment.REQUEST_LINK_CODE); fragment.show(fm, WikivoyageArticleContentsFragment.TAG); } }); saveBtn = (TextView) mainView.findViewById(R.id.save_button); - OsmandSettings.WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get(); contentWebView = (WebView) mainView.findViewById(R.id.content_web_view); WebSettings webSettings = contentWebView.getSettings(); webSettings.setJavaScriptEnabled(true); - switch (showImages) { - case ON: - webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); - break; - case OFF: - webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); - break; - case WIFI: - webSettings.setCacheMode(getMyApplication().getSettings().isWifiConnected() ? - WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY); - break; - } + updateWebSettings(); contentWebView.setWebViewClient(new WikivoyageWebViewClient(getActivity(), getFragmentManager())); return mainView; @@ -196,6 +187,24 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen String link = data.getStringExtra(WikivoyageArticleContentsFragment.CONTENTS_LINK_KEY); String title = data.getStringExtra(WikivoyageArticleContentsFragment.CONTENTS_TITLE_KEY); moveToAnchor(link, title); + } else if (requestCode == WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED) { + updateWebSettings(); + populateArticle(); + } + } + + @Override + public void onResume() { + super.onResume(); + OsmandSettings settings = getMyApplication().getSettings(); + if (!settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.get()) { + FragmentActivity activity = getActivity(); + if (activity != null) { + WikivoyageShowPicturesDialogFragment fragment = new WikivoyageShowPicturesDialogFragment(); + fragment.setTargetFragment(this, WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED); + fragment.show(activity.getSupportFragmentManager(), WikivoyageShowPicturesDialogFragment.TAG); + settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(true); + } } } @@ -204,6 +213,23 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen return nightMode ? R.color.status_bar_wikivoyage_article_dark : R.color.status_bar_wikivoyage_article_light; } + private void updateWebSettings() { + WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get(); + WebSettings webSettings = contentWebView.getSettings(); + switch (showImages) { + case ON: + webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); + break; + case OFF: + webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY); + break; + case WIFI: + webSettings.setCacheMode(getMyApplication().getSettings().isWifiConnected() ? + WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY); + break; + } + } + private void updateSaveButton() { if (article != null) { final WikivoyageLocalDataHelper helper = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();