From 3fd63d640aaa8248b69d035793681677ebc9a09c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 17 Sep 2012 16:57:02 +0400 Subject: [PATCH] more offline functionality stuff --- res/menu/offline_menu.xml | 8 +- .../fox/ttrss/offline/OfflineActivity.java | 256 +++++++++++++++++- .../ttrss/offline/OfflineArticlePager.java | 21 ++ .../ttrss/offline/OfflineFeedsActivity.java | 23 -- .../offline/OfflineHeadlinesFragment.java | 2 + 5 files changed, 281 insertions(+), 29 deletions(-) diff --git a/res/menu/offline_menu.xml b/res/menu/offline_menu.xml index 26444ef8..ad756aac 100644 --- a/res/menu/offline_menu.xml +++ b/res/menu/offline_menu.xml @@ -43,11 +43,11 @@ android:icon="@drawable/ic_menu_database" android:showAsAction="ifRoom" android:title="@string/headlines_select"/> - + android:title="@string/close_feed"/> --> - + android:title="@string/close_article"/> --> 0) { + SQLiteStatement stmt = getWritableDb() + .compileStatement( + "UPDATE articles SET unread = NOT unread WHERE selected = 1"); + stmt.execute(); + stmt.close(); + + refresh(); + } + return true; + case R.id.selection_toggle_marked: + if (getSelectedArticleCount() > 0) { + SQLiteStatement stmt = getWritableDb() + .compileStatement( + "UPDATE articles SET marked = NOT marked WHERE selected = 1"); + stmt.execute(); + stmt.close(); + + refresh(); + } + return true; + case R.id.selection_toggle_published: + if (getSelectedArticleCount() > 0) { + SQLiteStatement stmt = getWritableDb() + .compileStatement( + "UPDATE articles SET published = NOT published WHERE selected = 1"); + stmt.execute(); + stmt.close(); + + refresh(); + } + return true; + case R.id.toggle_published: + if (oap != null) { + int articleId = oap.getSelectedArticleId(); + + SQLiteStatement stmt = getWritableDb().compileStatement( + "UPDATE articles SET published = NOT published WHERE " + + BaseColumns._ID + " = ?"); + stmt.bindLong(1, articleId); + stmt.execute(); + stmt.close(); + + refresh(); + } + return true; + case R.id.catchup_above: + if (oap != null) { + int articleId = oap.getSelectedArticleId(); + + SQLiteStatement stmt = getWritableDb().compileStatement( + "UPDATE articles SET unread = 0 WHERE updated >= " + + "(SELECT updated FROM articles WHERE " + + BaseColumns._ID + " = ?)"); + stmt.bindLong(1, articleId); + stmt.execute(); + stmt.close(); + + refresh(); + } + return true; + case R.id.set_unread: + if (oap != null) { + int articleId = oap.getSelectedArticleId(); + + SQLiteStatement stmt = getWritableDb().compileStatement( + "UPDATE articles SET unread = 1 WHERE " + + BaseColumns._ID + " = ?"); + stmt.bindLong(1, articleId); + stmt.execute(); + stmt.close(); + + refresh(); + } + return true; default: Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId()); return super.onOptionsItemSelected(item); @@ -189,4 +413,32 @@ public class OfflineActivity extends CommonActivity { return selected; } + protected void deselectAllArticles() { + getWritableDb().execSQL("UPDATE articles SET selected = 0 "); + refresh(); + } + + protected void refresh() { + OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager() + .findFragmentByTag(FRAG_FEEDS); + + if (ff != null) { + ff.refresh(); + } + + OfflineFeedCategoriesFragment cf = (OfflineFeedCategoriesFragment) getSupportFragmentManager() + .findFragmentByTag(FRAG_CATS); + + if (cf != null) { + cf.refresh(); + } + + OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() + .findFragmentByTag(FRAG_HEADLINES); + + if (ohf != null) { + ohf.refresh(); + } + } + } diff --git a/src/org/fox/ttrss/offline/OfflineArticlePager.java b/src/org/fox/ttrss/offline/OfflineArticlePager.java index c6c824f5..0516d897 100644 --- a/src/org/fox/ttrss/offline/OfflineArticlePager.java +++ b/src/org/fox/ttrss/offline/OfflineArticlePager.java @@ -95,6 +95,12 @@ public class OfflineArticlePager extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.article_pager, container, false); + if (savedInstanceState != null) { + m_articleId = savedInstanceState.getInt("articleId", 0); + m_feedId = savedInstanceState.getInt("feedId", 0); + m_isCat = savedInstanceState.getBoolean("isCat", false); + } + m_adapter = new PagerAdapter(getActivity().getSupportFragmentManager()); m_cursor.moveToFirst(); @@ -130,6 +136,8 @@ public class OfflineArticlePager extends Fragment { m_listener.onArticleSelected(articleId, false); + m_articleId = articleId; + } } }); @@ -147,4 +155,17 @@ public class OfflineArticlePager extends Fragment { } + public int getSelectedArticleId() { + return m_articleId; + } + + @Override + public void onSaveInstanceState(Bundle out) { + super.onSaveInstanceState(out); + + out.putInt("articleId", m_articleId); + out.putInt("feedId", m_feedId); + out.putBoolean("isCat", m_isCat); + + } } diff --git a/src/org/fox/ttrss/offline/OfflineFeedsActivity.java b/src/org/fox/ttrss/offline/OfflineFeedsActivity.java index e44dcc82..61c13710 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedsActivity.java +++ b/src/org/fox/ttrss/offline/OfflineFeedsActivity.java @@ -81,29 +81,6 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead initMenu(); } - protected void refresh() { - OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager() - .findFragmentByTag(FRAG_FEEDS); - - if (ff != null) { - ff.refresh(); - } - - OfflineFeedCategoriesFragment cf = (OfflineFeedCategoriesFragment) getSupportFragmentManager() - .findFragmentByTag(FRAG_CATS); - - if (cf != null) { - cf.refresh(); - } - - /* OfflineHeadlinesFragment ohf = (OfflineHeadlinesFragment) getSupportFragmentManager() - .findFragmentByTag(FRAG_HEADLINES); - - if (ohf != null) { - ohf.refresh(); - } */ - } - @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { diff --git a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java index 6445d94d..6621105b 100644 --- a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java @@ -188,6 +188,8 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis m_combinedMode = savedInstanceState.getBoolean("combinedMode"); m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery"); m_feedIsCat = savedInstanceState.getBoolean("feedIsCat"); + } else { + m_listener.getWritableDb().execSQL("UPDATE articles SET selected = 0 "); } View view = inflater.inflate(R.layout.headlines_fragment, container, false);