use a string as threshold representation rather than svg

This commit is contained in:
ameba23
2021-03-04 08:38:02 +01:00
parent 681b151c8b
commit 6a7ceb4a68

View File

@@ -20,6 +20,7 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent; import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.contactselection.ContactSelectorListener; import org.briarproject.briar.android.contactselection.ContactSelectorListener;
import org.briarproject.briar.android.fragment.BaseFragment; import org.briarproject.briar.android.fragment.BaseFragment;
import org.magmacollective.darkcrystal.secretsharingwrapper.SecretSharingWrapper;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
@@ -30,7 +31,7 @@ public class ThresholdSelectorFragment extends BaseFragment {
protected ThresholdDefinedListener listener; protected ThresholdDefinedListener listener;
private SeekBar seekBar; private SeekBar seekBar;
private ImageView image; private TextView thresholdRepresentation;
private TextView message; private TextView message;
@Override @Override
@@ -46,7 +47,7 @@ public class ThresholdSelectorFragment extends BaseFragment {
container, false); container, false);
seekBar = view.findViewById(R.id.seekBar); seekBar = view.findViewById(R.id.seekBar);
image = view.findViewById(R.id.imageView); thresholdRepresentation = view.findViewById(R.id.textViewThresholdRepresentation);
message = view.findViewById(R.id.textViewMessage); message = view.findViewById(R.id.textViewMessage);
seekBar.setMax(2); seekBar.setMax(2);
@@ -95,19 +96,26 @@ public class ThresholdSelectorFragment extends BaseFragment {
@Override @Override
public void onProgressChanged(SeekBar seekBar, int progress, public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { boolean fromUser) {
// progress can be 0, 1, 2 int numCustodians = 5; // TODO this should be the actual number of custodians
int drawable = R.drawable.ic_pie_2_of_5; // progress can be 0, 1, 2 - translate allowed slider value to actual
switch (progress) { // threshold
case 1: int threshold = progress + 2;
drawable = R.drawable.ic_pie_3_of_5;
break; String thresholdRepresentationText = "";
case 2: for (int i = 0; i < threshold; i++) {
drawable = R.drawable.ic_pie_4_of_5; thresholdRepresentationText += R.string.filled_bullet;
break;
} }
int text = progress < 1 ? R.string.threshold_insecure : R.string.threshold_secure; for (int i = 0; i < (numCustodians - threshold); i++) {
image.setImageDrawable(getContext().getResources().getDrawable(drawable)); thresholdRepresentationText += R.string.linear_bullet;
}
thresholdRepresentation.setText(thresholdRepresentationText);
int sanityLevel = SecretSharingWrapper.thresholdSanity(threshold, numCustodians);
int text = R.string.threshold_secure;
if (sanityLevel < -1) text = R.string.threshold_low_insecure;
if (sanityLevel > 1) text = R.string.threshold_high_insecure;
message.setText(text); message.setText(text);
// TODO change colour of thresholdRepresentation to green/red based on sanityLevel
} }
@Override @Override