mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-23 21:09:00 +00:00
Make it possible to set a zero value for screen lock timeout
Fixes #7485
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package org.thoughtcrime.securesms.preferences;
|
||||
|
||||
import android.app.KeyguardManager;
|
||||
import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -13,9 +12,6 @@ import android.support.v7.preference.CheckBoxPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.codetroopers.betterpickers.hmspicker.HmsPickerBuilder;
|
||||
import com.codetroopers.betterpickers.hmspicker.HmsPickerDialogFragment;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.BlockedContactsActivity;
|
||||
@@ -34,6 +30,8 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import mobi.upod.timedurationpicker.TimeDurationPickerDialog;
|
||||
|
||||
public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment implements InjectableType {
|
||||
|
||||
private static final String PREFERENCE_CATEGORY_BLOCKED = "preference_category_blocked";
|
||||
@@ -132,32 +130,23 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private class ScreenLockTimeoutListener implements Preference.OnPreferenceClickListener, HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
|
||||
private class ScreenLockTimeoutListener implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
int[] attributes = {R.attr.app_protect_timeout_picker_color};
|
||||
TypedArray hmsStyle = getActivity().obtainStyledAttributes(attributes);
|
||||
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);
|
||||
}
|
||||
|
||||
new HmsPickerBuilder().setFragmentManager(getFragmentManager())
|
||||
.setStyleResId(hmsStyle.getResourceId(0, R.style.BetterPickersDialogFragment_Light))
|
||||
.addHmsPickerDialogHandler(this)
|
||||
.show();
|
||||
|
||||
hmsStyle.recycle();
|
||||
initializeScreenLockTimeoutSummary();
|
||||
}, 0).show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
|
||||
long timeoutSeconds = Math.max(TimeUnit.HOURS.toSeconds(hours) +
|
||||
TimeUnit.MINUTES.toSeconds(minutes) +
|
||||
TimeUnit.SECONDS.toSeconds(seconds), 60);
|
||||
|
||||
TextSecurePreferences.setScreenLockTimeout(getContext(), timeoutSeconds);
|
||||
initializeScreenLockTimeoutSummary();
|
||||
}
|
||||
}
|
||||
|
||||
private class AccountLockClickListener implements Preference.OnPreferenceClickListener {
|
||||
@@ -231,33 +220,21 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private class PassphraseIntervalClickListener implements Preference.OnPreferenceClickListener, HmsPickerDialogFragment.HmsPickerDialogHandlerV2 {
|
||||
private class PassphraseIntervalClickListener implements Preference.OnPreferenceClickListener {
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
int[] attributes = {R.attr.app_protect_timeout_picker_color};
|
||||
TypedArray hmsStyle = getActivity().obtainStyledAttributes(attributes);
|
||||
new TimeDurationPickerDialog(getContext(), (view, duration) -> {
|
||||
int timeoutMinutes = Math.max((int)TimeUnit.MILLISECONDS.toMinutes(duration), 1);
|
||||
|
||||
new HmsPickerBuilder().setFragmentManager(getFragmentManager())
|
||||
.setStyleResId(hmsStyle.getResourceId(0, R.style.BetterPickersDialogFragment_Light))
|
||||
.addHmsPickerDialogHandler(this)
|
||||
.show();
|
||||
TextSecurePreferences.setPassphraseTimeoutInterval(getActivity(), timeoutMinutes);
|
||||
|
||||
hmsStyle.recycle();
|
||||
initializePassphraseTimeoutSummary();
|
||||
|
||||
}, 0).show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogHmsSet(int reference, boolean isNegative, int hours, int minutes, int seconds) {
|
||||
int timeoutMinutes = Math.max((int)TimeUnit.HOURS.toMinutes(hours) +
|
||||
minutes +
|
||||
(int)TimeUnit.SECONDS.toMinutes(seconds), 1);
|
||||
|
||||
TextSecurePreferences.setPassphraseTimeoutInterval(getActivity(), timeoutMinutes);
|
||||
|
||||
initializePassphraseTimeoutSummary();
|
||||
}
|
||||
}
|
||||
|
||||
private class DisablePassphraseClickListener implements Preference.OnPreferenceChangeListener {
|
||||
|
Reference in New Issue
Block a user