diff --git a/OsmAnd/res/layout/wikipedia_dialog_fragment.xml b/OsmAnd/res/layout/wikipedia_dialog_fragment.xml index db6b07919f..8dbb3f31ca 100644 --- a/OsmAnd/res/layout/wikipedia_dialog_fragment.xml +++ b/OsmAnd/res/layout/wikipedia_dialog_fragment.xml @@ -54,6 +54,15 @@ tools:text="En" tools:textColor="?attr/wikivoyage_active_color" /> + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 97c2b1d22f..5c55afa69f 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 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 --> + Show images You have cancel OsmAnd Live subscription Renew subscription to continue use the all features: diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java index b4170e1da4..b9fead599f 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikipediaDialogFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.wikipedia; import android.annotation.SuppressLint; import android.app.Dialog; import android.content.Context; +import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.net.Uri; @@ -10,6 +11,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.customtabs.CustomTabsIntent; +import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.PopupMenu; @@ -17,12 +19,12 @@ import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; -import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.webkit.WebSettings; import android.webkit.WebView; +import android.widget.ImageView; import android.widget.TextView; import net.osmand.AndroidUtils; @@ -30,10 +32,10 @@ import net.osmand.IndexConstants; import net.osmand.data.Amenity; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.helpers.FileNameTranslationHelper; +import net.osmand.plus.wikivoyage.WikipediaOptionsBottomSheetDialogFragment; import net.osmand.util.Algorithms; import java.io.File; @@ -47,10 +49,6 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment { public static final String TAG = "WikipediaDialogFragment"; - private static final int MENU_ITEM_NO_ID = 0; - private static final int MENU_ITEM_SHOW_ID = 1; - private static final int MENU_ITEM_WIFI_ID = 2; - private TextView readFullArticleButton; private Amenity amenity; @@ -75,7 +73,25 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment { setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar)); articleToolbarText = (TextView) mainView.findViewById(R.id.title_text_view); - + ImageView options = (ImageView) mainView.findViewById(R.id.options_button); + options.setImageDrawable(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color)); + options.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandApplication app = getMyApplication(); + if (app != null) { + FragmentManager fm = getFragmentManager(); + if (fm == null) { + return; + } + WikipediaOptionsBottomSheetDialogFragment fragment = new WikipediaOptionsBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); + fragment.setTargetFragment(WikipediaDialogFragment.this, + WikipediaOptionsBottomSheetDialogFragment.REQUEST_CODE); + fragment.show(fm, WikipediaOptionsBottomSheetDialogFragment.TAG); + } + } + }); ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(getContext(), nightMode, R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p); @@ -256,37 +272,12 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment { return showInstance(activity, amenity, null); } - protected void setupToolbar(Toolbar toolbar) { - super.setupToolbar(toolbar); - toolbar.setOverflowIcon(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color)); - - Menu menu = toolbar.getMenu(); - MenuItem.OnMenuItemClickListener itemClickListener = new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - OsmandApplication app = getMyApplication(); - if (app != null) { - int itemId = item.getItemId(); - if (itemId == MENU_ITEM_SHOW_ID) { - app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.ON); - return true; - } else if (itemId == MENU_ITEM_WIFI_ID) { - app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.WIFI); - return true; - } else if (itemId == MENU_ITEM_NO_ID) { - app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(OsmandSettings.WikiArticleShowImages.OFF); - return true; - } - } - return false; - } - }; - - MenuItem itemShow = menu.add(0, MENU_ITEM_SHOW_ID, 0, R.string.shared_string_show); - itemShow.setOnMenuItemClickListener(itemClickListener); - MenuItem itemWifi = menu.add(0, MENU_ITEM_WIFI_ID, 0, R.string.shared_string_only_with_wifi); - itemWifi.setOnMenuItemClickListener(itemClickListener); - MenuItem itemNo = menu.add(0, MENU_ITEM_NO_ID, 0, R.string.shared_string_dont); - itemNo.setOnMenuItemClickListener(itemClickListener); + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == WikipediaOptionsBottomSheetDialogFragment.SHOW_PICTURES_CHANGED_REQUEST_CODE) { + updateWebSettings(); + populateArticle(); + } } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikipediaOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikipediaOptionsBottomSheetDialogFragment.java new file mode 100644 index 0000000000..9532b7b57d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikipediaOptionsBottomSheetDialogFragment.java @@ -0,0 +1,70 @@ +package net.osmand.plus.wikivoyage; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v7.widget.PopupMenu; +import android.view.Gravity; +import android.view.MenuItem; +import android.view.View; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.WikiArticleShowImages; +import net.osmand.plus.R; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; + + +public class WikipediaOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { + + public final static String TAG = "WikipediaOptionsBottomSheetDialogFragment"; + + public static final int REQUEST_CODE = 0; + public static final int SHOW_PICTURES_CHANGED_REQUEST_CODE = 1; + + @Override + public void createMenuItems(Bundle savedInstanceState) { + final OsmandApplication app = getMyApplication(); + final OsmandSettings.CommonPreference showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES; + + items.add(new TitleItem(getString(R.string.shared_string_options))); + + BaseBottomSheetItem showImagesItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(showImagesPref.get().name)) + .setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light) + .setIcon(getContentIcon(R.drawable.ic_type_img)) + .setTitle(getString(R.string.download_images)) + .setLayoutId(R.layout.bottom_sheet_item_with_right_descr) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final PopupMenu popup = new PopupMenu(v.getContext(), v, Gravity.END); + for (final WikiArticleShowImages showImages : WikiArticleShowImages.values()) { + MenuItem item = popup.getMenu().add(getString(showImages.name)); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + showImagesPref.set(showImages); + sendResult(); + dismiss(); + return true; + } + }); + } + popup.show(); + } + }) + .create(); + items.add(showImagesItem); + } + + private void sendResult() { + Fragment fragment = getTargetFragment(); + if (fragment != null) { + fragment.onActivityResult(getTargetRequestCode(), SHOW_PICTURES_CHANGED_REQUEST_CODE, null); + } + } +} +