2011-09-09 11:58:11 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
2011-11-25 09:10:56 +00:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2011-11-23 16:38:21 +00:00
|
|
|
import java.net.URLEncoder;
|
2011-11-25 09:10:56 +00:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
2011-11-23 16:38:21 +00:00
|
|
|
|
2011-09-09 11:58:11 +00:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Fragment;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
2011-11-24 14:57:44 +00:00
|
|
|
import android.text.Html;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
2011-09-09 11:58:11 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2011-09-09 16:36:09 +00:00
|
|
|
import android.webkit.WebView;
|
|
|
|
import android.widget.TextView;
|
2011-09-09 11:58:11 +00:00
|
|
|
|
2011-11-24 14:57:44 +00:00
|
|
|
public class ArticleFragment extends Fragment {
|
2011-09-09 16:36:09 +00:00
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
|
|
|
protected SharedPreferences m_prefs;
|
2011-11-23 12:51:15 +00:00
|
|
|
|
2011-11-23 16:38:21 +00:00
|
|
|
private Article m_article;
|
2011-09-09 11:58:11 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
2011-11-25 10:32:32 +00:00
|
|
|
m_article = savedInstanceState.getParcelable("article");
|
2011-09-09 11:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
View view = inflater.inflate(R.layout.article_fragment, container, false);
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-11-23 16:38:21 +00:00
|
|
|
if (m_article != null) {
|
|
|
|
|
|
|
|
TextView title = (TextView)view.findViewById(R.id.title);
|
|
|
|
|
|
|
|
if (title != null) {
|
2011-11-24 14:57:44 +00:00
|
|
|
title.setMovementMethod(LinkMovementMethod.getInstance());
|
2011-11-25 09:10:56 +00:00
|
|
|
title.setText(Html.fromHtml("<a href=\""+m_article.link.replace("\"", "\\\"")+"\">" + m_article.title + "</a>"));
|
2011-11-23 16:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WebView web = (WebView)view.findViewById(R.id.content);
|
|
|
|
|
|
|
|
if (web != null) {
|
|
|
|
|
|
|
|
// this is ridiculous
|
2011-11-24 14:57:44 +00:00
|
|
|
// TODO white on black style for dark theme
|
2011-11-25 09:10:56 +00:00
|
|
|
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();
|
|
|
|
}
|
2011-11-23 16:38:21 +00:00
|
|
|
|
|
|
|
web.loadData(content, "text/html", "utf-8");
|
|
|
|
}
|
2011-11-24 12:08:02 +00:00
|
|
|
|
2011-11-25 09:10:56 +00:00
|
|
|
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);
|
|
|
|
}
|
2011-11-23 16:38:21 +00:00
|
|
|
}
|
|
|
|
|
2011-09-09 11:58:11 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2011-09-11 09:04:48 +00:00
|
|
|
super.onDestroy();
|
2011-09-09 11:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-09-09 16:36:09 +00:00
|
|
|
public void onSaveInstanceState (Bundle out) {
|
2011-09-09 11:58:11 +00:00
|
|
|
super.onSaveInstanceState(out);
|
2011-09-09 16:36:09 +00:00
|
|
|
|
2011-11-25 10:32:32 +00:00
|
|
|
out.putParcelable("article", m_article);
|
2011-09-09 11:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
2011-11-23 16:38:21 +00:00
|
|
|
|
|
|
|
m_article = ((MainActivity)activity).getSelectedArticle();
|
2011-09-09 11:58:11 +00:00
|
|
|
}
|
|
|
|
}
|