From 12de7c7973ccbb6f0e229c2f7d88e82bd2d88e5e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 24 Jun 2012 15:57:58 +0400 Subject: [PATCH] simplify back stack handling a bit disable feed fragments selected state in small screen mode --- src/org/fox/ttrss/FeedCategoriesFragment.java | 2 +- src/org/fox/ttrss/FeedsFragment.java | 2 +- src/org/fox/ttrss/MainActivity.java | 99 +++++++------------ .../fox/ttrss/offline/OfflineActivity.java | 12 +-- .../OfflineFeedCategoriesFragment.java | 2 +- .../ttrss/offline/OfflineFeedsFragment.java | 2 +- 6 files changed, 47 insertions(+), 72 deletions(-) diff --git a/src/org/fox/ttrss/FeedCategoriesFragment.java b/src/org/fox/ttrss/FeedCategoriesFragment.java index 6137a6a1..ac75bdba 100644 --- a/src/org/fox/ttrss/FeedCategoriesFragment.java +++ b/src/org/fox/ttrss/FeedCategoriesFragment.java @@ -280,7 +280,7 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe public int getItemViewType(int position) { FeedCategory cat = items.get(position); - if (m_selectedCat != null && cat.id == m_selectedCat.id) { + if (!m_onlineServices.isSmallScreen() && m_selectedCat != null && cat.id == m_selectedCat.id) { return VIEW_SELECTED; } else { return VIEW_NORMAL; diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index 480d2ccb..18c2fb8c 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -375,7 +375,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh public int getItemViewType(int position) { Feed feed = items.get(position); - if (m_selectedFeed != null && feed.id == m_selectedFeed.id) { + if (!m_onlineServices.isSmallScreen() && m_selectedFeed != null && feed.id == m_selectedFeed.id) { return VIEW_SELECTED; } else { return VIEW_NORMAL; diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 04a5a725..1a966507 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -561,29 +561,25 @@ public class MainActivity extends FragmentActivity implements OnlineServices { private synchronized void refresh() { Date date = new Date(); - boolean canRefresh = date.getTime() - m_lastRefresh > 5000; - - if (m_sessionId != null) { + if (m_sessionId != null && date.getTime() - m_lastRefresh > 5000) { FeedsFragment ff = (FeedsFragment) getSupportFragmentManager() .findFragmentByTag(FRAG_FEEDS); if (ff != null) { - Log.d(TAG, "Refreshing feeds..."); - if (canRefresh) ff.refresh(true); - ff.setSelectedFeed(m_activeFeed); + Log.d(TAG, "Refreshing feeds/" + m_activeFeed); + ff.refresh(true); } FeedCategoriesFragment cf = (FeedCategoriesFragment) getSupportFragmentManager() .findFragmentByTag(FRAG_CATS); if (cf != null) { - Log.d(TAG, "Refreshing categories..."); - if (canRefresh) cf.refresh(true); - cf.setSelectedCategory(m_activeCategory); + Log.d(TAG, "Refreshing categories/" + m_activeCategory); + cf.refresh(true); } - if (canRefresh) m_lastRefresh = date.getTime(); + m_lastRefresh = date.getTime(); } } @@ -1011,7 +1007,30 @@ public class MainActivity extends FragmentActivity implements OnlineServices { if (m_selectedArticle != null) { closeArticle(); } else if (m_activeFeed != null) { - closeFeed(); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + if (m_activeFeed.is_cat) { + + Fragment headlines = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); + FeedCategoriesFragment cats = (FeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS); + + ft.show(cats); + ft.remove(headlines); + + } else { + Fragment headlines = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); + FeedsFragment feeds = (FeedsFragment) getSupportFragmentManager().findFragmentByTag(FRAG_FEEDS); + + ft.show(feeds); + ft.remove(headlines); + } + ft.commit(); + + m_activeFeed = null; + + refresh(); + + initMainMenu(); + } else if (m_activeCategory != null) { closeCategory(); } else if (allowQuit) { @@ -1021,16 +1040,8 @@ public class MainActivity extends FragmentActivity implements OnlineServices { if (m_selectedArticle != null) { closeArticle(); refresh(); - } else if (m_activeFeed != null) { - m_activeFeed = null; - - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - ft.replace(R.id.headlines_fragment, new DummyFragment(), ""); - ft.commit(); - - refresh(); - - initMainMenu(); + /* } else if (m_activeFeed != null) { + closeFeed(); */ } else if (m_activeCategory != null) { closeCategory(); } else if (allowQuit) { @@ -1577,11 +1588,11 @@ public class MainActivity extends FragmentActivity implements OnlineServices { getActionBar().setTitle(R.string.app_name); } - //if (m_smallScreenMode) { + if (m_smallScreenMode) { getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null || m_activeFeed != null); - //} else { - // getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null || m_activeFeed != null); - //} + } else { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null); + } if (android.os.Build.VERSION.SDK_INT >= 14) { ShareActionProvider shareProvider = (ShareActionProvider) m_menu.findItem(R.id.share_article).getActionProvider(); @@ -2308,45 +2319,9 @@ public class MainActivity extends FragmentActivity implements OnlineServices { toast.show(); } - private void closeFeed() { + private void _closeFeed() { if (m_activeFeed != null) { - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - - if (m_smallScreenMode) { - if (m_activeFeed.is_cat) { - - Fragment headlines = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); - FeedCategoriesFragment cats = (FeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS); - - ft.show(cats); - ft.remove(headlines); - - //cats.setSelectedCategory(null); - - //ft.replace(R.id.fragment_container, new FeedCategoriesFragment(), FRAG_CATS); - } else { - Fragment headlines = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); - FeedsFragment feeds = (FeedsFragment) getSupportFragmentManager().findFragmentByTag(FRAG_FEEDS); - - ft.show(feeds); - ft.remove(headlines); - - //feeds.setSelectedFeed(null); - - } - } else { - Fragment headlines = getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); - ft.remove(headlines); - } - ft.commit(); } - - m_activeFeed = null; - - refresh(); - - initMainMenu(); - } @Override diff --git a/src/org/fox/ttrss/offline/OfflineActivity.java b/src/org/fox/ttrss/offline/OfflineActivity.java index 9240bd44..ad243f16 100644 --- a/src/org/fox/ttrss/offline/OfflineActivity.java +++ b/src/org/fox/ttrss/offline/OfflineActivity.java @@ -502,7 +502,7 @@ public class OfflineActivity extends FragmentActivity implements } else { if (m_selectedArticleId != 0) { closeArticle(); - } else if (m_activeFeedId != 0) { + /* } else if (m_activeFeedId != 0) { m_activeFeedId = 0; OfflineFeedsFragment ff = (OfflineFeedsFragment) getSupportFragmentManager() @@ -524,7 +524,7 @@ public class OfflineActivity extends FragmentActivity implements } refreshViews(); - initMainMenu(); + initMainMenu(); */ } else if (m_activeCatId != -1) { closeCategory(); } else if (allowQuit) { @@ -1033,11 +1033,11 @@ public class OfflineActivity extends FragmentActivity implements getActionBar().setTitle(R.string.app_name); } - //if (!m_smallScreenMode) { - // getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0); - //} else { + if (m_smallScreenMode) { getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0 || m_activeCatId != -1); - //} + } else { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeCatId != -1); + } if (android.os.Build.VERSION.SDK_INT >= 14) { ShareActionProvider shareProvider = (ShareActionProvider) m_menu.findItem(R.id.share_article).getActionProvider(); diff --git a/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java b/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java index 6fc1adf1..f6ae2835 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java @@ -175,7 +175,7 @@ public class OfflineFeedCategoriesFragment extends Fragment implements OnItemCli public int getItemViewType(int position) { Cursor cursor = (Cursor) this.getItem(position); - if (cursor.getLong(0) == m_selectedCatId) { + if (!m_offlineServices.isSmallScreen() && cursor.getLong(0) == m_selectedCatId) { return VIEW_SELECTED; } else { return VIEW_NORMAL; diff --git a/src/org/fox/ttrss/offline/OfflineFeedsFragment.java b/src/org/fox/ttrss/offline/OfflineFeedsFragment.java index 762e1081..605f506c 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedsFragment.java +++ b/src/org/fox/ttrss/offline/OfflineFeedsFragment.java @@ -199,7 +199,7 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene public int getItemViewType(int position) { Cursor cursor = (Cursor) this.getItem(position); - if (cursor.getLong(0) == m_selectedFeedId) { + if (!m_offlineServices.isSmallScreen() && cursor.getLong(0) == m_selectedFeedId) { return VIEW_SELECTED; } else { return VIEW_NORMAL;