mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Add a MutableLiveData to RemoteWipeSetupState
This commit is contained in:
@@ -31,7 +31,7 @@ public class RemoteWipeSetupActivity extends BriarActivity implements
|
||||
viewModel = new ViewModelProvider(this, viewModelFactory)
|
||||
.get(RemoteWipeSetupViewModel.class);
|
||||
|
||||
// viewModel.getState().observeEvent(this, this::onStateChanged);
|
||||
viewModel.getState().observe(this, this::onStateChanged);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +43,7 @@ public class RemoteWipeSetupActivity extends BriarActivity implements
|
||||
} else {
|
||||
showInitialFragment(WiperSelectorFragment.newInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,4 +58,15 @@ public class RemoteWipeSetupActivity extends BriarActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
private void onStateChanged(RemoteWipeSetupState state) {
|
||||
if (state.equals(RemoteWipeSetupState.SUCCESS)) {
|
||||
Toast.makeText(this,
|
||||
"Success",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else if (state.equals(RemoteWipeSetupState.FAILED)) {
|
||||
Toast.makeText(this,
|
||||
"Failed",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.briarproject.briar.android.remotewipe;
|
||||
|
||||
public enum RemoteWipeSetupState {
|
||||
FAILED,
|
||||
SUCCESS
|
||||
}
|
||||
@@ -16,10 +16,12 @@ import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
public class RemoteWipeSetupViewModel extends AndroidViewModel {
|
||||
private final RemoteWipeManager remoteWipeManager;
|
||||
private final DatabaseComponent db;
|
||||
private final MutableLiveData<RemoteWipeSetupState> state = new MutableLiveData<>();
|
||||
|
||||
@Inject
|
||||
RemoteWipeSetupViewModel(
|
||||
@@ -44,7 +46,12 @@ public class RemoteWipeSetupViewModel extends AndroidViewModel {
|
||||
throws DbException, FormatException {
|
||||
db.transaction(false, txn -> {
|
||||
remoteWipeManager.setup(txn, (List<ContactId>) wipers);
|
||||
state.postValue(RemoteWipeSetupState.SUCCESS);
|
||||
});
|
||||
}
|
||||
|
||||
public MutableLiveData<RemoteWipeSetupState> getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user