2011-09-09 11:58:11 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
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-12-07 12:25:50 +00:00
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
import org.jsoup.select.Elements;
|
2011-11-28 09:45:19 +00:00
|
|
|
|
2011-09-09 11:58:11 +00:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
2011-11-25 11:03:14 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2011-11-25 18:37:02 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
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;
|
2011-11-28 10:01:04 +00:00
|
|
|
import android.view.ViewGroup;
|
2011-12-19 11:08:40 +00:00
|
|
|
import android.webkit.WebSettings;
|
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-12-09 20:49:55 +00:00
|
|
|
public class ArticleFragment extends Fragment {
|
2011-11-27 13:20:27 +00:00
|
|
|
@SuppressWarnings("unused")
|
2011-09-09 16:36:09 +00:00
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
2011-11-25 11:03:14 +00:00
|
|
|
private SharedPreferences m_prefs;
|
2011-11-23 16:38:21 +00:00
|
|
|
private Article m_article;
|
2011-12-06 12:52:33 +00:00
|
|
|
private OnlineServices m_onlineServices;
|
2011-12-09 20:49:55 +00:00
|
|
|
//private Article m_nextArticle;
|
|
|
|
//private Article m_prevArticle;
|
|
|
|
|
|
|
|
public ArticleFragment() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ArticleFragment(Article article) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
m_article = article;
|
|
|
|
}
|
|
|
|
|
2011-11-28 10:01:04 +00:00
|
|
|
private View.OnTouchListener m_gestureListener;
|
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-11-28 10:01:04 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
Activity activity = (Activity)getActivity();
|
2011-11-28 09:45:19 +00:00
|
|
|
|
|
|
|
if (activity != null) {
|
|
|
|
int orientation = activity.getWindowManager().getDefaultDisplay().getOrientation();
|
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
if (!m_onlineServices.isSmallScreen()) {
|
2011-11-28 09:45:19 +00:00
|
|
|
if (orientation % 2 == 0) {
|
|
|
|
view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
view.findViewById(R.id.splitter_vertical).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
view.findViewById(R.id.splitter_vertical).setVisibility(View.GONE);
|
|
|
|
view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
view.findViewById(R.id.splitter_horizontal).setVisibility(View.GONE);
|
|
|
|
}
|
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-30 09:02:26 +00:00
|
|
|
|
|
|
|
String titleStr;
|
|
|
|
|
|
|
|
if (m_article.title.length() > 200)
|
|
|
|
titleStr = m_article.title.substring(0, 200) + "...";
|
|
|
|
else
|
|
|
|
titleStr = m_article.title;
|
|
|
|
|
2011-11-24 14:57:44 +00:00
|
|
|
title.setMovementMethod(LinkMovementMethod.getInstance());
|
2011-11-30 09:02:26 +00:00
|
|
|
title.setText(Html.fromHtml("<a href=\""+m_article.link.replace("\"", "\\\"")+"\">" + titleStr + "</a>"));
|
2011-11-23 16:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WebView web = (WebView)view.findViewById(R.id.content);
|
|
|
|
|
|
|
|
if (web != null) {
|
|
|
|
|
2011-11-25 09:10:56 +00:00
|
|
|
String content;
|
2011-11-29 04:03:38 +00:00
|
|
|
String cssOverride = "";
|
|
|
|
|
2011-12-01 09:05:21 +00:00
|
|
|
|
2011-12-19 11:08:40 +00:00
|
|
|
WebSettings ws = web.getSettings();
|
|
|
|
ws.setSupportZoom(true);
|
|
|
|
ws.setBuiltInZoomControls(true);
|
2011-11-30 16:04:31 +00:00
|
|
|
|
2011-11-29 04:03:38 +00:00
|
|
|
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
2011-12-03 18:21:57 +00:00
|
|
|
cssOverride = "body { background : black; color : #e0e0e0}\n";
|
|
|
|
web.setBackgroundColor(android.R.color.black);
|
2011-11-30 16:04:31 +00:00
|
|
|
} else {
|
2011-12-03 18:21:57 +00:00
|
|
|
cssOverride = "";
|
2011-11-25 09:10:56 +00:00
|
|
|
}
|
2011-12-07 12:25:50 +00:00
|
|
|
|
2011-12-13 12:43:40 +00:00
|
|
|
String articleContent = m_article.content != null ? m_article.content : "";
|
2011-12-07 12:25:50 +00:00
|
|
|
|
|
|
|
Document doc = Jsoup.parse(articleContent);
|
|
|
|
|
|
|
|
if (doc != null) {
|
|
|
|
// thanks webview for crashing on <video> tag
|
|
|
|
Elements videos = doc.select("video");
|
|
|
|
|
|
|
|
for (Element video : videos)
|
|
|
|
video.remove();
|
|
|
|
|
|
|
|
articleContent = doc.toString();
|
|
|
|
}
|
2011-11-23 16:38:21 +00:00
|
|
|
|
2011-11-29 04:03:38 +00:00
|
|
|
content =
|
|
|
|
"<html>" +
|
|
|
|
"<head>" +
|
|
|
|
"<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\">" +
|
2011-12-03 18:21:57 +00:00
|
|
|
//"<meta name=\"viewport\" content=\"target-densitydpi=device-dpi\" />" +
|
2011-11-29 04:03:38 +00:00
|
|
|
"<style type=\"text/css\">" +
|
|
|
|
cssOverride +
|
2011-12-01 09:05:21 +00:00
|
|
|
"img { max-width : 98%; height : auto; }" +
|
2011-11-29 04:03:38 +00:00
|
|
|
"body { text-align : justify; }" +
|
|
|
|
"</style>" +
|
|
|
|
"</head>" +
|
2011-12-07 12:25:50 +00:00
|
|
|
"<body>" + articleContent + "</body></html>";
|
2011-11-29 04:03:38 +00:00
|
|
|
|
2011-12-07 12:13:58 +00:00
|
|
|
try {
|
|
|
|
web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2011-11-28 10:01:04 +00:00
|
|
|
|
2011-12-06 12:52:33 +00:00
|
|
|
if (m_onlineServices.isSmallScreen())
|
2011-11-28 10:01:04 +00:00
|
|
|
web.setOnTouchListener(m_gestureListener);
|
2011-11-23 16:38:21 +00:00
|
|
|
}
|
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));
|
|
|
|
}
|
|
|
|
|
2011-11-28 09:45:19 +00:00
|
|
|
TextView tagv = (TextView)view.findViewById(R.id.tags);
|
|
|
|
|
|
|
|
if (tagv != null) {
|
|
|
|
if (m_article.tags != null) {
|
|
|
|
String tagsStr = "";
|
|
|
|
|
|
|
|
for (String tag : m_article.tags)
|
|
|
|
tagsStr += tag + ", ";
|
|
|
|
|
|
|
|
tagsStr = tagsStr.replaceAll(", $", "");
|
|
|
|
|
|
|
|
tagv.setText(tagsStr);
|
|
|
|
} else {
|
|
|
|
tagv.setVisibility(View.GONE);
|
|
|
|
}
|
2011-11-25 09:10:56 +00:00
|
|
|
}
|
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-12-07 12:25:50 +00:00
|
|
|
|
2011-11-25 10:32:32 +00:00
|
|
|
out.putParcelable("article", m_article);
|
2011-09-09 11:58:11 +00:00
|
|
|
}
|
2011-12-09 20:49:55 +00:00
|
|
|
|
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
|
|
|
|
2011-11-25 11:03:14 +00:00
|
|
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
2011-12-06 12:52:33 +00:00
|
|
|
m_onlineServices = (OnlineServices)activity;
|
2011-12-09 20:49:55 +00:00
|
|
|
//m_article = m_onlineServices.getSelectedArticle();
|
2011-09-09 11:58:11 +00:00
|
|
|
}
|
2011-11-28 10:01:04 +00:00
|
|
|
|
2011-09-09 11:58:11 +00:00
|
|
|
}
|