From 5a91c7e84a378c96ce5b3f022b10ed05f79c7f47 Mon Sep 17 00:00:00 2001 From: Martin d'Allens Date: Sun, 24 Jan 2021 23:43:57 +0100 Subject: [PATCH] Remove seconds from screen lock timeout input for coherence Configure the TimeDurationPickerDialog to hide seconds. Seconds were already ignored below 1min. This avoids the user expecting it to work. Feature regression: after this change, seconds above 1min will also be impossible to input (ex: 1m30s). But it makes little sense anyway to allow it: they are even less useful for longer durations. Another possibility to reach a point where eveything is coherent would have been to just remove the Math.max(..., 60) that ignored seconds. The duration will be displayed as "xx:xx:00" to make it clear that xx:xx represents minutes. Fixes #10788. --- .../AppProtectionPreferenceFragment.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/preferences/AppProtectionPreferenceFragment.java b/app/src/main/java/org/thoughtcrime/securesms/preferences/AppProtectionPreferenceFragment.java index e16981ee0..74edc83f5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/preferences/AppProtectionPreferenceFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/preferences/AppProtectionPreferenceFragment.java @@ -72,6 +72,7 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; import mobi.upod.timedurationpicker.TimeDurationPickerDialog; +import mobi.upod.timedurationpicker.TimeDurationPicker; public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment { @@ -186,11 +187,10 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment long timeoutSeconds = TextSecurePreferences.getScreenLockTimeout(getContext()); long hours = TimeUnit.SECONDS.toHours(timeoutSeconds); long minutes = TimeUnit.SECONDS.toMinutes(timeoutSeconds) - (TimeUnit.SECONDS.toHours(timeoutSeconds) * 60 ); - long seconds = TimeUnit.SECONDS.toSeconds(timeoutSeconds) - (TimeUnit.SECONDS.toMinutes(timeoutSeconds) * 60); findPreference(TextSecurePreferences.SCREEN_LOCK_TIMEOUT) .setSummary(timeoutSeconds <= 0 ? getString(R.string.AppProtectionPreferenceFragment_none) : - String.format(Locale.getDefault(), "%02d:%02d:%02d", hours, minutes, seconds)); + String.format(Locale.getDefault(), "%02d:%02d:00", hours, minutes)); } private void initializePhoneNumberPrivacyWhoCanSeeSummary() { @@ -255,15 +255,11 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment @Override public boolean onPreferenceClick(Preference preference) { new TimeDurationPickerDialog(getContext(), (view, duration) -> { - if (duration == 0) { - TextSecurePreferences.setScreenLockTimeout(getContext(), 0); - } else { - long timeoutSeconds = Math.max(TimeUnit.MILLISECONDS.toSeconds(duration), 60); - TextSecurePreferences.setScreenLockTimeout(getContext(), timeoutSeconds); - } + long timeoutSeconds = TimeUnit.MILLISECONDS.toSeconds(duration); + TextSecurePreferences.setScreenLockTimeout(getContext(), timeoutSeconds); initializeScreenLockTimeoutSummary(); - }, 0).show(); + }, 0, TimeDurationPicker.HH_MM).show(); return true; } @@ -399,7 +395,7 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment initializePassphraseTimeoutSummary(); - }, 0).show(); + }, 0, TimeDurationPicker.HH_MM).show(); return true; }