improve threshold choosing UI

This commit is contained in:
ameba23
2021-03-23 09:14:18 +01:00
parent b6d57a492b
commit 265d1da566
4 changed files with 26 additions and 19 deletions

View File

@@ -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)) {

View File

@@ -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);

View File

@@ -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));
}

View File

@@ -655,12 +655,15 @@
<string name="select_at_least_n_contacts">Please select at least %d contacts</string>
<string name="select_at_least_n_more_contacts">Please select at least %d more contacts</string>
<string name="threshold">The minimum number of trusted contacts needed to restore your account:</string>
<string name="threshold">Choose the minimum number of trusted contacts needed to restore your account</string>
<string name="threshold_disabled">Two trusted contacts will be needed to restore your account</string>
<string name="threshold_secure">Secure</string>
<string name="threshold_recommended">Secure - recommended threshold</string>
<string name="threshold_low_insecure">Insecure higher threshold recommended</string>
<string name="threshold_high_insecure">Danger of loss lower threshold recommended</string>
<string name="threshold_too_few_custodians">Danger of loss - more contacts recommended</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="backup_done_info">Backup pieces sent to trusted contacts</string>
<string name="backup_done_dismiss">Got it</string>
@@ -691,7 +694,7 @@
<string name="title_distributed_backup">Social Backup</string>
<string name="title_select_custodians">Select Trusted Contacts</string>
<string name="title_define_threshold">Choose Threshold</string>
<string name="title_define_threshold">Threshold</string>
<string name="title_recovery_mode">Recovery Mode</string>
<string name="title_help_recover">Help recover account</string>