mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 07:09:56 +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();
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
viewModel.getState().observe(this, hotspotState -> {
|
viewModel.getState().observe(this, hotspotState -> {
|
||||||
if (hotspotState instanceof HotspotStarted) {
|
if (hotspotState instanceof HotspotStarted) {
|
||||||
|
HotspotStarted started = (HotspotStarted) hotspotState;
|
||||||
String tag = HotspotFragment.TAG;
|
String tag = HotspotFragment.TAG;
|
||||||
// check if fragment is already added
|
// check if fragment is already added
|
||||||
// to not lose state on configuration changes
|
// to not lose state on configuration changes
|
||||||
if (fm.findFragmentByTag(tag) == null) {
|
if (fm.findFragmentByTag(tag) == null) {
|
||||||
showFragment(fm, new HotspotFragment(), tag);
|
if (!started.consume()) {
|
||||||
|
showFragment(fm, new HotspotFragment(), tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (hotspotState instanceof HotspotError) {
|
} else if (hotspotState instanceof HotspotError) {
|
||||||
HotspotError error = ((HotspotError) hotspotState);
|
HotspotError error = ((HotspotError) hotspotState);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
abstract class HotspotState {
|
abstract class HotspotState {
|
||||||
@@ -38,6 +39,9 @@ abstract class HotspotState {
|
|||||||
static class HotspotStarted extends HotspotState {
|
static class HotspotStarted extends HotspotState {
|
||||||
private final NetworkConfig networkConfig;
|
private final NetworkConfig networkConfig;
|
||||||
private final WebsiteConfig websiteConfig;
|
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,
|
HotspotStarted(NetworkConfig networkConfig,
|
||||||
WebsiteConfig websiteConfig) {
|
WebsiteConfig websiteConfig) {
|
||||||
@@ -52,6 +56,18 @@ abstract class HotspotState {
|
|||||||
WebsiteConfig getWebsiteConfig() {
|
WebsiteConfig getWebsiteConfig() {
|
||||||
return websiteConfig;
|
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 {
|
static class HotspotError extends HotspotState {
|
||||||
|
|||||||
@@ -96,9 +96,13 @@ class HotspotViewModel extends DbViewModel
|
|||||||
void startHotspot() {
|
void startHotspot() {
|
||||||
HotspotState s = state.getValue();
|
HotspotState s = state.getValue();
|
||||||
if (s instanceof HotspotStarted) {
|
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 and
|
||||||
// This can happen if the user navigates back to intro fragment.
|
// taps 'start sharing' again. In this case, don't try to start the
|
||||||
state.setValue(s);
|
// 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 {
|
} else {
|
||||||
hotspotManager.startWifiP2pHotspot();
|
hotspotManager.startWifiP2pHotspot();
|
||||||
notificationManager.showHotspotNotification();
|
notificationManager.showHotspotNotification();
|
||||||
|
|||||||
Reference in New Issue
Block a user