better handle moving back from nested feeds

This commit is contained in:
Andrew Dolgov 2013-05-18 14:27:04 +04:00
parent c59613fe05
commit 858e2c93c9
7 changed files with 92 additions and 10 deletions

View File

@ -457,8 +457,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
} }
} }
if (!m_activity.isSmallScreen()) //if (!m_activity.isSmallScreen())
m_selectedCat = cat; // m_selectedCat = cat;
m_adapter.notifyDataSetChanged(); m_adapter.notifyDataSetChanged();
} }

View File

@ -34,6 +34,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
protected long m_lastRefresh = 0; protected long m_lastRefresh = 0;
private boolean m_actionbarUpEnabled = false; private boolean m_actionbarUpEnabled = false;
private int m_actionbarRevertDepth = 0;
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
@ -118,6 +119,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
} }
} else { // savedInstanceState != null } else { // savedInstanceState != null
m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled"); m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled");
m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth");
if (!isSmallScreen()) { if (!isSmallScreen()) {
// temporary hack because FeedsActivity doesn't track whether active feed is open // 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) { public void onCatSelected(FeedCategory cat, boolean openAsFeed) {
FeedCategoriesFragment fc = (FeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS);
if (!openAsFeed) { if (!openAsFeed) {
if (isSmallScreen()) { if (isSmallScreen()) {
@ -246,6 +249,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} else { } else {
if (fc != null) {
fc.setSelectedCategory(null);
}
FragmentTransaction ft = getSupportFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
@ -255,8 +262,17 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
ft.addToBackStack(null); ft.addToBackStack(null);
ft.commit(); ft.commit();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
m_actionbarUpEnabled = true;
m_actionbarRevertDepth = m_actionbarRevertDepth + 1;
} }
} else { } else {
if (fc != null) {
fc.setSelectedCategory(cat);
}
Feed feed = new Feed(cat.id, cat.title, true); Feed feed = new Feed(cat.id, cat.title, true);
onFeedSelected(feed); onFeedSelected(feed);
} }
@ -269,6 +285,18 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { 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: case R.id.show_feeds:
setUnreadOnly(!getUnreadOnly()); setUnreadOnly(!getUnreadOnly());
initMenu(); initMenu();
@ -297,6 +325,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
super.onSaveInstanceState(out); super.onSaveInstanceState(out);
out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled); out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled);
out.putInt("actionbarRevertDepth", m_actionbarRevertDepth);
GlobalState.getInstance().save(out); GlobalState.getInstance().save(out);
} }

View File

@ -621,9 +621,9 @@ public class OnlineActivity extends CommonActivity {
final ArticlePager ap = (ArticlePager)getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE); final ArticlePager ap = (ArticlePager)getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: /* case android.R.id.home:
finish(); finish();
return true; return true; */
case R.id.subscribe_to_feed: case R.id.subscribe_to_feed:
Intent subscribe = new Intent(OnlineActivity.this, SubscribeActivity.class); Intent subscribe = new Intent(OnlineActivity.this, SubscribeActivity.class);
startActivityForResult(subscribe, 0); startActivityForResult(subscribe, 0);

View File

@ -169,9 +169,9 @@ public class OfflineActivity extends CommonActivity {
.findFragmentByTag(FRAG_ARTICLE); .findFragmentByTag(FRAG_ARTICLE);
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: /* case android.R.id.home:
finish(); finish();
return true; return true; */
case R.id.go_online: case R.id.go_online:
switchOnline(); switchOnline();
return true; return true;

View File

@ -197,8 +197,8 @@ public class OfflineFeedCategoriesFragment extends Fragment implements OnItemCli
m_activity.onCatSelected(feedId); m_activity.onCatSelected(feedId);
} }
if (!m_activity.isSmallScreen()) /* if (!m_activity.isSmallScreen())
m_selectedCatId = feedId; m_selectedCatId = feedId; */
m_adapter.notifyDataSetChanged(); m_adapter.notifyDataSetChanged();
} }

View File

@ -24,6 +24,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
private boolean m_actionbarUpEnabled = false; private boolean m_actionbarUpEnabled = false;
private int m_actionbarRevertDepth = 0;
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Override @Override
@ -44,6 +45,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
if (savedInstanceState != null) { if (savedInstanceState != null) {
m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled"); m_actionbarUpEnabled = savedInstanceState.getBoolean("actionbarUpEnabled");
m_actionbarRevertDepth = savedInstanceState.getInt("actionbarRevertDepth");
if (m_actionbarUpEnabled) { if (m_actionbarUpEnabled) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -127,6 +129,18 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { 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: case R.id.show_feeds:
setUnreadOnly(!getUnreadOnly()); setUnreadOnly(!getUnreadOnly());
initMenu(); initMenu();
@ -143,6 +157,7 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
super.onSaveInstanceState(out); super.onSaveInstanceState(out);
out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled); out.putBoolean("actionbarUpEnabled", m_actionbarUpEnabled);
out.putInt("actionbarRevertDepth", m_actionbarRevertDepth);
GlobalState.getInstance().save(out); GlobalState.getInstance().save(out);
} }
@ -179,7 +194,13 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
} }
public void onCatSelected(int catId, boolean openAsFeed) { public void onCatSelected(int catId, boolean openAsFeed) {
OfflineFeedCategoriesFragment fc = (OfflineFeedCategoriesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_CATS);
if (openAsFeed) { if (openAsFeed) {
if (fc != null) {
fc.setSelectedFeedId(catId);
}
onFeedSelected(catId, true, true); onFeedSelected(catId, true, true);
} else { } else {
if (isSmallScreen()) { if (isSmallScreen()) {
@ -188,6 +209,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} else { } else {
if (fc != null) {
fc.setSelectedFeedId(-1);
}
FragmentTransaction ft = getSupportFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
@ -196,6 +221,10 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS); ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
ft.addToBackStack(null); ft.addToBackStack(null);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
m_actionbarUpEnabled = true;
m_actionbarRevertDepth = m_actionbarRevertDepth + 1;
ft.commit(); ft.commit();
} }
@ -303,7 +332,9 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
intent.putExtra("isCat", hf.getFeedIsCat()); intent.putExtra("isCat", hf.getFeedIsCat());
intent.putExtra("article", articleId); intent.putExtra("article", articleId);
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
overridePendingTransition(R.anim.right_slide_in, 0);
} }
} else { } else {
refresh(); refresh();

View File

@ -3,6 +3,8 @@ package org.fox.ttrss.offline;
import org.fox.ttrss.GlobalState; import org.fox.ttrss.GlobalState;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import com.actionbarsherlock.view.MenuItem;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -13,6 +15,7 @@ import android.preference.PreferenceManager;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View; import android.view.View;
public class OfflineHeadlinesActivity extends OfflineActivity implements OfflineHeadlinesEventListener { public class OfflineHeadlinesActivity extends OfflineActivity implements OfflineHeadlinesEventListener {
@ -90,6 +93,19 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
initMenu(); 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 @Override
public void onArticleSelected(int articleId, boolean open) { public void onArticleSelected(int articleId, boolean open) {
SQLiteStatement stmt = getWritableDb().compileStatement( SQLiteStatement stmt = getWritableDb().compileStatement(
@ -142,4 +158,10 @@ public class OfflineHeadlinesActivity extends OfflineActivity implements Offline
public void onArticleSelected(int articleId) { public void onArticleSelected(int articleId) {
onArticleSelected(articleId, true); onArticleSelected(articleId, true);
} }
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(0, R.anim.right_slide_out);
}
} }