From ae7a553aa333d1d937feac99afa97cdf9f8be9fe Mon Sep 17 00:00:00 2001 From: ameba23 Date: Fri, 11 Feb 2022 12:02:39 +0100 Subject: [PATCH] Basic strength meter when choosing threshold --- .../ThresholdSelectorFragment.java | 20 +++++++++++++++---- .../res/layout/fragment_select_threshold.xml | 15 ++++++++++++-- 2 files changed, 29 insertions(+), 6 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 716a448e9..60cba332a 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 @@ -18,6 +18,7 @@ import android.widget.TextView; import org.briarproject.briar.R; import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.fragment.BaseFragment; +import org.briarproject.briar.android.login.StrengthMeter; import org.magmacollective.darkcrystal.secretsharingwrapper.SecretSharingWrapper; import java.util.Arrays; @@ -41,6 +42,7 @@ public class ThresholdSelectorFragment extends BaseFragment { private TextView thresholdRepresentation; private TextView message; private TextView mOfn; + private StrengthMeter strengthMeter; @Inject ViewModelProvider.Factory viewModelFactory; @@ -81,7 +83,8 @@ public class ThresholdSelectorFragment extends BaseFragment { thresholdRepresentation = view.findViewById(R.id.textViewThresholdRepresentation); message = view.findViewById(R.id.textViewMessage); - mOfn = view.findViewById(R.id.textViewmOfn); + mOfn = view.findViewById(R.id.text_view_m_of_n); + strengthMeter = view.findViewById(R.id.strength_meter); if (numberOfCustodians > 3) { seekBar.setMax(numberOfCustodians -3); @@ -184,10 +187,19 @@ public class ThresholdSelectorFragment extends BaseFragment { int sanityLevel = SecretSharingWrapper .thresholdSanity(threshold, numberOfCustodians); int text = R.string.threshold_secure; - if (threshold == recommendedThreshold) + float strength = 1; + 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; + } + if (sanityLevel < -1) { + strength = 0.75f; + text = R.string.threshold_low_insecure; + } + if (sanityLevel > 0) { + strength = 0.75f; + text = R.string.threshold_high_insecure; + } + strengthMeter.setStrength(strength); message.setText(text); // TODO change colour of thresholdRepresentation to green/red based on sanityLevel } diff --git a/briar-android/src/main/res/layout/fragment_select_threshold.xml b/briar-android/src/main/res/layout/fragment_select_threshold.xml index fe74f5cd1..98ae96397 100644 --- a/briar-android/src/main/res/layout/fragment_select_threshold.xml +++ b/briar-android/src/main/res/layout/fragment_select_threshold.xml @@ -45,7 +45,7 @@ app:layout_constraintTop_toBottomOf="@+id/seekBar" /> + + + app:layout_constraintTop_toBottomOf="@+id/strength_meter" />