mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
improve thresholdSelectorFragment
This commit is contained in:
@@ -34,9 +34,11 @@ public class ThresholdSelectorFragment extends BaseFragment {
|
||||
// TODO this should be the actual number of custodians
|
||||
private int numberOfCustodians;
|
||||
private int threshold;
|
||||
private int recommendedThreshold;
|
||||
private SeekBar seekBar;
|
||||
private TextView thresholdRepresentation;
|
||||
private TextView message;
|
||||
private TextView mOfn;
|
||||
|
||||
public static ThresholdSelectorFragment newInstance(int numberCustodians) {
|
||||
Bundle bundle = new Bundle();
|
||||
@@ -46,10 +48,6 @@ public class ThresholdSelectorFragment extends BaseFragment {
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private void setNumberCustodians(int numberCustodians) {
|
||||
numberOfCustodians = numberCustodians;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -67,17 +65,24 @@ public class ThresholdSelectorFragment extends BaseFragment {
|
||||
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());
|
||||
threshold = SecretSharingWrapper.defaultThreshold(numberOfCustodians);
|
||||
recommendedThreshold = SecretSharingWrapper.defaultThreshold(numberOfCustodians);
|
||||
threshold = recommendedThreshold;
|
||||
seekBar.setProgress(threshold - 2);
|
||||
|
||||
thresholdRepresentation.setText(buildThresholdRepresentationString());
|
||||
setmOfnText();
|
||||
return view;
|
||||
// return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
private void setmOfnText() {
|
||||
mOfn.setText(String.format("%d of %d contacts needed to recover your account", threshold, numberOfCustodians));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -116,11 +121,9 @@ public class ThresholdSelectorFragment extends BaseFragment {
|
||||
String thresholdRepresentationText = "";
|
||||
for (int i = 0; i < threshold; i++) {
|
||||
thresholdRepresentationText += getString(R.string.filled_bullet);
|
||||
// thresholdRepresentationText += "1 ";
|
||||
}
|
||||
for (int i = 0; i < (numberOfCustodians - threshold); i++) {
|
||||
thresholdRepresentationText += getString(R.string.linear_bullet);
|
||||
// thresholdRepresentationText += "0 ";
|
||||
}
|
||||
return thresholdRepresentationText;
|
||||
}
|
||||
@@ -135,11 +138,12 @@ public class ThresholdSelectorFragment extends BaseFragment {
|
||||
thresholdRepresentation.setText(
|
||||
buildThresholdRepresentationString()
|
||||
);
|
||||
setmOfnText();
|
||||
|
||||
int sanityLevel = SecretSharingWrapper.thresholdSanity(threshold, numberOfCustodians);
|
||||
int text = R.string.threshold_secure;
|
||||
// TODO use 1 / -1 instead of 0
|
||||
if (sanityLevel < 0) text = R.string.threshold_low_insecure;
|
||||
if (threshold == recommendedThreshold) text = R.string.threshold_recommended;
|
||||
if (sanityLevel < -1) text = R.string.threshold_low_insecure;
|
||||
if (sanityLevel > 0) text = R.string.threshold_high_insecure;
|
||||
message.setText(text);
|
||||
// TODO change colour of thresholdRepresentation to green/red based on sanityLevel
|
||||
|
||||
@@ -39,11 +39,22 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="placeholder"
|
||||
android:textSize="16dp"
|
||||
android:textSize="64dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/seekBar" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewmOfn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="24dp"
|
||||
android:text="m of n contacts needed to recover your account"
|
||||
android:textSize="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewThresholdRepresentation" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewMessage"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -53,6 +64,6 @@
|
||||
android:textSize="16dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewThresholdRepresentation" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewmOfn" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
@@ -657,9 +657,9 @@
|
||||
|
||||
<string name="threshold">The minimum number of trusted contacts 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>
|
||||
<!-- the next one does only appear when long-pressing the submit arrow in the app bar-->
|
||||
<string name="threshold_defined">Choose Threshold</string>
|
||||
|
||||
<string name="backup_done_info">Backup pieces sent to trusted contacts</string>
|
||||
|
||||
Reference in New Issue
Block a user