summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>2011-11-25 12:10:56 +0300
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>2011-11-25 12:10:56 +0300
commit20effebcbf1f0a56ef7f5e39362e947b2ece20d1 (patch)
treeb3f1abfe636246f6d2bc6086c25b2895aec6a378
parent8c19ec257c8df6cc13a19e4df674423ec4644cc1 (diff)
fix webview encoding in articlefragment
-rw-r--r--res/layout/article_fragment.xml12
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/org/fox/ttrss/ArticleFragment.java34
3 files changed, 42 insertions, 7 deletions
diff --git a/res/layout/article_fragment.xml b/res/layout/article_fragment.xml
index 48b597de..dde2265d 100644
--- a/res/layout/article_fragment.xml
+++ b/res/layout/article_fragment.xml
@@ -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>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6441033b..b951c291 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -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>
diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java
index 7e1d528f..511932bc 100644
--- a/src/org/fox/ttrss/ArticleFragment.java
+++ b/src/org/fox/ttrss/ArticleFragment.java
@@ -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;