2011-09-09 11:58:11 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
2011-09-10 08:16:59 +00:00
|
|
|
import java.sql.SQLData;
|
|
|
|
|
2011-09-09 11:58:11 +00:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Fragment;
|
|
|
|
import android.content.SharedPreferences;
|
2011-09-09 16:36:09 +00:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2011-09-09 11:58:11 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
2011-09-09 16:36:09 +00:00
|
|
|
import android.provider.BaseColumns;
|
|
|
|
import android.util.Log;
|
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
|
|
|
|
|
|
|
public class ArticleFragment extends Fragment {
|
2011-09-09 16:36:09 +00:00
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
|
|
|
protected SharedPreferences m_prefs;
|
|
|
|
protected int m_articleId;
|
2011-09-10 08:16:59 +00:00
|
|
|
protected SQLiteDatabase m_db;
|
2011-09-09 11:58:11 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
2011-09-09 16:36:09 +00:00
|
|
|
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
|
|
|
DatabaseHelper dh = new DatabaseHelper(getActivity());
|
2011-09-10 08:16:59 +00:00
|
|
|
m_db = dh.getReadableDatabase();
|
2011-09-09 16:36:09 +00:00
|
|
|
|
|
|
|
Log.d(TAG, "Opening article #" + m_articleId);
|
|
|
|
|
2011-09-10 08:16:59 +00:00
|
|
|
Cursor c = m_db.query("articles", null, BaseColumns._ID + "=?",
|
2011-09-09 16:36:09 +00:00
|
|
|
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();
|
|
|
|
|
2011-09-09 11:58:11 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2011-09-09 16:36:09 +00:00
|
|
|
public void initialize(int articleId) {
|
|
|
|
m_articleId = articleId;
|
|
|
|
}
|
|
|
|
|
2011-09-09 11:58:11 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
2011-09-10 08:16:59 +00:00
|
|
|
|
|
|
|
m_db.close();
|
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
|
|
|
|
|
|
|
out.putInt("articleId", m_articleId);
|
2011-09-09 11:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|