diff --git a/res/layout/headlines_fragment.xml b/res/layout/headlines_fragment.xml index 05281162..abe5076c 100644 --- a/res/layout/headlines_fragment.xml +++ b/res/layout/headlines_fragment.xml @@ -7,7 +7,9 @@ - + + diff --git a/res/layout/headlines_row.xml b/res/layout/headlines_row.xml new file mode 100644 index 00000000..668fcd24 --- /dev/null +++ b/res/layout/headlines_row.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 8dc43dcb..0d14aa5d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -27,4 +27,5 @@ Offline Online Synchronizing... + No articles found. 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();