ConfigActivity: Fix restoring layout on resume

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-08-16 00:46:43 -05:00
parent 61d6b89bbe
commit ebb0091ad4

View File

@ -26,7 +26,7 @@ public class ConfigActivity extends BaseConfigActivity {
private ConfigListFragment listFragment; private ConfigListFragment listFragment;
private int mainContainer; private int mainContainer;
private final PlaceholderFragment placeholderFragment = new PlaceholderFragment(); private final PlaceholderFragment placeholderFragment = new PlaceholderFragment();
private boolean updateWasSkipped; private boolean wasUpdateSkipped;
@Override @Override
public void onBackPressed() { public void onBackPressed() {
@ -63,11 +63,11 @@ public class ConfigActivity extends BaseConfigActivity {
// Avoid performing fragment transactions when it would be illegal or the service is null. // Avoid performing fragment transactions when it would be illegal or the service is null.
if (!isServiceAvailable || isStateSaved) { if (!isServiceAvailable || isStateSaved) {
// Signal that updates need to be performed once the activity is resumed. // Signal that updates need to be performed once the activity is resumed.
updateWasSkipped = true; wasUpdateSkipped = true;
return; return;
} else { } else {
// Now that an update is being performed, reset the flag. // Now that an update is being performed, reset the flag.
updateWasSkipped = false; wasUpdateSkipped = false;
} }
// If the config change came from the intent or ConfigEditFragment, forward it to the list. // If the config change came from the intent or ConfigEditFragment, forward it to the list.
// listFragment is guaranteed not to be null at this point by onServiceAvailable(). // listFragment is guaranteed not to be null at this point by onServiceAvailable().
@ -107,15 +107,16 @@ public class ConfigActivity extends BaseConfigActivity {
startActivity(new Intent(this, SettingsActivity.class)); startActivity(new Intent(this, SettingsActivity.class));
return true; return true;
default: default:
return false; return super.onOptionsItemSelected(item);
} }
} }
@Override @Override
public void onPostResume() { public void onPostResume() {
super.onPostResume(); super.onPostResume();
final boolean wasStateSaved = isStateSaved;
isStateSaved = false; isStateSaved = false;
if (updateWasSkipped) if (wasStateSaved || wasUpdateSkipped)
onCurrentConfigChanged(getCurrentConfig()); onCurrentConfigChanged(getCurrentConfig());
} }