Reset plugin assignments when starting AddNearbyContactIntroFragment

This commit is contained in:
Torsten Grote
2021-04-20 14:38:58 -03:00
parent 4c11f93ee2
commit 0266da993d
2 changed files with 16 additions and 2 deletions

View File

@@ -95,6 +95,9 @@ public class AddNearbyContactIntroFragment extends BaseFragment {
super.onStart();
// Permissions may have been granted manually while we were stopped
permissionManager.resetPermissions();
// Reset plugins in case they were assigned when we weren't signed-in
viewModel.resetPlugins();
// Scroll down in case the screen is small, so the button is visible
scrollView.post(() -> scrollView.fullScroll(FOCUS_DOWN));
}

View File

@@ -148,8 +148,8 @@ class AddNearbyContactViewModel extends AndroidViewModel
@Nullable
private final BluetoothAdapter bt;
@Nullable
private final Plugin wifiPlugin, bluetoothPlugin;
@Nullable // UiThread
private Plugin wifiPlugin, bluetoothPlugin;
// UiThread
private BluetoothDecision bluetoothDecision = BluetoothDecision.UNKNOWN;
@@ -210,6 +210,17 @@ class AddNearbyContactViewModel extends AndroidViewModel
stopListening();
}
/**
* When this activity gets killed and re-created while the user is not
* signed-in (can happen when a permission is denied which terminates app),
* the plugins will be null, so we need to re-assign them after sign-in.
*/
@UiThread
void resetPlugins() {
wifiPlugin = pluginManager.getPlugin(LanTcpConstants.ID);
bluetoothPlugin = pluginManager.getPlugin(BluetoothConstants.ID);
}
@UiThread
void onContinueClicked() {
if (bluetoothDecision == REFUSED) {