From 678dd31017243804d3ebba600183f17c1af75e2a Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 9 Apr 2018 20:08:27 +0300 Subject: [PATCH] Choose the language for the wikivoyage article from history in the better way --- .../wikivoyage/WikivoyageArticleDialogFragment.java | 12 ++++++++++++ .../search/WikivoyageSearchDialogFragment.java | 6 +----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java index b8a6f168f7..0553e4840f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java @@ -57,6 +57,11 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { if (savedInstanceState != null) { selectedLang = savedInstanceState.getString(SELECTED_LANG_KEY); + } else { + Bundle args = getArguments(); + if (args != null) { + selectedLang = args.getString(SELECTED_LANG_KEY); + } } final View mainView = inflate(R.layout.fragment_wikivoyage_article_dialog, container); @@ -190,10 +195,17 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen } public static boolean showInstance(FragmentManager fm, long cityId, ArrayList langs) { + return showInstance(fm, cityId, langs, null); + } + + public static boolean showInstance(FragmentManager fm, long cityId, ArrayList langs, @Nullable String selectedLang) { try { Bundle args = new Bundle(); args.putLong(CITY_ID_KEY, cityId); args.putStringArrayList(LANGS_KEY, langs); + if (langs.contains(selectedLang)) { + args.putString(SELECTED_LANG_KEY, selectedLang); + } WikivoyageArticleDialogFragment fragment = new WikivoyageArticleDialogFragment(); fragment.setArguments(args); fragment.show(fm, TAG); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java index 4d96b3b4ee..32e262e7bf 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java @@ -111,12 +111,8 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment WikivoyageSearchHistoryItem historyItem = (WikivoyageSearchHistoryItem) item; ArrayList langs = getMyApplication().getWikivoyageDbHelper() .getArticleLangs(historyItem.getCityId()); - boolean selectedLangExists = langs.remove(historyItem.getLang()); - if (selectedLangExists) { - langs.add(0, historyItem.getLang()); - } WikivoyageArticleDialogFragment.showInstance(getFragmentManager(), - historyItem.getCityId(), langs); + historyItem.getCityId(), langs, historyItem.getLang()); } } }