ConfigActivity: Adjust when the back arrow is shown

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-16 01:05:13 -05:00
parent 73217a098a
commit 6d2960b853

View File

@ -31,13 +31,15 @@ public class ConfigActivity extends BaseConfigActivity {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
super.onBackPressed(); super.onBackPressed();
// Ensure the current config is cleared when going back to the single-fragment-layout list. if ((isEditing && isSplitLayout) || (!isEditing && !isSplitLayout)) {
if (getActionBar() != null)
getActionBar().setDisplayHomeAsUpEnabled(false);
}
// Ensure the current config is cleared when going back to the single-pane-layout list.
if (isEditing) if (isEditing)
isEditing = false; isEditing = false;
else else
setCurrentConfig(null); setCurrentConfig(null);
if (!isSplitLayout && fm.getBackStackEntryCount() == 0 && getActionBar() != null)
getActionBar().setDisplayHomeAsUpEnabled(false);
} }
@Override @Override
@ -77,10 +79,8 @@ public class ConfigActivity extends BaseConfigActivity {
if (!isSplitLayout) if (!isSplitLayout)
setTitle(config != null ? config.getName() : getString(R.string.app_name)); setTitle(config != null ? config.getName() : getString(R.string.app_name));
// Update the fragment in the main container. // Update the fragment in the main container.
if (isEditing) { if (isEditing)
fm.popBackStackImmediate(); onBackPressed();
isEditing = false;
}
if (config != null) { if (config != null) {
final boolean shouldPush = !isSplitLayout && final boolean shouldPush = !isSplitLayout &&
fm.findFragmentById(mainContainer) instanceof ConfigListFragment; fm.findFragmentById(mainContainer) instanceof ConfigListFragment;
@ -97,8 +97,8 @@ public class ConfigActivity extends BaseConfigActivity {
onBackPressed(); onBackPressed();
return true; return true;
case R.id.menu_action_edit: case R.id.menu_action_edit:
switchToFragment(mainContainer, TAG_EDIT, true);
isEditing = true; isEditing = true;
switchToFragment(mainContainer, TAG_EDIT, true);
return true; return true;
case R.id.menu_action_save: case R.id.menu_action_save:
// This menu item is handled by the current fragment. // This menu item is handled by the current fragment.
@ -186,7 +186,7 @@ public class ConfigActivity extends BaseConfigActivity {
if (push) { if (push) {
transaction.addToBackStack(null); transaction.addToBackStack(null);
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
if (!isSplitLayout && getActionBar() != null) if (getActionBar() != null && (!isSplitLayout || isEditing))
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);
} }
transaction.replace(container, fragment, null).commit(); transaction.replace(container, fragment, null).commit();