Replace TextView with WebView; make WikivoyageSearchResult parcelable
This commit is contained in:
parent
7807b54504
commit
6d86f021ce
3 changed files with 54 additions and 23 deletions
|
@ -17,15 +17,9 @@
|
|||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<ScrollView
|
||||
<WebView
|
||||
android:id="@+id/content_web_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/content_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</ScrollView>
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -4,12 +4,10 @@ import android.os.Bundle;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
|
@ -20,11 +18,7 @@ public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment {
|
|||
|
||||
public static final String TAG = "WikivoyageArticleDialogFragment";
|
||||
|
||||
private WikivoyageSearchResult searchResult;
|
||||
|
||||
public void setSearchResult(WikivoyageSearchResult searchResult) {
|
||||
this.searchResult = searchResult;
|
||||
}
|
||||
private static final String SEARCH_RESULT_KEY = "search_result_key";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
@ -41,18 +35,22 @@ public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment {
|
|||
}
|
||||
});
|
||||
|
||||
TextView contentTv = (TextView) mainView.findViewById(R.id.content_text_view);
|
||||
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper().getArticle(searchResult.getCityId(),
|
||||
searchResult.getLang().get(0));
|
||||
contentTv.setText(new SpannableString(Html.fromHtml(article.getContent())));
|
||||
WikivoyageSearchResult searchResult = (WikivoyageSearchResult) getArguments().getParcelable(SEARCH_RESULT_KEY);
|
||||
|
||||
WebView contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
|
||||
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper()
|
||||
.getArticle(searchResult.getCityId(), searchResult.getLang().get(0));
|
||||
contentWebView.loadData(article.getContent(), "text/html", "UTF-8");
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fm, WikivoyageSearchResult searchResult) {
|
||||
try {
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(SEARCH_RESULT_KEY, searchResult);
|
||||
WikivoyageArticleDialogFragment fragment = new WikivoyageArticleDialogFragment();
|
||||
fragment.setSearchResult(searchResult);
|
||||
fragment.setArguments(args);
|
||||
fragment.show(fm, TAG);
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
|
|
|
@ -1,15 +1,29 @@
|
|||
package net.osmand.plus.wikivoyage.data;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WikivoyageSearchResult {
|
||||
public class WikivoyageSearchResult implements Parcelable {
|
||||
|
||||
List<String> searchTerm = new ArrayList<>();
|
||||
long cityId;
|
||||
List<String> articleTitle = new ArrayList<>();
|
||||
List<String> langs = new ArrayList<>();
|
||||
|
||||
WikivoyageSearchResult() {
|
||||
|
||||
}
|
||||
|
||||
private WikivoyageSearchResult(Parcel in) {
|
||||
searchTerm = in.createStringArrayList();
|
||||
cityId = in.readLong();
|
||||
articleTitle = in.createStringArrayList();
|
||||
langs = in.createStringArrayList();
|
||||
}
|
||||
|
||||
public List<String> getSearchTerm() {
|
||||
return searchTerm;
|
||||
}
|
||||
|
@ -25,4 +39,29 @@ public class WikivoyageSearchResult {
|
|||
public List<String> getLang() {
|
||||
return langs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeStringList(searchTerm);
|
||||
dest.writeLong(cityId);
|
||||
dest.writeStringList(articleTitle);
|
||||
dest.writeStringList(langs);
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue