tt-rss-android/src/org/fox/ttrss/ArticleFragment.java

83 lines
2.1 KiB
Java
Raw Normal View History

2011-09-09 11:58:11 +00:00
package org.fox.ttrss;
import java.net.URLEncoder;
2011-09-09 11:58:11 +00:00
import android.app.Activity;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.os.Bundle;
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
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
//private int m_articleId;
2011-11-23 12:51:15 +00:00
private String m_sessionId;
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-23 12:51:15 +00:00
m_sessionId = savedInstanceState.getString("sessionId");
//m_articleId = savedInstanceState.getInt("articleId");
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
if (m_article != null) {
TextView title = (TextView)view.findViewById(R.id.title);
if (title != null) {
title.setText(m_article.title);
}
WebView web = (WebView)view.findViewById(R.id.content);
if (web != null) {
// this is ridiculous
2011-11-24 05:59:11 +00:00
String content = URLEncoder.encode("<html>" +
"<head><style type=\"text/css\">img { max-width : 90%; }</style></head>" +
"<body>" + m_article.content + "</body></html>").replace('+', ' ');
web.loadData(content, "text/html", "utf-8");
}
}
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-23 12:51:15 +00:00
out.putString("sessionId", m_sessionId);
//out.putInt("articleId", m_articleId);
2011-09-09 11:58:11 +00:00
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
m_sessionId = ((MainActivity)activity).getSessionId();
m_article = ((MainActivity)activity).getSelectedArticle();
//m_prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
2011-09-09 11:58:11 +00:00
}
}