From 210339648917ee53236a5fc586f591fed8fb176e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 17 Sep 2012 19:08:21 +0400 Subject: [PATCH] various offline fixes --- .../fox/ttrss/offline/OfflineActivity.java | 96 +++++++++++++------ .../ttrss/offline/OfflineArticlePager.java | 8 ++ .../offline/OfflineHeadlinesFragment.java | 25 ++++- 3 files changed, 101 insertions(+), 28 deletions(-) diff --git a/src/org/fox/ttrss/offline/OfflineActivity.java b/src/org/fox/ttrss/offline/OfflineActivity.java index 78aca34b..b7b151b9 100644 --- a/src/org/fox/ttrss/offline/OfflineActivity.java +++ b/src/org/fox/ttrss/offline/OfflineActivity.java @@ -47,6 +47,7 @@ public class OfflineActivity extends CommonActivity { public void onDestroyActionMode(ActionMode mode) { deselectAllArticles(); m_headlinesActionMode = null; + initMenu(); } @Override @@ -114,6 +115,47 @@ public class OfflineActivity extends CommonActivity { out.putBoolean("unreadOnly", m_unreadOnly); } + protected void selectArticles(int feedId, boolean isCat, int mode) { + switch (mode) { + case 0: + SQLiteStatement stmtSelectAll = null; + + if (isCat) { + stmtSelectAll = getWritableDb().compileStatement( + "UPDATE articles SET selected = 1 WHERE feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)"); + } else { + stmtSelectAll = getWritableDb().compileStatement( + "UPDATE articles SET selected = 1 WHERE feed_id = ?"); + } + + stmtSelectAll.bindLong(1, feedId); + stmtSelectAll.execute(); + stmtSelectAll.close(); + + break; + case 1: + + SQLiteStatement stmtSelectUnread = null; + + if (isCat) { + stmtSelectUnread = getWritableDb().compileStatement( + "UPDATE articles SET selected = 1 WHERE feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?) AND unread = 1"); + } else { + stmtSelectUnread = getWritableDb().compileStatement( + "UPDATE articles SET selected = 1 WHERE feed_id = ? AND unread = 1"); + } + + stmtSelectUnread.bindLong(1, feedId); + stmtSelectUnread.execute(); + stmtSelectUnread.close(); + + break; + case 2: + deselectAllArticles(); + break; + } + } + @Override public boolean onOptionsItemSelected(MenuItem item) { final OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() @@ -188,29 +230,8 @@ public class OfflineActivity extends CommonActivity { @Override public void onClick(DialogInterface dialog, int which) { - switch (which) { - case 0: - SQLiteStatement stmtSelectAll = getWritableDb() - .compileStatement( - "UPDATE articles SET selected = 1 WHERE feed_id = ?"); - stmtSelectAll.bindLong(1, ohf.getFeedId()); - stmtSelectAll.execute(); - stmtSelectAll.close(); - break; - case 1: - SQLiteStatement stmtSelectUnread = getWritableDb() - .compileStatement( - "UPDATE articles SET selected = 1 WHERE feed_id = ? AND unread = 1"); - stmtSelectUnread - .bindLong(1, ohf.getFeedId()); - stmtSelectUnread.execute(); - stmtSelectUnread.close(); - break; - case 2: - deselectAllArticles(); - break; - } + selectArticles(ohf.getFeedId(), ohf.getFeedIsCat(), which); initMenu(); refresh(); @@ -225,9 +246,17 @@ public class OfflineActivity extends CommonActivity { case R.id.headlines_mark_as_read: if (ohf != null) { int feedId = ohf.getFeedId(); + boolean isCat = ohf.getFeedIsCat(); - SQLiteStatement stmt = getWritableDb().compileStatement( + SQLiteStatement stmt = null; + + if (isCat) { + stmt = getWritableDb().compileStatement( + "UPDATE articles SET unread = 0 WHERE feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)"); + } else { + stmt = getWritableDb().compileStatement( "UPDATE articles SET unread = 0 WHERE feed_id = ?"); + } stmt.bindLong(1, feedId); stmt.execute(); stmt.close(); @@ -309,12 +338,25 @@ public class OfflineActivity extends CommonActivity { case R.id.catchup_above: if (oap != null) { int articleId = oap.getSelectedArticleId(); + int feedId = oap.getFeedId(); + boolean isCat = oap.getFeedIsCat(); + + SQLiteStatement stmt = null; + + if (isCat) { + stmt = getWritableDb().compileStatement( + "UPDATE articles SET unread = 0 WHERE " + + "updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " + + "AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)"); + } else { + stmt = getWritableDb().compileStatement( + "UPDATE articles SET unread = 0 WHERE " + + "updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " + + "AND feed_id = ?"); + } - SQLiteStatement stmt = getWritableDb().compileStatement( - "UPDATE articles SET unread = 0 WHERE updated >= " - + "(SELECT updated FROM articles WHERE " - + BaseColumns._ID + " = ?)"); stmt.bindLong(1, articleId); + stmt.bindLong(2, feedId); stmt.execute(); stmt.close(); diff --git a/src/org/fox/ttrss/offline/OfflineArticlePager.java b/src/org/fox/ttrss/offline/OfflineArticlePager.java index b1e04993..254e1edc 100644 --- a/src/org/fox/ttrss/offline/OfflineArticlePager.java +++ b/src/org/fox/ttrss/offline/OfflineArticlePager.java @@ -28,6 +28,14 @@ public class OfflineArticlePager extends Fragment { private String m_searchQuery = ""; private Cursor m_cursor; + public int getFeedId() { + return m_feedId; + } + + public boolean getFeedIsCat() { + return m_isCat; + } + public Cursor createCursor() { String feedClause = null; diff --git a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java index 4c0ffca8..fd3fad37 100644 --- a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java @@ -177,7 +177,30 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis m_activity.shareArticle(articleId); } return true; - case R.id.catchup_above: + case R.id.catchup_above: + if (true) { + int articleId = getArticleIdAtPosition(info.position); + + SQLiteStatement stmt = null; + + if (m_feedIsCat) { + stmt = m_activity.getWritableDb().compileStatement( + "UPDATE articles SET unread = 0 WHERE " + + "updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " + + "AND feed_id IN (SELECT "+BaseColumns._ID+" FROM feeds WHERE cat_id = ?)"); + } else { + stmt = m_activity.getWritableDb().compileStatement( + "UPDATE articles SET unread = 0 WHERE " + + "updated >= (SELECT updated FROM articles WHERE " + BaseColumns._ID + " = ?) " + + "AND feed_id = ?"); + } + + stmt.bindLong(1, articleId); + stmt.bindLong(2, m_feedId); + stmt.execute(); + stmt.close(); + } + refresh(); return true; default: Log.d(TAG, "onContextItemSelected, unhandled id=" + item.getItemId());