Improve handling of HotspotState's field 'consumed'

This commit is contained in:
Sebastian Kürten
2021-08-04 12:35:33 +02:00
parent acacb59114
commit d411b99030
2 changed files with 7 additions and 3 deletions

View File

@@ -60,6 +60,7 @@ public class HotspotActivity extends BriarActivity
// to not lose state on configuration changes // to not lose state on configuration changes
if (fm.findFragmentByTag(tag) == null) { if (fm.findFragmentByTag(tag) == null) {
if (started.wasNotYetConsumed()) { if (started.wasNotYetConsumed()) {
started.consume();
showFragment(fm, new HotspotFragment(), tag); showFragment(fm, new HotspotFragment(), tag);
} }
} }

View File

@@ -57,16 +57,19 @@ abstract class HotspotState {
return websiteConfig; return websiteConfig;
} }
@UiThread
boolean wasNotYetConsumed() {
return !consumed;
}
/** /**
* Mark this state as consumed, i.e. the UI has already done something * Mark this state as consumed, i.e. the UI has already done something
* as a result of the state changing to this. This can be used in order * as a result of the state changing to this. This can be used in order
* to not repeat actions such as showing fragments on rotation changes. * to not repeat actions such as showing fragments on rotation changes.
*/ */
@UiThread @UiThread
boolean wasNotYetConsumed() { void consume() {
boolean old = consumed;
consumed = true; consumed = true;
return !old;
} }
} }