mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Popup dialog on shards sent
This commit is contained in:
@@ -7,6 +7,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
@@ -31,7 +32,7 @@ public class ExistingBackupFragment extends BaseFragment {
|
|||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
private static SocialBackupSetupViewModel viewModel;
|
private SocialBackupSetupViewModel viewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
@@ -40,21 +41,6 @@ public class ExistingBackupFragment extends BaseFragment {
|
|||||||
.get(SocialBackupSetupViewModel.class);
|
.get(SocialBackupSetupViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExistingBackupFragment newInstance() {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
BackupMetadata backupMetadata = viewModel.getBackupMetadata();
|
|
||||||
List<Author> custodians = backupMetadata.getCustodians();
|
|
||||||
ArrayList custodianNames = new ArrayList();
|
|
||||||
for (Author custodian : custodians) {
|
|
||||||
custodianNames.add(custodian.getName());
|
|
||||||
}
|
|
||||||
bundle.putStringArrayList(CUSTODIANS, custodianNames);
|
|
||||||
bundle.putInt(THRESHOLD, backupMetadata.getThreshold());
|
|
||||||
ExistingBackupFragment fragment = new ExistingBackupFragment();
|
|
||||||
fragment.setArguments(bundle);
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -68,20 +54,20 @@ public class ExistingBackupFragment extends BaseFragment {
|
|||||||
ViewGroup container, @Nullable Bundle savedInstanceState) {
|
ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_existing_backup,
|
View view = inflater.inflate(R.layout.fragment_existing_backup,
|
||||||
container, false);
|
container, false);
|
||||||
Bundle args = requireArguments();
|
BackupMetadata backupMetadata = viewModel.getBackupMetadata();
|
||||||
ArrayList<String> custodianNames = args.getStringArrayList(CUSTODIANS);
|
List<Author> custodians = backupMetadata.getCustodians();
|
||||||
|
|
||||||
StringBuilder custodianNamesString = new StringBuilder();
|
StringBuilder custodianNamesString = new StringBuilder();
|
||||||
for (String custodianName : custodianNames) {
|
for (Author custodian : custodians) {
|
||||||
custodianNamesString
|
custodianNamesString
|
||||||
.append("• ")
|
.append("• ")
|
||||||
.append(custodianName)
|
.append(custodian.getName())
|
||||||
.append("\n");
|
.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView textViewThreshold = view.findViewById(R.id.textViewThreshold);
|
TextView textViewThreshold = view.findViewById(R.id.textViewThreshold);
|
||||||
textViewThreshold.setText(getString(R.string.existing_backup_explain,
|
textViewThreshold.setText(getString(R.string.existing_backup_explain,
|
||||||
args.getInt(THRESHOLD)));
|
backupMetadata.getThreshold()));
|
||||||
TextView textViewCustodians =
|
TextView textViewCustodians =
|
||||||
view.findViewById(R.id.textViewCustodians);
|
view.findViewById(R.id.textViewCustodians);
|
||||||
textViewCustodians.setText(custodianNamesString);
|
textViewCustodians.setText(custodianNamesString);
|
||||||
@@ -94,11 +80,9 @@ public class ExistingBackupFragment extends BaseFragment {
|
|||||||
// listener = (ShardsSentDismissedListener) context;
|
// listener = (ShardsSentDismissedListener) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUniqueTag() {
|
public String getUniqueTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,9 +46,7 @@ public class SocialBackupSetupActivity extends BriarActivity implements
|
|||||||
setContentView(R.layout.activity_distributed_backup);
|
setContentView(R.layout.activity_distributed_backup);
|
||||||
|
|
||||||
if (viewModel.haveExistingBackup()) {
|
if (viewModel.haveExistingBackup()) {
|
||||||
ExistingBackupFragment fragment =
|
showInitialFragment(new ExistingBackupFragment());
|
||||||
ExistingBackupFragment.newInstance();
|
|
||||||
showInitialFragment(fragment);
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (!viewModel.haveEnoughContacts()) {
|
if (!viewModel.haveEnoughContacts()) {
|
||||||
@@ -73,16 +71,13 @@ public class SocialBackupSetupActivity extends BriarActivity implements
|
|||||||
private void onStateChanged(SocialBackupSetupViewModel.State state) {
|
private void onStateChanged(SocialBackupSetupViewModel.State state) {
|
||||||
switch(state) {
|
switch(state) {
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
try {
|
finish();
|
||||||
viewModel.createBackup();
|
break;
|
||||||
ShardsSentFragment fragment = new ShardsSentFragment();
|
case FAILURE:
|
||||||
showNextFragment(fragment);
|
Toast.makeText(this,
|
||||||
} catch (DbException e) {
|
"There was an error when creating the backup",
|
||||||
Toast.makeText(this,
|
Toast.LENGTH_LONG).show();
|
||||||
"There was an error when creating the backup",
|
finish();
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case CHOOSING_CUSTODIANS:
|
case CHOOSING_CUSTODIANS:
|
||||||
CustodianSelectorFragment fragment =
|
CustodianSelectorFragment fragment =
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ public class SocialBackupSetupViewModel extends AndroidViewModel {
|
|||||||
EXPLAINING,
|
EXPLAINING,
|
||||||
CHOOSING_CUSTODIANS,
|
CHOOSING_CUSTODIANS,
|
||||||
GETTING_THRESHOLD,
|
GETTING_THRESHOLD,
|
||||||
SUCCESS
|
SUCCESS,
|
||||||
|
FAILURE
|
||||||
}
|
}
|
||||||
|
|
||||||
private final MutableLiveData<State> state =
|
private final MutableLiveData<State> state =
|
||||||
@@ -53,39 +54,44 @@ public class SocialBackupSetupViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
public boolean haveExistingBackup() {
|
public boolean haveExistingBackup() {
|
||||||
try {
|
try {
|
||||||
db.transaction(false, txn -> {
|
backupMetadata = db.transactionWithNullableResult(true,
|
||||||
backupMetadata =
|
socialBackupManager::getBackupMetadata);
|
||||||
socialBackupManager.getBackupMetadata(txn);
|
|
||||||
if (backupMetadata == null) throw new DbException();
|
|
||||||
});
|
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return (backupMetadata != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BackupMetadata getBackupMetadata() {
|
public BackupMetadata getBackupMetadata() {
|
||||||
return backupMetadata;
|
return backupMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean haveEnoughContacts() throws DbException {
|
public boolean haveEnoughContacts() throws DbException {
|
||||||
return (contactManager.getContacts().size() > 1);
|
return (contactManager.getContacts().size() > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCustodians(Collection<ContactId> contacts) {
|
public void setCustodians(Collection<ContactId> contacts) {
|
||||||
custodians = contacts;
|
custodians = contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createBackup() throws DbException {
|
public void createBackup() {
|
||||||
db.transaction(false, txn -> {
|
try {
|
||||||
socialBackupManager
|
db.transaction(false, txn -> {
|
||||||
.createBackup(txn, (List<ContactId>) custodians,
|
socialBackupManager
|
||||||
threshold);
|
.createBackup(txn, (List<ContactId>) custodians,
|
||||||
});
|
threshold);
|
||||||
|
});
|
||||||
|
} catch (DbException e) {
|
||||||
|
state.postValue(State.FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreshold(int threshold) {
|
public void setThreshold(int threshold) {
|
||||||
this.threshold = threshold;
|
this.threshold = threshold;
|
||||||
|
createBackup();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSuccessDismissed() {
|
||||||
state.postValue(State.SUCCESS);
|
state.postValue(State.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +100,7 @@ public class SocialBackupSetupViewModel extends AndroidViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onExplainerDismissed() {
|
public void onExplainerDismissed() {
|
||||||
state.postValue(State.CHOOSING_CUSTODIANS);
|
state.postValue(State.CHOOSING_CUSTODIANS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
public class ThresholdSelectorFragment extends BaseFragment {
|
public class ThresholdSelectorFragment extends BaseFragment {
|
||||||
@@ -125,12 +126,25 @@ public class ThresholdSelectorFragment extends BaseFragment {
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_threshold_defined:
|
case R.id.action_threshold_defined:
|
||||||
viewModel.setThreshold(threshold);
|
viewModel.setThreshold(threshold);
|
||||||
|
showSuccessDialog();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showSuccessDialog() {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(),
|
||||||
|
R.style.BriarDialogTheme);
|
||||||
|
builder.setTitle(R.string.backup_created);
|
||||||
|
builder.setMessage(R.string.backup_done_info);
|
||||||
|
builder.setPositiveButton(R.string.ok,
|
||||||
|
(dialog, which) -> viewModel.onSuccessDismissed());
|
||||||
|
builder.setIcon(R.drawable.ic_baseline_done_outline_24);
|
||||||
|
AlertDialog dialog = builder.create();
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
private String buildThresholdRepresentationString() {
|
private String buildThresholdRepresentationString() {
|
||||||
String thresholdRepresentationText = "";
|
String thresholdRepresentationText = "";
|
||||||
for (int i = 0; i < threshold; i++) {
|
for (int i = 0; i < threshold; i++) {
|
||||||
|
|||||||
@@ -667,12 +667,11 @@
|
|||||||
<string name="threshold_defined">Choose Threshold</string>
|
<string name="threshold_defined">Choose Threshold</string>
|
||||||
<string name="threshold_m_of_n">%d of %d contacts needed to recover your account</string>
|
<string name="threshold_m_of_n">%d of %d contacts needed to recover your account</string>
|
||||||
|
|
||||||
|
<string name="backup_created">Social Backup created</string>
|
||||||
<string name="backup_done_info">Backup pieces sent to trusted contacts</string>
|
<string name="backup_done_info">Backup pieces sent to trusted contacts</string>
|
||||||
|
|
||||||
<string name="backup_created">Backup created 1/6/2020</string>
|
|
||||||
|
|
||||||
<string name="social_backup_setup_explainer_title">Backup your Briar identity and contacts list using trusted contacts</string>
|
<string name="social_backup_setup_explainer_title">Backup your Briar identity and contacts list using trusted contacts</string>
|
||||||
<string name="social_backup_setup_explainer_long">You must choose a set of contacts to send backup pieces to.</string>
|
<string name="social_backup_setup_explainer_long">You must choose a set true contacts to send backup pieces to.</string>
|
||||||
<string name="social_backup_setup_explainer_button">Choose trusted contacts</string>
|
<string name="social_backup_setup_explainer_button">Choose trusted contacts</string>
|
||||||
|
|
||||||
<!-- recovery from the secret owner's POV -->
|
<!-- recovery from the secret owner's POV -->
|
||||||
|
|||||||
@@ -96,7 +96,7 @@
|
|||||||
app:iconSpaceReserved="false">
|
app:iconSpaceReserved="false">
|
||||||
|
|
||||||
<intent
|
<intent
|
||||||
android:targetClass="org.briarproject.briar.android.socialbackup.DistributedBackupActivity"
|
android:targetClass="org.briarproject.briar.android.socialbackup.SocialBackupSetupActivity"
|
||||||
android:targetPackage="@string/app_package" />
|
android:targetPackage="@string/app_package" />
|
||||||
|
|
||||||
</Preference>
|
</Preference>
|
||||||
|
|||||||
Reference in New Issue
Block a user