summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-09-09 13:50:15 +0400
committerAndrew Dolgov <[email protected]>2011-09-09 13:50:15 +0400
commit23e390d2cfc4b49fe6b158e5cd5f15797977f9f9 (patch)
treeab4369e118783f5c8695fb9757d7d4d07bcb95fa /src
parent7393ab7631bfe138263ea8ffe2be4e012908d6c9 (diff)
implement basic headline loading
Diffstat (limited to 'src')
-rw-r--r--src/org/fox/ttrss/DatabaseHelper.java5
-rw-r--r--src/org/fox/ttrss/HeadlinesFragment.java35
-rw-r--r--src/org/fox/ttrss/MainActivity.java19
3 files changed, 50 insertions, 9 deletions
diff --git a/src/org/fox/ttrss/DatabaseHelper.java b/src/org/fox/ttrss/DatabaseHelper.java
index b06a76f8..7e7edbdb 100644
--- a/src/org/fox/ttrss/DatabaseHelper.java
+++ b/src/org/fox/ttrss/DatabaseHelper.java
@@ -10,7 +10,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
private final String TAG = this.getClass().getSimpleName();
public static final String DATABASE_NAME = "LocalStorage";
- public static final int DATABASE_VERSION = 6;
+ public static final int DATABASE_VERSION = 7;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
@@ -44,7 +44,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
"link TEXT, " +
"feed_id INTEGER, " +
"tags TEXT, " +
- "content TEXT" +
+ "content TEXT, " +
+ "excerpt TEXT" +
");");
db.execSQL("CREATE VIEW feeds_unread AS SELECT feeds."+BaseColumns._ID+" AS "+BaseColumns._ID+", " +
diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java
index 08a70e10..cc1b0aac 100644
--- a/src/org/fox/ttrss/HeadlinesFragment.java
+++ b/src/org/fox/ttrss/HeadlinesFragment.java
@@ -3,22 +3,47 @@ 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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.AbsListView;
+import android.widget.ListView;
+import android.widget.SimpleCursorAdapter;
public class HeadlinesFragment extends Fragment {
private final String TAG = this.getClass().getSimpleName();
protected int m_feedId;
protected SharedPreferences m_prefs;
-
+ protected SQLiteDatabase m_db;
+ protected Cursor m_cursor;
+ protected SimpleCursorAdapter m_adapter;
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.headlines_fragment, container, false);
+ DatabaseHelper helper = new DatabaseHelper(getActivity());
+
+ m_db = helper.getReadableDatabase();
+ m_cursor = m_db.query("articles", null, "feed_id = ?", new String[] { String.valueOf(m_feedId) }, null, null, "updated DESC");
+
+ m_adapter = new SimpleCursorAdapter(getActivity(), R.layout.headlines_row, m_cursor,
+ new String[] { "title", "excerpt" }, new int[] { R.id.title, R.id.excerpt }, 0);
+
+ ListView list = (ListView) view.findViewById(R.id.headlines);
+
+ if (list != null) {
+ list.setAdapter(m_adapter);
+ //list.setOnItemClickListener(this);
+ list.setEmptyView(view.findViewById(R.id.no_headlines));
+ //list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
+ }
+
return view;
}
@@ -29,6 +54,14 @@ public class HeadlinesFragment extends Fragment {
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
}
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ m_cursor.close();
+ m_db.close();
+ }
+
public void initialize(int feedId) {
m_feedId = feedId;
}
diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java
index 7f1c2d7b..c6ca7b09 100644
--- a/src/org/fox/ttrss/MainActivity.java
+++ b/src/org/fox/ttrss/MainActivity.java
@@ -238,12 +238,12 @@ public class MainActivity extends Activity {
/* db.execSQL("DELETE FROM articles"); */
SQLiteStatement stmtInsert = db.compileStatement("INSERT INTO articles " +
- "("+BaseColumns._ID+", unread, marked, published, updated, is_updated, title, link, feed_id, tags, content) " +
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
+ "("+BaseColumns._ID+", unread, marked, published, updated, is_updated, title, link, feed_id, tags, content, excerpt) " +
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
SQLiteStatement stmtUpdate = db.compileStatement("UPDATE articles SET " +
"unread = ?, marked = ?, published = ?, updated = ?, is_updated = ?, title = ?, link = ?, feed_id = ?, " +
- "tags = ?, content = ? WHERE " + BaseColumns._ID + " = ?");
+ "tags = ?, content = ?, excerpt = ? WHERE " + BaseColumns._ID + " = ?");
for (Article article : articles) {
//Log.d(TAG, "Processing article #" + article.id);
@@ -255,6 +255,12 @@ public class MainActivity extends Activity {
Cursor c = db.query("articles", new String[] { BaseColumns._ID } , BaseColumns._ID + "=?",
new String[] { String.valueOf(article.id) }, null, null, null);
+ String excerpt = article.content.replaceAll("\\<[^>]*>","");
+
+ if (excerpt.length() > 120) {
+ excerpt = excerpt.substring(120) + "...";
+ }
+
if (c.getCount() != 0) {
stmtUpdate.bindLong(1, article.unread ? 1 : 0);
stmtUpdate.bindLong(2, article.marked ? 1 : 0);
@@ -266,7 +272,8 @@ public class MainActivity extends Activity {
stmtUpdate.bindLong(8, article.feed_id);
stmtUpdate.bindString(9, ""); // comma-separated tags
stmtUpdate.bindString(10, article.content);
- stmtUpdate.bindLong(11, article.id);
+ stmtUpdate.bindString(11, excerpt);
+ stmtUpdate.bindLong(12, article.id);
stmtUpdate.execute();
} else {
@@ -283,8 +290,8 @@ public class MainActivity extends Activity {
stmtInsert.bindLong(9, article.feed_id);
stmtInsert.bindString(10, ""); // comma-separated tags
stmtInsert.bindString(11, article.content);
- stmtInsert.execute();
-
+ stmtInsert.bindString(12, excerpt);
+ stmtInsert.execute();
}
c.close();