From 3fd2afa44b414f859784a191cc4b0ddf3b91b9c9 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 18 Jan 2012 11:43:21 +0300 Subject: [PATCH] properly handle home button on actionbar in small screen mode --- src/org/fox/ttrss/MainActivity.java | 67 ++++++++++++++------------ src/org/fox/ttrss/OfflineActivity.java | 21 +++++--- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 51c40e67..c60e7e66 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -754,6 +754,35 @@ public class MainActivity extends FragmentActivity implements OnlineServices { @Override public void onBackPressed() { + goBack(true); + } + + private void closeCategory() { + + findViewById(R.id.feeds_fragment).setVisibility(View.GONE); + findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE); + + m_activeCategory = null; + + initMainMenu(); + refreshCategories(); + } + + private void deselectAllArticles() { + HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + .findFragmentById(R.id.headlines_fragment); + + if (hf != null) { + ArticleList selected = hf.getSelectedArticles(); + if (selected.size() > 0) { + selected.clear(); + initMainMenu(); + hf.notifyUpdated(); + } + } + } + + private void goBack(boolean allowQuit) { if (m_smallScreenMode) { if (m_selectedArticle != null) { closeArticle(); @@ -792,7 +821,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { closeCategory(); - } else { + } else if (allowQuit) { finish(); } } else { @@ -800,37 +829,11 @@ public class MainActivity extends FragmentActivity implements OnlineServices { closeArticle(); } else if (m_activeCategory != null) { closeCategory(); - } else { + } else if (allowQuit) { finish(); } } } - - private void closeCategory() { - - findViewById(R.id.feeds_fragment).setVisibility(View.GONE); - findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE); - - m_activeCategory = null; - - initMainMenu(); - refreshCategories(); - } - - private void deselectAllArticles() { - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() - .findFragmentById(R.id.headlines_fragment); - - if (hf != null) { - ArticleList selected = hf.getSelectedArticles(); - if (selected.size() > 0) { - selected.clear(); - initMainMenu(); - hf.notifyUpdated(); - } - } - } - @SuppressWarnings("unchecked") @Override @@ -840,7 +843,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { switch (item.getItemId()) { case android.R.id.home: - closeArticle(); + goBack(false); return true; case R.id.preferences: Intent intent = new Intent(MainActivity.this, @@ -1199,7 +1202,11 @@ public class MainActivity extends FragmentActivity implements OnlineServices { } if (!m_compatMode) { - getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null); + if (!m_smallScreenMode) { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeCategory != null); + } else { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticle != null || m_activeFeed != null || m_activeCategory != null); + } } m_menu.findItem(R.id.set_labels).setEnabled(m_apiLevel >= 1); diff --git a/src/org/fox/ttrss/OfflineActivity.java b/src/org/fox/ttrss/OfflineActivity.java index ca69623c..730c6a3e 100644 --- a/src/org/fox/ttrss/OfflineActivity.java +++ b/src/org/fox/ttrss/OfflineActivity.java @@ -305,8 +305,7 @@ public class OfflineActivity extends FragmentActivity implements } } - @Override - public void onBackPressed() { + private void goBack(boolean allowQuit) { if (m_smallScreenMode) { if (m_selectedArticleId != 0) { closeArticle(); @@ -332,17 +331,21 @@ public class OfflineActivity extends FragmentActivity implements refreshViews(); initMainMenu(); - } else { + } else if (allowQuit) { finish(); } } else { if (m_selectedArticleId != 0) { closeArticle(); - } else { + } else if (allowQuit) { finish(); } } - + } + + @Override + public void onBackPressed() { + goBack(true); } /* @@ -426,7 +429,7 @@ public class OfflineActivity extends FragmentActivity implements switch (item.getItemId()) { case android.R.id.home: - closeArticle(); + goBack(false); return true; case R.id.preferences: Intent intent = new Intent(this, PreferencesActivity.class); @@ -668,7 +671,11 @@ public class OfflineActivity extends FragmentActivity implements } if (!m_compatMode) { - getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0); + if (!m_smallScreenMode) { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0); + } else { + getActionBar().setDisplayHomeAsUpEnabled(m_selectedArticleId != 0 || m_activeFeedId != 0); + } } } }