aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-04-14 16:47:56 -0700
committerScott Jackson <daneren2005@gmail.com>2013-04-14 16:47:56 -0700
commit70024de8492ade279a2337b71864fb3d1284d169 (patch)
tree4922bc2fb3bb0b7fc92634fab4cafcfa21459f71
parent0c4351858bcdfd1d0e193e3983800dfc43c1ada0 (diff)
downloaddsub-70024de8492ade279a2337b71864fb3d1284d169.tar.gz
dsub-70024de8492ade279a2337b71864fb3d1284d169.tar.bz2
dsub-70024de8492ade279a2337b71864fb3d1284d169.zip
Manage own backstack since Google can't design a usable one
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java34
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java30
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java1
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java8
4 files changed, 41 insertions, 32 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
index 06925e8b..57423fb3 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
@@ -52,28 +52,18 @@ public class MainActivity extends SubsonicActivity {
@Override
public void onBackPressed() {
- int backStack = getSupportFragmentManager().getBackStackEntryCount();
- int currentTab = viewPager.getCurrentItem();
-
- if(backStack == 0) {
- if(currentTab == 0) {
- AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
- builder.setTitle(R.string.common_confirm)
- .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- MainActivity.super.onBackPressed();
- }
- })
- .setNegativeButton(R.string.common_cancel, null);
- AlertDialog dialog = builder.create();
- dialog.show();
- } else {
- viewPager.setCurrentItem(0);
- }
- } else {
- super.onBackPressed();
- pagerAdapter.removeCurrent();
+ if(pagerAdapter.onBackPressed()) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+ builder.setTitle(R.string.menu_exit)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ MainActivity.super.onBackPressed();
+ }
+ })
+ .setNegativeButton(R.string.common_cancel, null);
+ AlertDialog dialog = builder.create();
+ dialog.show();
}
}
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 61a8c18c..659d53db 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -224,6 +224,7 @@ public class SubsonicActivity extends SherlockFragmentActivity {
private SubsonicTabFragment currentFragment;
private List tabs = new ArrayList();
private List frags = new ArrayList();
+ private List ids = new ArrayList();
private int currentPosition;
public TabPagerAdapter(SherlockFragmentActivity activity, ViewPager pager) {
@@ -241,6 +242,7 @@ public class SubsonicActivity extends SherlockFragmentActivity {
List fragStack = new ArrayList();
fragStack.add(frag);
frags.add(i, fragStack);
+ ids.add(i, 0);
if(currentFragment == null) {
currentFragment = (SubsonicTabFragment) frag;
currentFragment.setPrimaryFragment(true);
@@ -312,7 +314,7 @@ public class SubsonicActivity extends SherlockFragmentActivity {
notifyDataSetChanged();
}
- public void replaceCurrent(SubsonicTabFragment fragment) {
+ public void replaceCurrent(SubsonicTabFragment fragment, int id) {
if(currentFragment != null) {
currentFragment.setPrimaryFragment(false);
}
@@ -322,6 +324,11 @@ public class SubsonicActivity extends SherlockFragmentActivity {
currentFragment = fragment;
currentFragment.setPrimaryFragment(true);
activity.invalidateOptionsMenu();
+
+ ids.add(currentPosition, id);
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.add(id, fragment);
+ trans.commit();
}
public void removeCurrent() {
@@ -329,11 +336,30 @@ public class SubsonicActivity extends SherlockFragmentActivity {
currentFragment.setPrimaryFragment(false);
}
List fragStack = (List)frags.get(currentPosition);
- fragStack.remove(fragStack.size() - 1);
+ Fragment oldFrag = (Fragment)fragStack.remove(fragStack.size() - 1);
currentFragment = (SubsonicTabFragment) fragStack.get(fragStack.size() - 1);
currentFragment.setPrimaryFragment(true);
activity.invalidateOptionsMenu();
+
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.remove(oldFrag);
+ trans.commit();
+ }
+
+ public boolean onBackPressed() {
+ List fragStack = (List)frags.get(currentPosition);
+ if(fragStack.size() > 1) {
+ removeCurrent();
+ return false;
+ } else {
+ if(currentPosition == 0) {
+ return true;
+ } else {
+ viewPager.setCurrentItem(0);
+ return false;
+ }
+ }
}
private class TabInfo {
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index 92155fe1..9e8d42e9 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -118,7 +118,6 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements
} else {
menuInflater.inflate(R.menu.select_album, menu);
}
- hideButtons = false;
} else {
if(Util.isOffline(context)) {
menuInflater.inflate(R.menu.select_song_offline, menu);
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java
index 017b2c89..ee789382 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java
@@ -22,7 +22,6 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
-import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
@@ -74,12 +73,7 @@ public class SubsonicTabFragment extends SherlockFragment {
public void replaceFragment(SubsonicTabFragment fragment, int id) {
this.setPrimaryFragment(false);
fragment.setPrimaryFragment(true);
- context.getPagerAdapter().replaceCurrent(fragment);
-
- FragmentTransaction trans = getFragmentManager().beginTransaction();
- trans.replace(id, fragment);
- trans.addToBackStack(null);
- trans.commit();
+ context.getPagerAdapter().replaceCurrent(fragment, id);
}
protected void exit() {