diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-11-01 23:01:25 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-11-01 23:01:25 -0700 |
commit | c3a10b4d37fcb132dfb4505e4b2cdf59a0d0423c (patch) | |
tree | 74f1d06a52da43ed0635f21e6897617013bbe161 | |
parent | aa7c4a09e6b7ff5dc696ead1f685a4033be8ed67 (diff) | |
download | dsub-c3a10b4d37fcb132dfb4505e4b2cdf59a0d0423c.tar.gz dsub-c3a10b4d37fcb132dfb4505e4b2cdf59a0d0423c.tar.bz2 dsub-c3a10b4d37fcb132dfb4505e4b2cdf59a0d0423c.zip |
#123 Fleshed out more of the tablet logic
4 files changed, 100 insertions, 31 deletions
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 3a41bd91..4c92d11c 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -107,12 +107,6 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
drawerToggle.syncState();
-
- // Check whether this is a tablet or not
- secondaryContainer = findViewById(R.id.fragment_second_container);
- if(secondaryContainer != null) {
- primaryContainer = findViewById(R.id.fragment_container);
- }
}
@Override
@@ -189,6 +183,12 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte };
drawer.setDrawerListener(drawerToggle);
drawerToggle.setDrawerIndicatorEnabled(false);
+
+ // Check whether this is a tablet or not
+ secondaryContainer = findViewById(R.id.fragment_second_container);
+ if(secondaryContainer != null) {
+ primaryContainer = findViewById(R.id.fragment_container);
+ }
}
@Override
@@ -212,11 +212,42 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte FragmentManager fm = getSupportFragmentManager();
currentFragment = (SubsonicFragment)fm.findFragmentByTag(ids[0]);
currentFragment.setPrimaryFragment(true);
+ currentFragment.setSupportTag(ids[0]);
supportInvalidateOptionsMenu();
for(int i = 1; i < size; i++) {
SubsonicFragment frag = (SubsonicFragment)fm.findFragmentByTag(ids[i]);
+ frag.setSupportTag(ids[i]);
+ if(secondaryContainer != null) {
+ frag.setPrimaryFragment(false, true);
+ }
backStack.add(frag);
}
+
+ // Current fragment is hidden in secondaryContainer
+ if(secondaryContainer == null && findViewById(currentFragment.getRootId()) == null) {
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.remove(currentFragment);
+ trans.commit();
+ getSupportFragmentManager().executePendingTransactions();
+
+ trans = getSupportFragmentManager().beginTransaction();
+ trans.add(backStack.get(backStack.size() - 1).getRootId(), currentFragment, ids[0]);
+ trans.commit();
+ }
+ // Current fragment needs to be moved over to secondaryContainer
+ else if(secondaryContainer != null && secondaryContainer.findViewById(currentFragment.getRootId()) == null) {
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+ trans.remove(currentFragment);
+ trans.commit();
+ getSupportFragmentManager().executePendingTransactions();
+
+ trans = getSupportFragmentManager().beginTransaction();
+ trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
+ trans.commit();
+
+ secondaryContainer.setVisibility(View.VISIBLE);
+ }
+
recreateSpinner();
}
@@ -256,7 +287,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte @Override
public void setTitle(CharSequence title) {
- super.setTitle(title);
+ getSupportActionBar().setTitle(title);
recreateSpinner();
}
public void setSubtitle(CharSequence title) {
@@ -367,10 +398,13 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte super.onBackPressed();
}
}
-
+
public void replaceFragment(SubsonicFragment fragment, int id, int tag) {
+ replaceFragment(fragment, id, tag, false);
+ }
+ public void replaceFragment(SubsonicFragment fragment, int id, int tag, boolean replaceCurrent) {
if(currentFragment != null) {
- currentFragment.setPrimaryFragment(false);
+ currentFragment.setPrimaryFragment(false, secondaryContainer != null);
}
backStack.add(currentFragment);
@@ -385,21 +419,31 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte } else {
// Make sure secondary container is visible now
secondaryContainer.setVisibility(View.VISIBLE);
-
+
+ FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
+
// Check to see if you need to put on top of old left or not
- int leftId = R.id.fragment_container;
if(backStack.size() > 1) {
- SubsonicFragment oldLeftFragment = backStack.get(backStack.size() - 2);
- leftId = oldLeftFragment.getRootId();
+ // Move old right to left if there is a backstack already
+ SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1);
+ trans.remove(newLeftFragment);
+
+ // Only move right to left if replaceCurrent is false
+ if(!replaceCurrent) {
+ SubsonicFragment oldLeftFragment = backStack.get(backStack.size() - 2);
+ int leftId = oldLeftFragment.getRootId();
+
+ // Make sure remove is finished before adding
+ trans.commit();
+ getSupportFragmentManager().executePendingTransactions();
+
+ trans = getSupportFragmentManager().beginTransaction();
+ trans.add(leftId, newLeftFragment, newLeftFragment.getSupportTag() + "");
+ } else {
+ backStack.remove(backStack.size() - 1);
+ }
}
- FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
-
- // Move old right to left
- SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1);
- trans.remove(newLeftFragment);
- trans.add(leftId, newLeftFragment, newLeftFragment.getSupportTag() + "");
-
// Add fragment to the right container
trans.add(R.id.fragment_second_container, fragment, tag + "");
@@ -408,7 +452,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte }
recreateSpinner();
}
- protected void removeCurrent() {
+ public void removeCurrent() {
if(currentFragment != null) {
currentFragment.setPrimaryFragment(false);
}
@@ -427,10 +471,21 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte // Remove old right fragment
trans.remove(oldFrag);
-
- // Add current left fragment to right side
- trans.remove(currentFragment);
- trans.add(R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + "");
+
+ // Only switch places if there is a backstack, otherwise primary container is correct
+ if(backStack.size() > 0) {
+ // Add current left fragment to right side
+ trans.remove(currentFragment);
+
+ // Make sure remove is finished before adding
+ trans.commit();
+ getSupportFragmentManager().executePendingTransactions();
+
+ trans = getSupportFragmentManager().beginTransaction();
+ trans.add(R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + "");
+ } else {
+ secondaryContainer.setVisibility(View.GONE);
+ }
trans.commit();
}
diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 642822d6..5854e633 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -282,7 +282,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity { drawerToggle.setDrawerIndicatorEnabled(false);
}
@Override
- protected void removeCurrent() {
+ public void removeCurrent() {
super.removeCurrent();
if(backStack.isEmpty()) {
drawerToggle.setDrawerIndicatorEnabled(true);
@@ -311,6 +311,10 @@ public class SubsonicFragmentActivity extends SubsonicActivity { supportInvalidateOptionsMenu();
recreateSpinner();
drawer.closeDrawers();
+
+ if(secondaryContainer != null) {
+ secondaryContainer.setVisibility(View.GONE);
+ }
}
private SubsonicFragment getNewFragment(String fragmentType) {
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 59bfe000..8c99fe01 100644 --- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -138,7 +138,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter }
if(entries == null) {
- if(primaryFragment) {
+ if(primaryFragment || secondaryFragment) {
load(false);
} else {
invalidated = true;
@@ -306,7 +306,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle());
fragment.setArguments(args);
- replaceFragment(fragment, fragId);
+ replaceFragment(fragment, fragId, fragId == rootId);
} else if (entry.isVideo()) {
playVideo(entry);
} else if(entry instanceof PodcastEpisode) {
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 7c293447..bab8cd84 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -85,6 +85,7 @@ public class SubsonicFragment extends Fragment { protected CharSequence subtitle = null;
protected View rootView;
protected boolean primaryFragment = false;
+ protected boolean secondaryFragment = false;
protected boolean invalidated = false;
protected static Random random = new Random();
@@ -289,7 +290,10 @@ public class SubsonicFragment extends Fragment { }
public void replaceFragment(SubsonicFragment fragment, int id) {
- context.replaceFragment(fragment, id, fragment.getSupportTag());
+ replaceFragment(fragment, id, true);
+ }
+ public void replaceFragment(SubsonicFragment fragment, int id, boolean replaceCurrent) {
+ context.replaceFragment(fragment, id, fragment.getSupportTag(), secondaryFragment && replaceCurrent);
}
protected int getNewId() {
@@ -306,7 +310,9 @@ public class SubsonicFragment extends Fragment { public int getRootId() {
return rootView.getId();
}
-
+
+ public void setSupportTag(int tag) { this.tag = tag; }
+ public void setSupportTag(String tag) { this.tag = Integer.parseInt(tag); }
public int getSupportTag() {
return tag;
}
@@ -324,7 +330,11 @@ public class SubsonicFragment extends Fragment { }
}
}
-
+ public void setPrimaryFragment(boolean primary, boolean secondary) {
+ setPrimaryFragment(primary);
+ secondaryFragment = secondary;
+ }
+
public void invalidate() {
if(primaryFragment) {
refresh(false);
|