mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Don't move to HotspotFragment on rotate when user navigated back to introduction
This commit is contained in:
@@ -54,11 +54,14 @@ public class HotspotActivity extends BriarActivity
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
viewModel.getState().observe(this, hotspotState -> {
|
||||
if (hotspotState instanceof HotspotStarted) {
|
||||
HotspotStarted started = (HotspotStarted) hotspotState;
|
||||
String tag = HotspotFragment.TAG;
|
||||
// check if fragment is already added
|
||||
// to not lose state on configuration changes
|
||||
if (fm.findFragmentByTag(tag) == null) {
|
||||
showFragment(fm, new HotspotFragment(), tag);
|
||||
if (!started.consume()) {
|
||||
showFragment(fm, new HotspotFragment(), tag);
|
||||
}
|
||||
}
|
||||
} else if (hotspotState instanceof HotspotError) {
|
||||
HotspotError error = ((HotspotError) hotspotState);
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
@NotNullByDefault
|
||||
abstract class HotspotState {
|
||||
@@ -38,6 +39,9 @@ abstract class HotspotState {
|
||||
static class HotspotStarted extends HotspotState {
|
||||
private final NetworkConfig networkConfig;
|
||||
private final WebsiteConfig websiteConfig;
|
||||
// 'consumed' is set to true once this state triggered a UI change, i.e.
|
||||
// moving to the next fragment.
|
||||
private boolean consumed = false;
|
||||
|
||||
HotspotStarted(NetworkConfig networkConfig,
|
||||
WebsiteConfig websiteConfig) {
|
||||
@@ -52,6 +56,18 @@ abstract class HotspotState {
|
||||
WebsiteConfig getWebsiteConfig() {
|
||||
return websiteConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* to not repeat actions such as showing fragments on rotation changes.
|
||||
*/
|
||||
@UiThread
|
||||
boolean consume() {
|
||||
boolean old = consumed;
|
||||
consumed = true;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
static class HotspotError extends HotspotState {
|
||||
|
||||
@@ -96,9 +96,13 @@ class HotspotViewModel extends DbViewModel
|
||||
void startHotspot() {
|
||||
HotspotState s = state.getValue();
|
||||
if (s instanceof HotspotStarted) {
|
||||
// Don't try to start again, if already started, just re-set value.
|
||||
// This can happen if the user navigates back to intro fragment.
|
||||
state.setValue(s);
|
||||
// This can happen if the user navigates back to intro fragment and
|
||||
// taps 'start sharing' again. In this case, don't try to start the
|
||||
// hotspot again. Instead, just create a new, unconsumed HotspotStarted
|
||||
// event with the same config.
|
||||
HotspotStarted old = (HotspotStarted) s;
|
||||
state.setValue(new HotspotStarted(old.getNetworkConfig(),
|
||||
old.getWebsiteConfig()));
|
||||
} else {
|
||||
hotspotManager.startWifiP2pHotspot();
|
||||
notificationManager.showHotspotNotification();
|
||||
|
||||
Reference in New Issue
Block a user