Add helper to determine if now playing is open

This commit is contained in:
Andrew Rabert 2018-07-03 17:41:47 -04:00
parent 405fc8cafd
commit 2054ce5427
1 changed files with 17 additions and 11 deletions

View File

@ -310,7 +310,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
super.onNewIntent(intent); super.onNewIntent(intent);
if (currentFragment != null && intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) { if (currentFragment != null && intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY) != null) {
if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { if (isNowPlayingOpen()) {
closeNowPlaying(); closeNowPlaying();
} }
@ -329,7 +329,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
replaceFragment(fragment, fragment.getSupportTag()); replaceFragment(fragment, fragment.getSupportTag());
} }
} else if (intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, false)) { } else if (intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, false)) {
if (slideUpPanel.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED) { if (!isNowPlayingOpen()) {
openNowPlaying(); openNowPlaying();
} }
} else { } else {
@ -417,10 +417,12 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && secondaryFragment == null) { if (isNowPlayingOpen()) {
closeNowPlaying(); if (secondaryFragment == null) {
} else if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { closeNowPlaying();
removeCurrent(); } else {
removeCurrent();
}
} else { } else {
super.onBackPressed(); super.onBackPressed();
} }
@ -428,7 +430,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
@Override @Override
public SubsonicFragment getCurrentFragment() { public SubsonicFragment getCurrentFragment() {
if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { if (isNowPlayingOpen()) {
if (secondaryFragment == null) { if (secondaryFragment == null) {
return nowPlayingFragment; return nowPlayingFragment;
} else { } else {
@ -441,7 +443,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
@Override @Override
public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) { public void replaceFragment(SubsonicFragment fragment, int tag, boolean replaceCurrent) {
if (slideUpPanel != null && slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && !isPanelClosing) { if (slideUpPanel != null && isNowPlayingOpen() && !isPanelClosing) {
secondaryFragment = fragment; secondaryFragment = fragment;
nowPlayingFragment.setPrimaryFragment(false); nowPlayingFragment.setPrimaryFragment(false);
secondaryFragment.setPrimaryFragment(true); secondaryFragment.setPrimaryFragment(true);
@ -459,7 +461,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
@Override @Override
public void removeCurrent() { public void removeCurrent() {
if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED && secondaryFragment != null) { if (isNowPlayingOpen() && secondaryFragment != null) {
FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left); trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right, R.anim.enter_from_right, R.anim.exit_to_left);
trans.remove(secondaryFragment); trans.remove(secondaryFragment);
@ -476,7 +478,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
@Override @Override
public void setTitle(CharSequence title) { public void setTitle(CharSequence title) {
if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { if (isNowPlayingOpen()) {
getSupportActionBar().setTitle(title); getSupportActionBar().setTitle(title);
} else { } else {
super.setTitle(title); super.setTitle(title);
@ -487,7 +489,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
protected void drawerItemSelected(String fragmentType) { protected void drawerItemSelected(String fragmentType) {
super.drawerItemSelected(fragmentType); super.drawerItemSelected(fragmentType);
if (slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) { if (isNowPlayingOpen()) {
closeNowPlaying(); closeNowPlaying();
} }
} }
@ -536,6 +538,10 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
isPanelClosing = true; isPanelClosing = true;
} }
private boolean isNowPlayingOpen() {
return slideUpPanel.getPanelState() == PanelState.EXPANDED;
}
private SubsonicFragment getNewFragment(String fragmentType) { private SubsonicFragment getNewFragment(String fragmentType) {
switch (fragmentType) { switch (fragmentType) {
case "Playlist": case "Playlist":