1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package org.fox.ttrss;
import android.app.Activity;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.TextView;
public class ArticleFragment extends Fragment {
private final String TAG = this.getClass().getSimpleName();
protected SharedPreferences m_prefs;
protected int m_articleId;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) {
m_articleId = savedInstanceState.getInt("articleId");
}
View view = inflater.inflate(R.layout.article_fragment, container, false);
DatabaseHelper dh = new DatabaseHelper(getActivity());
SQLiteDatabase db = dh.getReadableDatabase();
Log.d(TAG, "Opening article #" + m_articleId);
Cursor c = db.query("articles", null, BaseColumns._ID + "=?",
new String[] { String.valueOf(m_articleId) }, null, null, null);
c.moveToFirst();
Log.d(TAG, "Cursor count: " + c.getCount());
TextView title = (TextView)view.findViewById(R.id.title);
if (title != null) {
title.setText(c.getString(c.getColumnIndex("title")));
}
WebView content = (WebView)view.findViewById(R.id.content);
if (content != null) {
String contentData = "<html><body>" + c.getString(c.getColumnIndex("content")) + "</body></html>";
Log.d(TAG, "content=" + contentData);
content.loadData(contentData, "text/html", "utf-8");
}
c.close();
db.close();
return view;
}
public void initialize(int articleId) {
m_articleId = articleId;
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onSaveInstanceState (Bundle out) {
super.onSaveInstanceState(out);
out.putInt("articleId", m_articleId);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
}
}
|