Make WikivoyageSearchResult not Parcelable
This commit is contained in:
parent
e96a67ce93
commit
c16465da8f
3 changed files with 22 additions and 57 deletions
|
@ -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 = "<html><head>\n" +
|
||||
|
@ -40,7 +43,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
|
|||
"</head><body>";
|
||||
private static final String FOOTER_INNER = "</div></body></html>";
|
||||
|
||||
private WikivoyageSearchResult searchResult;
|
||||
private long cityId = NO_VALUE;
|
||||
private ArrayList<String> 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<String> 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);
|
||||
|
|
|
@ -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<String> 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<WikivoyageSearchResult> CREATOR = new Creator<WikivoyageSearchResult>() {
|
||||
@Override
|
||||
public WikivoyageSearchResult createFromParcel(Parcel in) {
|
||||
return new WikivoyageSearchResult(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WikivoyageSearchResult[] newArray(int size) {
|
||||
return new WikivoyageSearchResult[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue