fix webview encoding in articlefragment

This commit is contained in:
Andrew Dolgov 2011-11-25 12:10:56 +03:00
parent 8c19ec257c
commit 20effebcbf
3 changed files with 42 additions and 7 deletions

View File

@ -6,8 +6,16 @@
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent" android:orientation="vertical">
<LinearLayout android:background="?articleHeader" android:layout_gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/article_header" android:padding="10dip">
<TextView android:singleLine="true" android:layout_weight="1" android:text="" android:layout_height="wrap_content" android:ellipsize="end" android:layout_width="match_parent" android:id="@+id/title" android:textSize="18dip"></TextView>
<LinearLayout android:background="?articleHeader" android:layout_gravity="center_vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/article_header" android:padding="10dip" android:orientation="vertical">
<TextView android:singleLine="true" android:layout_weight="1" android:text="{Title}" android:layout_height="wrap_content" android:ellipsize="end" android:layout_width="match_parent" android:id="@+id/title" android:textSize="18dip"></TextView>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView android:text="{COMMENTS}" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="wrap_content" android:id="@+id/comments"></TextView>
<TextView android:text="{DATE}" android:gravity="right" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/date"></TextView>
</LinearLayout>
</LinearLayout>
<ImageView android:background="?feedlistDivider" android:paddingTop="2dip" android:layout_weight="0" android:layout_height="wrap_content" android:layout_width="match_parent"></ImageView>

View File

@ -29,6 +29,7 @@
<string name="menu_unread_feeds">Show unread feeds</string>
<string name="menu_all_feeds">Show all feeds</string>
<string name="update_feeds">Refresh feeds</string>
<string name="close_article">Close article</string>
<string name="close_article">Close article</string>
<string name="share_article">Share article</string>
<string name="could_not_decode_content">Could not decode content (UnsupportedEncodingException)</string>
</resources>

View File

@ -1,6 +1,9 @@
package org.fox.ttrss;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.app.Fragment;
@ -37,8 +40,8 @@ public class ArticleFragment extends Fragment {
TextView title = (TextView)view.findViewById(R.id.title);
if (title != null) {
title.setText(Html.fromHtml("<a href=\""+URLEncoder.encode(m_article.link)+"\">" + m_article.title + "</a>"));
title.setMovementMethod(LinkMovementMethod.getInstance());
title.setText(Html.fromHtml("<a href=\""+m_article.link.replace("\"", "\\\"")+"\">" + m_article.title + "</a>"));
}
WebView web = (WebView)view.findViewById(R.id.content);
@ -47,13 +50,36 @@ public class ArticleFragment extends Fragment {
// this is ridiculous
// TODO white on black style for dark theme
String content = URLEncoder.encode("<html>" +
"<head><style type=\"text/css\">img { max-width : 90%; }</style></head>" +
"<body>" + m_article.content + "</body></html>").replace('+', ' ');
String content;
try {
content = URLEncoder.encode("<html>" +
"<head>" +
"<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\">" + // wtf, google?
"<style type=\"text/css\">img { max-width : 90%; }</style>" +
"</head>" +
"<body>" + m_article.content + "</body></html>", "utf-8").replace('+', ' ');
} catch (UnsupportedEncodingException e) {
content = getString(R.string.could_not_decode_content);
e.printStackTrace();
}
web.loadData(content, "text/html", "utf-8");
}
TextView dv = (TextView)view.findViewById(R.id.date);
if (dv != null) {
Date d = new Date(m_article.updated * 1000L);
SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy, HH:mm");
dv.setText(df.format(d));
}
TextView cv = (TextView)view.findViewById(R.id.comments);
// comments are not currently returned by the API
if (cv != null) {
cv.setVisibility(View.GONE);
}
}
return view;