From 858e2c93c9b587d31eff69a8441c008f08947a21 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 18 May 2013 14:27:04 +0400 Subject: [PATCH] better handle moving back from nested feeds --- src/org/fox/ttrss/FeedCategoriesFragment.java | 4 +-- src/org/fox/ttrss/FeedsActivity.java | 31 ++++++++++++++++- src/org/fox/ttrss/OnlineActivity.java | 4 +-- .../fox/ttrss/offline/OfflineActivity.java | 4 +-- .../OfflineFeedCategoriesFragment.java | 4 +-- .../ttrss/offline/OfflineFeedsActivity.java | 33 ++++++++++++++++++- .../offline/OfflineHeadlinesActivity.java | 22 +++++++++++++ 7 files changed, 92 insertions(+), 10 deletions(-) diff --git a/src/org/fox/ttrss/FeedCategoriesFragment.java b/src/org/fox/ttrss/FeedCategoriesFragment.java index fdd44f9e..144ea7c8 100644 --- a/src/org/fox/ttrss/FeedCategoriesFragment.java +++ b/src/org/fox/ttrss/FeedCategoriesFragment.java @@ -457,8 +457,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe } } - if (!m_activity.isSmallScreen()) - m_selectedCat = cat; + //if (!m_activity.isSmallScreen()) + // m_selectedCat = cat; m_adapter.notifyDataSetChanged(); } diff --git a/src/org/fox/ttrss/FeedsActivity.java b/src/org/fox/ttrss/FeedsActivity.java index 3682ba08..914d5461 100644 --- a/src/org/fox/ttrss/FeedsActivity.java +++ b/src/org/fox/ttrss/FeedsActivity.java @@ -34,6 +34,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe protected long m_lastRefresh = 0; private boolean m_actionbarUpEnabled = false; + private int m_actionbarRevertDepth = 0; @SuppressLint("NewApi") @Override @@ -118,6 +119,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe } } else { // savedInstanceState != null m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled"); + m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth"); if (!isSmallScreen()) { // temporary hack because FeedsActivity doesn't track whether active feed is open @@ -235,7 +237,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe } public void onCatSelected(FeedCategory cat, boolean openAsFeed) { - + FeedCategoriesFragment fc = (FeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS); + if (!openAsFeed) { if (isSmallScreen()) { @@ -246,6 +249,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe startActivityForResult(intent, 0); } else { + if (fc != null) { + fc.setSelectedCategory(null); + } + FragmentTransaction ft = getSupportFragmentManager() .beginTransaction(); @@ -255,8 +262,17 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe ft.addToBackStack(null); ft.commit(); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + m_actionbarUpEnabled = true; + m_actionbarRevertDepth = m_actionbarRevertDepth + 1; } } else { + + if (fc != null) { + fc.setSelectedCategory(cat); + } + Feed feed = new Feed(cat.id, cat.title, true); onFeedSelected(feed); } @@ -269,6 +285,18 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case android.R.id.home: + if (m_actionbarRevertDepth > 0) { + + m_actionbarRevertDepth = m_actionbarRevertDepth - 1; + m_actionbarUpEnabled = m_actionbarRevertDepth > 0; + getSupportActionBar().setDisplayHomeAsUpEnabled(m_actionbarUpEnabled); + + onBackPressed(); + } else { + finish(); + } + return true; case R.id.show_feeds: setUnreadOnly(!getUnreadOnly()); initMenu(); @@ -297,6 +325,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe super.onSaveInstanceState(out); out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled); + out.putInt("actionbarRevertDepth", m_actionbarRevertDepth); GlobalState.getInstance().save(out); } diff --git a/src/org/fox/ttrss/OnlineActivity.java b/src/org/fox/ttrss/OnlineActivity.java index 1606c728..c3696d02 100644 --- a/src/org/fox/ttrss/OnlineActivity.java +++ b/src/org/fox/ttrss/OnlineActivity.java @@ -621,9 +621,9 @@ public class OnlineActivity extends CommonActivity { final ArticlePager ap = (ArticlePager)getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE); switch (item.getItemId()) { - case android.R.id.home: + /* case android.R.id.home: finish(); - return true; + return true; */ case R.id.subscribe_to_feed: Intent subscribe = new Intent(OnlineActivity.this, SubscribeActivity.class); startActivityForResult(subscribe, 0); diff --git a/src/org/fox/ttrss/offline/OfflineActivity.java b/src/org/fox/ttrss/offline/OfflineActivity.java index 319b76c8..de437fcf 100644 --- a/src/org/fox/ttrss/offline/OfflineActivity.java +++ b/src/org/fox/ttrss/offline/OfflineActivity.java @@ -169,9 +169,9 @@ public class OfflineActivity extends CommonActivity { .findFragmentByTag(FRAG_ARTICLE); switch (item.getItemId()) { - case android.R.id.home: + /* case android.R.id.home: finish(); - return true; + return true; */ case R.id.go_online: switchOnline(); return true; diff --git a/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java b/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java index 31cfcb03..426cda0d 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineFeedCategoriesFragment.java @@ -197,8 +197,8 @@ public class OfflineFeedCategoriesFragment extends Fragment implements OnItemCli m_activity.onCatSelected(feedId); } - if (!m_activity.isSmallScreen()) - m_selectedCatId = feedId; + /* if (!m_activity.isSmallScreen()) + m_selectedCatId = feedId; */ m_adapter.notifyDataSetChanged(); } diff --git a/src/org/fox/ttrss/offline/OfflineFeedsActivity.java b/src/org/fox/ttrss/offline/OfflineFeedsActivity.java index 30a08213..fc0f521f 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedsActivity.java +++ b/src/org/fox/ttrss/offline/OfflineFeedsActivity.java @@ -24,6 +24,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead private final String TAG = this.getClass().getSimpleName(); private boolean m_actionbarUpEnabled = false; + private int m_actionbarRevertDepth = 0; @SuppressLint("NewApi") @Override @@ -44,6 +45,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead if (savedInstanceState != null) { m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled"); + m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth"); if (m_actionbarUpEnabled) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -127,6 +129,18 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case android.R.id.home: + if (m_actionbarRevertDepth > 0) { + + m_actionbarRevertDepth = m_actionbarRevertDepth - 1; + m_actionbarUpEnabled = m_actionbarRevertDepth > 0; + getSupportActionBar().setDisplayHomeAsUpEnabled(m_actionbarUpEnabled); + + onBackPressed(); + } else { + finish(); + } + return true; case R.id.show_feeds: setUnreadOnly(!getUnreadOnly()); initMenu(); @@ -143,6 +157,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead super.onSaveInstanceState(out); out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled); + out.putInt("actionbarRevertDepth", m_actionbarRevertDepth); GlobalState.getInstance().save(out); } @@ -179,7 +194,13 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead } public void onCatSelected(int catId, boolean openAsFeed) { + OfflineFeedCategoriesFragment fc = (OfflineFeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS); + if (openAsFeed) { + if (fc != null) { + fc.setSelectedFeedId(catId); + } + onFeedSelected(catId, true, true); } else { if (isSmallScreen()) { @@ -188,6 +209,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead startActivityForResult(intent, 0); } else { + if (fc != null) { + fc.setSelectedFeedId(-1); + } + FragmentTransaction ft = getSupportFragmentManager() .beginTransaction(); @@ -196,6 +221,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS); ft.addToBackStack(null); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + m_actionbarUpEnabled = true; + m_actionbarRevertDepth = m_actionbarRevertDepth + 1; ft.commit(); } @@ -303,7 +332,9 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead intent.putExtra("isCat", hf.getFeedIsCat()); intent.putExtra("article", articleId); - startActivityForResult(intent, 0); + startActivityForResult(intent, 0); + + overridePendingTransition(R.anim.right_slide_in, 0); } } else { refresh(); diff --git a/src/org/fox/ttrss/offline/OfflineHeadlinesActivity.java b/src/org/fox/ttrss/offline/OfflineHeadlinesActivity.java index 3ae56bdb..cfd1e19e 100644 --- a/src/org/fox/ttrss/offline/OfflineHeadlinesActivity.java +++ b/src/org/fox/ttrss/offline/OfflineHeadlinesActivity.java @@ -3,6 +3,8 @@ package org.fox.ttrss.offline; import org.fox.ttrss.GlobalState; import org.fox.ttrss.R; +import com.actionbarsherlock.view.MenuItem; + import android.annotation.SuppressLint; import android.content.Intent; import android.content.SharedPreferences; @@ -13,6 +15,7 @@ import android.preference.PreferenceManager; import android.provider.BaseColumns; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.util.Log; import android.view.View; public class OfflineHeadlinesActivity extends OfflineActivity implements OfflineHeadlinesEventListener { @@ -90,6 +93,19 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline initMenu(); } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + overridePendingTransition(0, R.anim.right_slide_out); + return true; + default: + Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId()); + return super.onOptionsItemSelected(item); + } + } + @Override public void onArticleSelected(int articleId, boolean open) { SQLiteStatement stmt = getWritableDb().compileStatement( @@ -142,4 +158,10 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline public void onArticleSelected(int articleId) { onArticleSelected(articleId, true); } + + @Override + public void onBackPressed() { + super.onBackPressed(); + overridePendingTransition(0, R.anim.right_slide_out); + } }