diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-04-30 20:55:27 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-04-30 20:55:27 -0700 |
commit | 9f396015bf6cbf538871305dc8458d288b2ebd9a (patch) | |
tree | a72115065f16dded6e9133ce66c279f35c66b5f5 | |
parent | b0e3b154eab451ee0980aa7b2266bba5bde5e8f8 (diff) | |
download | dsub-9f396015bf6cbf538871305dc8458d288b2ebd9a.tar.gz dsub-9f396015bf6cbf538871305dc8458d288b2ebd9a.tar.bz2 dsub-9f396015bf6cbf538871305dc8458d288b2ebd9a.zip |
Do own backStack logic for when not using tabs as well + apply to search activity
5 files changed, 58 insertions, 2 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index b5ff4abb..2504d040 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -189,7 +189,7 @@ public class MainActivity extends SubsonicActivity { @Override public void onBackPressed() { - if(pagerAdapter.onBackPressed()) { + if(onBackPressedSupport()) { if(lastBackPressTime < (System.currentTimeMillis() - 4000)) { lastBackPressTime = System.currentTimeMillis(); Util.toast(this, R.string.main_back_confirm); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java index 53864e7d..7d2280e2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java @@ -63,4 +63,11 @@ public class SearchActivity extends SubsonicActivity { public void onSupportNewIntent(Intent intent) { onNewIntent(intent); } + + @Override + public void onBackPressed() { + if(onBackPressedSupport()) { + super.onBackPressed(); + } + } }
\ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index a56cffba..8e9c147d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -39,6 +39,8 @@ public class SubsonicActivity extends SherlockFragmentActivity { private boolean destroyed = false;
protected TabPagerAdapter pagerAdapter;
protected ViewPager viewPager;
+ protected List<SubsonicFragment> backStack = new ArrayList<SubsonicFragment>();
+ protected SubsonicFragment currentFragment;
@Override
protected void onCreate(Bundle bundle) {
@@ -87,6 +89,49 @@ public class SubsonicActivity extends SherlockFragmentActivity { return super.onKeyDown(keyCode, event);
}
+ public boolean onBackPressedSupport() {
+ if(pagerAdapter != null) {
+ return pagerAdapter.onBackPressed();
+ } else {
+ if(backStack.size() > 0) {
+ if(currentFragment != null) {
+ currentFragment.setPrimaryFragment(false);
+ }
+ Fragment oldFrag = (Fragment)currentFragment;
+
+ currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1);
+ currentFragment.setPrimaryFragment(true);
+ invalidateOptionsMenu();
+
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.remove(oldFrag);
+ trans.commit();
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+
+ public void replaceFragment(SubsonicFragment fragment, int id) {
+ if(pagerAdapter != null) {
+ pagerAdapter.replaceCurrent(fragment, id);
+ } else {
+ if(currentFragment != null) {
+ currentFragment.setPrimaryFragment(false);
+ }
+ backStack.add(fragment);
+
+ currentFragment = fragment;
+ currentFragment.setPrimaryFragment(true);
+ invalidateOptionsMenu();
+
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.add(id, fragment);
+ trans.commit();
+ }
+ }
+
protected void addTab(int titleRes, Class fragmentClass, Bundle args) {
pagerAdapter.addTab(getString(titleRes), fragmentClass, args);
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index ff12ac22..39bc4617 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -150,6 +150,10 @@ public class SearchFragment extends SubsonicFragment { @Override
public boolean onContextItemSelected(MenuItem menuItem) {
+ if(!primaryFragment) {
+ return false;
+ }
+
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
Object selectedItem = list.getItemAtPosition(info.position);
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 67e05faa..e1c8087b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -237,7 +237,7 @@ public class SubsonicFragment extends SherlockFragment { }
public void replaceFragment(SubsonicFragment fragment, int id) {
- context.getPagerAdapter().replaceCurrent(fragment, id);
+ context.replaceFragment(fragment, id);
}
public void setPrimaryFragment(boolean primary) {
|