From 265d1da5669f3f87976af17537cbb90216f9f4c5 Mon Sep 17 00:00:00 2001 From: ameba23 Date: Tue, 23 Mar 2021 09:14:18 +0100 Subject: [PATCH] improve threshold choosing UI --- .../CustodianHelpRecoverActivity.java | 3 +- .../DistributedBackupActivity.java | 5 ---- .../ThresholdSelectorFragment.java | 30 ++++++++++++------- briar-android/src/main/res/values/strings.xml | 7 +++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/CustodianHelpRecoverActivity.java b/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/CustodianHelpRecoverActivity.java index 9c48693c6..571652442 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/CustodianHelpRecoverActivity.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/CustodianHelpRecoverActivity.java @@ -11,7 +11,6 @@ import org.briarproject.briar.R; import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.activity.BriarActivity; import org.briarproject.briar.android.fragment.BaseFragment; -import org.briarproject.briar.api.socialbackup.BackupMetadata; import org.briarproject.briar.api.socialbackup.SocialBackupManager; import javax.inject.Inject; @@ -41,7 +40,7 @@ public class CustodianHelpRecoverActivity extends BriarActivity implements if (id == -1) throw new IllegalStateException("No ContactId"); ContactId contactId = new ContactId(id); - // check if we have a shard for this secret owner + // check if we have a shard for this secret owner try { db.transaction(false, txn -> { if (!socialBackupManager.amCustodian(txn, contactId)) { diff --git a/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/DistributedBackupActivity.java b/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/DistributedBackupActivity.java index 27f0e1b51..4f8b29ea8 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/DistributedBackupActivity.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/DistributedBackupActivity.java @@ -64,11 +64,6 @@ public class DistributedBackupActivity extends BriarActivity implements String.format("selected %d contacts", contacts.size()), Toast.LENGTH_SHORT).show(); custodians = contacts; - if (contacts.size() < 4) { - // For 2 or 3 contacts, there is no choice of threshold - thresholdDefined(2); - return; - } ThresholdSelectorFragment fragment = ThresholdSelectorFragment.newInstance(contacts.size()); showNextFragment(fragment); diff --git a/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/ThresholdSelectorFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/ThresholdSelectorFragment.java index 74d8f0569..c20a64dc4 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/ThresholdSelectorFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/socialbackup/ThresholdSelectorFragment.java @@ -27,7 +27,6 @@ public class ThresholdSelectorFragment extends BaseFragment { protected ThresholdDefinedListener listener; - // TODO this should be the actual number of custodians private int numberOfCustodians; private int threshold; private int recommendedThreshold; @@ -59,20 +58,31 @@ public class ThresholdSelectorFragment extends BaseFragment { container, false); Bundle args = requireArguments(); numberOfCustodians = args.getInt(NUMBER_CUSTODIANS); - seekBar = view.findViewById(R.id.seekBar); thresholdRepresentation = view.findViewById(R.id.textViewThresholdRepresentation); message = view.findViewById(R.id.textViewMessage); mOfn = view.findViewById(R.id.textViewmOfn); - int max = numberOfCustodians - 3; - seekBar.setMax(max); - seekBar.setOnSeekBarChangeListener(new SeekBarListener()); - recommendedThreshold = - SecretSharingWrapper.defaultThreshold(numberOfCustodians); - threshold = recommendedThreshold; - seekBar.setProgress(threshold - 2); + if (numberOfCustodians == 2) { + message.setText(R.string.threshold_too_few_custodians); + } + if (numberOfCustodians > 3) { + seekBar.setMax(numberOfCustodians -3); + seekBar.setProgress(threshold - 2); + seekBar.setOnSeekBarChangeListener(new SeekBarListener()); + recommendedThreshold = + SecretSharingWrapper.defaultThreshold(numberOfCustodians); + threshold = recommendedThreshold; + + } else { + seekBar.setEnabled(false); + threshold = 2; + seekBar.setMax(numberOfCustodians); + seekBar.setProgress(threshold); + TextView t = view.findViewById(R.id.title_threshold); + t.setText(R.string.threshold_disabled); + } thresholdRepresentation.setText(buildThresholdRepresentationString()); setmOfnText(); return view; @@ -81,7 +91,7 @@ public class ThresholdSelectorFragment extends BaseFragment { private void setmOfnText() { mOfn.setText(String.format( - "%d of %d contacts needed to recover your account", threshold, + getString(R.string.threshold_m_of_n), threshold, numberOfCustodians)); } diff --git a/briar-android/src/main/res/values/strings.xml b/briar-android/src/main/res/values/strings.xml index 1c7f3f2b6..bd4caa517 100644 --- a/briar-android/src/main/res/values/strings.xml +++ b/briar-android/src/main/res/values/strings.xml @@ -655,12 +655,15 @@ Please select at least %d contacts Please select at least %d more contacts - The minimum number of trusted contacts needed to restore your account: + Choose the minimum number of trusted contacts needed to restore your account + Two trusted contacts will be needed to restore your account Secure Secure - recommended threshold Insecure – higher threshold recommended Danger of loss – lower threshold recommended + Danger of loss - more contacts recommended Choose Threshold + %d of %d contacts needed to recover your account Backup pieces sent to trusted contacts Got it @@ -691,7 +694,7 @@ Social Backup Select Trusted Contacts - Choose Threshold + Threshold Recovery Mode Help recover account