From 0b9e4915dc4a4e52d0a2de7a31c7b23bb47cdec9 Mon Sep 17 00:00:00 2001 From: ameba23 Date: Thu, 4 Mar 2021 08:52:52 +0100 Subject: [PATCH] set initial state of threshold representation --- .../ThresholdSelectorFragment.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) 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 7cd690fb2..6ec2b1e1b 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 @@ -30,6 +30,8 @@ public class ThresholdSelectorFragment extends BaseFragment { protected ThresholdDefinedListener listener; + // TODO this should be the actual number of custodians + private int numberOfCustodians = 5; private SeekBar seekBar; private TextView thresholdRepresentation; private TextView message; @@ -54,6 +56,7 @@ public class ThresholdSelectorFragment extends BaseFragment { seekBar.setOnSeekBarChangeListener(new SeekBarListener()); seekBar.setProgress(1); + thresholdRepresentation.setText(buildThresholdRepresentationString(3)); return view; } @@ -91,26 +94,31 @@ public class ThresholdSelectorFragment extends BaseFragment { } } + private String buildThresholdRepresentationString (int threshold) { + String thresholdRepresentationText = ""; + for (int i = 0; i < threshold; i++) { + thresholdRepresentationText += R.string.filled_bullet; + } + for (int i = 0; i < (numberOfCustodians - threshold); i++) { + thresholdRepresentationText += R.string.linear_bullet; + } + return thresholdRepresentationText; + } + private class SeekBarListener implements SeekBar.OnSeekBarChangeListener { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - int numCustodians = 5; // TODO this should be the actual number of custodians // progress can be 0, 1, 2 - translate allowed slider value to actual // threshold int threshold = progress + 2; - String thresholdRepresentationText = ""; - for (int i = 0; i < threshold; i++) { - thresholdRepresentationText += R.string.filled_bullet; - } - for (int i = 0; i < (numCustodians - threshold); i++) { - thresholdRepresentationText += R.string.linear_bullet; - } - thresholdRepresentation.setText(thresholdRepresentationText); + thresholdRepresentation.setText( + buildThresholdRepresentationString(threshold) + ); - int sanityLevel = SecretSharingWrapper.thresholdSanity(threshold, numCustodians); + int sanityLevel = SecretSharingWrapper.thresholdSanity(threshold, numberOfCustodians); int text = R.string.threshold_secure; if (sanityLevel < -1) text = R.string.threshold_low_insecure; if (sanityLevel > 1) text = R.string.threshold_high_insecure;