diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java index c82f75f5c0..28c2f63cc5 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageArticleDialogFragment.java @@ -22,15 +22,18 @@ import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.plus.R; import net.osmand.plus.wikivoyage.data.WikivoyageArticle; -import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult; import java.io.File; +import java.util.ArrayList; public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragment { public static final String TAG = "WikivoyageArticleDialogFragment"; - private static final String SEARCH_RESULT_KEY = "search_result_key"; + private static final long NO_VALUE = -1; + + private static final String CITY_ID_KEY = "city_id_key"; + private static final String LANGS_KEY = "langs_key"; private static final String SELECTED_LANG_KEY = "selected_lang_key"; private static final String HEADER_INNER = "\n" + @@ -40,7 +43,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen ""; private static final String FOOTER_INNER = ""; - private WikivoyageSearchResult searchResult; + private long cityId = NO_VALUE; + private ArrayList langs; private String selectedLang; private TextView selectedLangTv; @@ -97,12 +101,12 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen } private void showPopupLangMenu(View view) { - if (searchResult == null) { + if (langs == null) { return; } final PopupMenu popup = new PopupMenu(view.getContext(), view, Gravity.END); - for (final String lang : searchResult.getLangs()) { + for (final String lang : langs) { MenuItem item = popup.getMenu().add(lang); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override @@ -120,23 +124,24 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen } private void populateArticle() { - if (searchResult == null) { + if (cityId == NO_VALUE || langs == null) { Bundle args = getArguments(); if (args != null) { - searchResult = (WikivoyageSearchResult) args.getParcelable(SEARCH_RESULT_KEY); + cityId = args.getLong(CITY_ID_KEY); + langs = args.getStringArrayList(LANGS_KEY); } } - if (searchResult == null) { + if (cityId == NO_VALUE || langs == null || langs.isEmpty()) { return; } if (selectedLang == null) { - selectedLang = searchResult.getLangs().get(0); + selectedLang = langs.get(0); } selectedLangTv.setText(selectedLang); WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper() - .getArticle(searchResult.getCityId(), selectedLang); + .getArticle(cityId, selectedLang); if (article == null) { return; } @@ -180,10 +185,11 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen return normal; } - public static boolean showInstance(FragmentManager fm, WikivoyageSearchResult searchResult) { + public static boolean showInstance(FragmentManager fm, long cityId, ArrayList langs) { try { Bundle args = new Bundle(); - args.putParcelable(SEARCH_RESULT_KEY, searchResult); + args.putLong(CITY_ID_KEY, cityId); + args.putStringArrayList(LANGS_KEY, langs); WikivoyageArticleDialogFragment fragment = new WikivoyageArticleDialogFragment(); fragment.setArguments(args); fragment.show(fm, TAG); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java index 8fae83a095..59d60ea5aa 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageSearchResult.java @@ -1,14 +1,11 @@ package net.osmand.plus.wikivoyage.data; -import android.os.Parcel; -import android.os.Parcelable; - import net.osmand.util.Algorithms; import java.util.ArrayList; import java.util.List; -public class WikivoyageSearchResult implements Parcelable { +public class WikivoyageSearchResult { private static final int SHOW_LANGS = 3; @@ -19,19 +16,6 @@ public class WikivoyageSearchResult implements Parcelable { String isPartOf; String imageTitle; - WikivoyageSearchResult() { - - } - - private WikivoyageSearchResult(Parcel in) { - searchTerms = in.createStringArrayList(); - cityId = in.readLong(); - articleTitles = in.createStringArrayList(); - langs = in.createStringArrayList(); - isPartOf = in.readString(); - imageTitle = in.readString(); - } - public List getSearchTerms() { return searchTerms; } @@ -67,31 +51,4 @@ public class WikivoyageSearchResult implements Parcelable { } return res.toString(); } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeStringList(searchTerms); - dest.writeLong(cityId); - dest.writeStringList(articleTitles); - dest.writeStringList(langs); - dest.writeString(isPartOf); - dest.writeString(imageTitle); - } - - public static final Creator CREATOR = new Creator() { - @Override - public WikivoyageSearchResult createFromParcel(Parcel in) { - return new WikivoyageSearchResult(in); - } - - @Override - public WikivoyageSearchResult[] newArray(int size) { - return new WikivoyageSearchResult[size]; - } - }; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java index e936df7745..36c8f9038f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java @@ -22,6 +22,7 @@ import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment; import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult; +import java.util.ArrayList; import java.util.List; public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment { @@ -100,8 +101,9 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment if (pos != RecyclerView.NO_POSITION) { Object item = adapter.getItem(pos); if (item instanceof WikivoyageSearchResult) { + WikivoyageSearchResult res = (WikivoyageSearchResult) item; WikivoyageArticleDialogFragment.showInstance(getFragmentManager(), - (WikivoyageSearchResult) item); + res.getCityId(), new ArrayList<>(res.getLangs())); } } }