update feedlist on unread count change, implement feeds_unread view
This commit is contained in:
parent
7dfef7375d
commit
38028b1e7e
@ -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 = 4;
|
||||
public static final int DATABASE_VERSION = 6;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
@ -20,6 +20,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL("DROP TABLE IF EXISTS feeds;");
|
||||
db.execSQL("DROP TABLE IF EXISTS articles;");
|
||||
db.execSQL("DROP VIEW IF EXISTS feeds_unread;");
|
||||
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS feeds (" +
|
||||
BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
@ -45,6 +46,11 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
"tags TEXT, " +
|
||||
"content TEXT" +
|
||||
");");
|
||||
|
||||
db.execSQL("CREATE VIEW feeds_unread AS SELECT feeds._id AS _id, " +
|
||||
"feeds.title AS title, " +
|
||||
"SUM(articles.unread) AS unread FROM feeds " +
|
||||
"LEFT JOIN articles ON (articles.feed_id = feeds._id) GROUP BY feeds._id, feeds.title;");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
||||
View view = inflater.inflate(R.layout.feeds_fragment, container, false);
|
||||
|
||||
DatabaseHelper helper = new DatabaseHelper(getActivity());
|
||||
m_cursor = helper.getReadableDatabase().query("feeds", null, null, null, null, null, "unread DESC");
|
||||
m_cursor = helper.getReadableDatabase().query("feeds_unread", null, null, null, null, null, "unread DESC");
|
||||
|
||||
m_adapter = new FeedsListAdapter(getActivity(), R.layout.feeds_row, m_cursor,
|
||||
new String[] { "title", "unread" }, new int[] { R.id.title, R.id.unread_counter }, 0);
|
||||
@ -197,7 +197,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
|
||||
out.putLong("lastUpdate", m_lastUpdate);
|
||||
}
|
||||
|
||||
private class FeedsListAdapter extends SimpleCursorAdapter {
|
||||
class FeedsListAdapter extends SimpleCursorAdapter {
|
||||
|
||||
private Context context;
|
||||
private int layout;
|
||||
|
@ -100,7 +100,7 @@ public class MainActivity extends Activity {
|
||||
FeedsFragment frag = new FeedsFragment();
|
||||
|
||||
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
|
||||
ft.replace(R.id.feeds_container, frag);
|
||||
ft.replace(R.id.feeds_container, frag, "FEEDLIST");
|
||||
ft.commit();
|
||||
|
||||
m_feedsOpened = true;
|
||||
@ -210,8 +210,8 @@ public class MainActivity extends Activity {
|
||||
stmtInsert.bindString(7, article.title);
|
||||
stmtInsert.bindString(8, article.link);
|
||||
stmtInsert.bindLong(9, article.feed_id);
|
||||
stmtInsert.bindString(9, ""); // comma-separated tags
|
||||
stmtInsert.bindString(10, article.content);
|
||||
stmtInsert.bindString(10, ""); // comma-separated tags
|
||||
stmtInsert.bindString(11, article.content);
|
||||
stmtInsert.execute();
|
||||
|
||||
}
|
||||
@ -221,6 +221,13 @@ public class MainActivity extends Activity {
|
||||
|
||||
db.close();
|
||||
|
||||
FeedsFragment ff = (FeedsFragment) getFragmentManager().findFragmentByTag("FEEDLIST");
|
||||
|
||||
if (ff != null) {
|
||||
ff.m_cursor.requery();
|
||||
ff.m_adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
Log.d(TAG, articlesFound + " articles processed");
|
||||
|
||||
if (articlesFound == m_limit && m_offset <= 300) {
|
||||
|
Loading…
Reference in New Issue
Block a user