From 14d08eafb389c38a192848143da46402220bce85 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 2 May 2018 19:26:56 +0300 Subject: [PATCH] refactored setupToolbar --- .../WikipediaDialogFragment.java | 54 +++++++++---------- .../WikivoyageShowPicturesDialogFragment.java | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java index 520f6daf7f..cb00eb78f5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -57,6 +57,10 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { ""; private static final String FOOTER_INNER = ""; + 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 WebView contentWebView; private TextView articleToolbarText; private TextView readFullArticleButton; @@ -327,39 +331,35 @@ public class WikipediaDialogFragment extends BaseOsmAndDialogFragment { toolbar.setNavigationIcon(getIcon(R.drawable.ic_arrow_back, R.color.icon_color)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); Menu menu = toolbar.getMenu(); - MenuItem itemShow = menu.add(R.string.shared_string_show); - itemShow.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + + MenuItem.OnMenuItemClickListener itemClickListener = new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { OsmandApplication app = getMyApplication(); if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.ON); + int itemId = item.getItemId(); + if (itemId == MENU_ITEM_SHOW_ID) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.ON); + return true; + } else if (itemId == MENU_ITEM_WIFI_ID) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.WIFI); + return true; + } else if (itemId == MENU_ITEM_NO_ID) { + app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.OFF); + return true; + } } - return true; + return false; } - }); - MenuItem itemWifi = menu.add(R.string.shared_string_only_with_wifi); - itemWifi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - OsmandApplication app = getMyApplication(); - if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.WIFI); - } - return true; - } - }); - MenuItem itemNo = menu.add(R.string.shared_string_dont); - itemNo.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - OsmandApplication app = getMyApplication(); - if (app != null) { - app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(OsmandSettings.WikivoyageShowImages.OFF); - } - return true; - } - }); + }; + + 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); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java index f7b63c9110..6811e23da9 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java @@ -59,7 +59,7 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm } }); } else { - buttonDownload.setText(R.string.shared_string_do); + buttonDownload.setText(R.string.shared_string_show); buttonDownload.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {