ConfigActivity: Invert isSplitLayout→isSingleLayout for clarity

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-24 17:25:08 -05:00
parent b1d0091bc0
commit 23fdb72eda

View File

@ -25,7 +25,7 @@ public class ConfigActivity extends BaseConfigActivity {
private final FragmentCache fragments = new FragmentCache(fm); private final FragmentCache fragments = new FragmentCache(fm);
private boolean isLayoutFinished; private boolean isLayoutFinished;
private boolean isServiceAvailable; private boolean isServiceAvailable;
private boolean isSplitLayout; private boolean isSingleLayout;
private boolean isStateSaved; private boolean isStateSaved;
private int mainContainer; private int mainContainer;
private String visibleFragmentTag; private String visibleFragmentTag;
@ -41,7 +41,7 @@ public class ConfigActivity extends BaseConfigActivity {
// Sanity check. // Sanity check.
if (tag == null && config != null) if (tag == null && config != null)
throw new IllegalArgumentException("Cannot set a config on a null fragment"); throw new IllegalArgumentException("Cannot set a config on a null fragment");
if ((tag == null && !isSplitLayout) || (TAG_LIST.equals(tag) && isSplitLayout)) if ((tag == null && isSingleLayout) || (TAG_LIST.equals(tag) && !isSingleLayout))
throw new IllegalArgumentException("Requested tag " + tag + " does not match layout"); throw new IllegalArgumentException("Requested tag " + tag + " does not match layout");
// First tear down fragments as necessary. // First tear down fragments as necessary.
if (tag == null || TAG_LIST.equals(tag) || (TAG_DETAIL.equals(tag) if (tag == null || TAG_LIST.equals(tag) || (TAG_DETAIL.equals(tag)
@ -55,7 +55,7 @@ public class ConfigActivity extends BaseConfigActivity {
// Recompute the visible fragment. // Recompute the visible fragment.
if (TAG_EDIT.equals(visibleFragmentTag)) if (TAG_EDIT.equals(visibleFragmentTag))
visibleFragmentTag = TAG_DETAIL; visibleFragmentTag = TAG_DETAIL;
else if (!isSplitLayout && TAG_DETAIL.equals(visibleFragmentTag)) else if (isSingleLayout && TAG_DETAIL.equals(visibleFragmentTag))
visibleFragmentTag = TAG_LIST; visibleFragmentTag = TAG_LIST;
else else
throw new IllegalStateException(); throw new IllegalStateException();
@ -82,7 +82,7 @@ public class ConfigActivity extends BaseConfigActivity {
editorState = null; editorState = null;
} }
final FragmentTransaction transaction = fm.beginTransaction(); final FragmentTransaction transaction = fm.beginTransaction();
if (TAG_EDIT.equals(tag) || (!isSplitLayout && TAG_DETAIL.equals(tag))) { if (TAG_EDIT.equals(tag) || (isSingleLayout && TAG_DETAIL.equals(tag))) {
transaction.addToBackStack(null); transaction.addToBackStack(null);
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
} }
@ -113,19 +113,19 @@ public class ConfigActivity extends BaseConfigActivity {
if (fm.findFragmentById(R.id.master_fragment) == null) if (fm.findFragmentById(R.id.master_fragment) == null)
fm.beginTransaction().add(R.id.master_fragment, listFragment, TAG_LIST).commit(); fm.beginTransaction().add(R.id.master_fragment, listFragment, TAG_LIST).commit();
// In the single-pane layout, the main container starts holding the list fragment. // In the single-pane layout, the main container starts holding the list fragment.
if (!isSplitLayout && visibleFragmentTag == null) if (isSingleLayout && visibleFragmentTag == null)
visibleFragmentTag = TAG_LIST; visibleFragmentTag = TAG_LIST;
// Forward any config changes to the list (they may have come from the intent or editing). // Forward any config changes to the list (they may have come from the intent or editing).
listFragment.setCurrentConfig(config); listFragment.setCurrentConfig(config);
// Ensure the correct main fragment is visible, adjusting the back stack as necessary. // Ensure the correct main fragment is visible, adjusting the back stack as necessary.
moveToFragment(config, shouldBeEditing ? TAG_EDIT : moveToFragment(config, shouldBeEditing ? TAG_EDIT :
(config != null ? TAG_DETAIL : (isSplitLayout ? null : TAG_LIST))); (config != null ? TAG_DETAIL : (isSingleLayout ? TAG_LIST : null)));
// Show the current config as the title if the list of configurations is not visible. // Show the current config as the title if the list of configurations is not visible.
setTitle(!isSplitLayout && config != null ? config.getName() : getString(R.string.app_name)); setTitle(isSingleLayout && config != null ? config.getName() : getString(R.string.app_name));
// Show or hide the action bar back button if the back stack is not empty. // Show or hide the action bar back button if the back stack is not empty.
if (getActionBar() != null) { if (getActionBar() != null) {
getActionBar().setDisplayHomeAsUpEnabled(config != null && getActionBar().setDisplayHomeAsUpEnabled(config != null &&
(!isSplitLayout || shouldBeEditing)); (isSingleLayout || shouldBeEditing));
} }
} }
@ -135,7 +135,7 @@ public class ConfigActivity extends BaseConfigActivity {
// The visible fragment is now the one that was on top of the back stack, if there was one. // The visible fragment is now the one that was on top of the back stack, if there was one.
if (isEditing()) if (isEditing())
visibleFragmentTag = TAG_DETAIL; visibleFragmentTag = TAG_DETAIL;
else if (!isSplitLayout && TAG_DETAIL.equals(visibleFragmentTag)) else if (isSingleLayout && TAG_DETAIL.equals(visibleFragmentTag))
visibleFragmentTag = TAG_LIST; visibleFragmentTag = TAG_LIST;
// If the user went back from the detail screen to the list, clear the current config. // If the user went back from the detail screen to the list, clear the current config.
moveToState(isEditing() ? getCurrentConfig() : null, false); moveToState(isEditing() ? getCurrentConfig() : null, false);
@ -147,8 +147,8 @@ public class ConfigActivity extends BaseConfigActivity {
if (savedInstanceState != null) if (savedInstanceState != null)
editorState = savedInstanceState.getParcelable(KEY_EDITOR_STATE); editorState = savedInstanceState.getParcelable(KEY_EDITOR_STATE);
setContentView(R.layout.config_activity); setContentView(R.layout.config_activity);
isSplitLayout = findViewById(R.id.detail_fragment) != null; isSingleLayout = findViewById(R.id.detail_fragment) == null;
mainContainer = isSplitLayout ? R.id.detail_fragment : R.id.master_fragment; mainContainer = isSingleLayout ? R.id.master_fragment : R.id.detail_fragment;
isLayoutFinished = true; isLayoutFinished = true;
moveToState(getCurrentConfig(), isEditing()); moveToState(getCurrentConfig(), isEditing());
} }
@ -214,7 +214,7 @@ public class ConfigActivity extends BaseConfigActivity {
// For the case where the activity is restarted. // For the case where the activity is restarted.
outState.putParcelable(KEY_EDITOR_STATE, editorState); outState.putParcelable(KEY_EDITOR_STATE, editorState);
} }
moveToFragment(null, isSplitLayout ? null : TAG_LIST); moveToFragment(null, isSingleLayout ? TAG_LIST : null);
} }
// Prevent further changes to fragments. // Prevent further changes to fragments.
isStateSaved = true; isStateSaved = true;