2019-02-07 22:39:33 +01:00
|
|
|
package com.beemdevelopment.aegis;
|
2018-05-11 20:08:51 +02:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
2019-06-22 09:58:35 +02:00
|
|
|
import android.content.res.Resources;
|
2020-01-04 22:06:59 +01:00
|
|
|
import android.net.Uri;
|
2019-06-22 09:58:35 +02:00
|
|
|
import android.os.Build;
|
2018-05-11 20:08:51 +02:00
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
2020-01-19 13:53:08 +01:00
|
|
|
import java.util.Date;
|
2019-06-22 09:58:35 +02:00
|
|
|
import java.util.Locale;
|
2020-01-19 13:53:08 +01:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2019-06-22 09:58:35 +02:00
|
|
|
|
2018-05-11 20:08:51 +02:00
|
|
|
public class Preferences {
|
2020-08-12 21:33:25 +02:00
|
|
|
public static final int AUTO_LOCK_OFF = 1 << 0;
|
|
|
|
public static final int AUTO_LOCK_ON_BACK_BUTTON = 1 << 1;
|
|
|
|
public static final int AUTO_LOCK_ON_MINIMIZE = 1 << 2;
|
|
|
|
public static final int AUTO_LOCK_ON_DEVICE_LOCK = 1 << 3;
|
|
|
|
|
|
|
|
public static final int[] AUTO_LOCK_SETTINGS = {
|
|
|
|
AUTO_LOCK_ON_BACK_BUTTON,
|
|
|
|
AUTO_LOCK_ON_MINIMIZE,
|
|
|
|
AUTO_LOCK_ON_DEVICE_LOCK
|
|
|
|
};
|
|
|
|
|
2018-05-11 20:08:51 +02:00
|
|
|
private SharedPreferences _prefs;
|
|
|
|
|
|
|
|
public Preferences(Context context) {
|
|
|
|
_prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
2020-01-19 13:53:08 +01:00
|
|
|
|
|
|
|
if (getPasswordReminderTimestamp().getTime() == 0) {
|
|
|
|
resetPasswordReminderTimestamp();
|
|
|
|
}
|
2018-05-11 20:08:51 +02:00
|
|
|
}
|
|
|
|
|
2019-03-25 21:32:29 +01:00
|
|
|
public boolean isTapToRevealEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_tap_to_reveal", false);
|
|
|
|
}
|
|
|
|
|
2019-09-07 22:26:34 +02:00
|
|
|
public boolean isEntryHighlightEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_highlight_entry", false);
|
|
|
|
}
|
2019-09-11 20:51:02 +02:00
|
|
|
|
2020-08-16 22:45:02 +02:00
|
|
|
public boolean isPanicTriggerEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_panic_trigger", false);
|
|
|
|
}
|
|
|
|
|
2018-05-11 20:08:51 +02:00
|
|
|
public boolean isSecureScreenEnabled() {
|
2019-06-19 14:19:49 +02:00
|
|
|
// screen security should be enabled by default, but not for debug builds
|
|
|
|
return _prefs.getBoolean("pref_secure_screen", !BuildConfig.DEBUG);
|
2018-05-11 20:08:51 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 13:53:08 +01:00
|
|
|
public boolean isPasswordReminderEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_password_reminder", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPasswordReminderNeeded() {
|
|
|
|
long diff = new Date().getTime() - getPasswordReminderTimestamp().getTime();
|
|
|
|
long days = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
|
2020-05-12 22:23:47 +02:00
|
|
|
return isPasswordReminderEnabled() && days >= 30;
|
2020-01-19 13:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Date getPasswordReminderTimestamp() {
|
|
|
|
return new Date(_prefs.getLong("pref_password_reminder_counter", 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetPasswordReminderTimestamp() {
|
|
|
|
_prefs.edit().putLong("pref_password_reminder_counter", new Date().getTime()).apply();
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:10:03 +02:00
|
|
|
public boolean isAccountNameVisible() {
|
2019-09-15 21:04:36 +02:00
|
|
|
return _prefs.getBoolean("pref_account_name", true);
|
2018-05-11 20:08:51 +02:00
|
|
|
}
|
|
|
|
|
2020-04-23 23:19:38 +02:00
|
|
|
public int getCodeGroupSize() {
|
|
|
|
if (_prefs.getBoolean("pref_code_group_size", false)) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 20:08:51 +02:00
|
|
|
public boolean isIntroDone() {
|
|
|
|
return _prefs.getBoolean("pref_intro", false);
|
|
|
|
}
|
|
|
|
|
2020-08-12 21:33:25 +02:00
|
|
|
private int getAutoLockMask() {
|
|
|
|
final int def = AUTO_LOCK_ON_BACK_BUTTON | AUTO_LOCK_ON_DEVICE_LOCK;
|
|
|
|
if (!_prefs.contains("pref_auto_lock_mask")) {
|
|
|
|
return _prefs.getBoolean("pref_auto_lock", true) ? def : AUTO_LOCK_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _prefs.getInt("pref_auto_lock_mask", def);
|
|
|
|
}
|
|
|
|
|
2019-04-07 18:18:50 +02:00
|
|
|
public boolean isAutoLockEnabled() {
|
2020-08-12 21:33:25 +02:00
|
|
|
return getAutoLockMask() != AUTO_LOCK_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAutoLockTypeEnabled(int autoLockType) {
|
|
|
|
return (getAutoLockMask() & autoLockType) == autoLockType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAutoLockMask(int autoLock) {
|
|
|
|
_prefs.edit().putInt("pref_auto_lock_mask", autoLock).apply();
|
2019-04-07 18:18:50 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 20:08:51 +02:00
|
|
|
public void setIntroDone(boolean done) {
|
|
|
|
_prefs.edit().putBoolean("pref_intro", done).apply();
|
|
|
|
}
|
|
|
|
|
2019-03-26 00:06:39 +01:00
|
|
|
public void setTapToRevealTime(int number) {
|
|
|
|
_prefs.edit().putInt("pref_tap_to_reveal_time", number).apply();
|
|
|
|
}
|
|
|
|
|
2019-03-31 22:34:25 +02:00
|
|
|
public void setCurrentSortCategory(SortCategory category) {
|
|
|
|
_prefs.edit().putInt("pref_current_sort_category", category.ordinal()).apply();
|
|
|
|
}
|
|
|
|
|
2019-05-15 21:29:45 +02:00
|
|
|
public SortCategory getCurrentSortCategory() {
|
|
|
|
return SortCategory.fromInteger(_prefs.getInt("pref_current_sort_category", 0));
|
2019-03-31 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
2019-03-26 00:06:39 +01:00
|
|
|
public int getTapToRevealTime() {
|
|
|
|
return _prefs.getInt("pref_tap_to_reveal_time", 30);
|
|
|
|
}
|
|
|
|
|
2019-05-15 21:29:45 +02:00
|
|
|
public Theme getCurrentTheme() {
|
2020-04-20 15:29:41 +02:00
|
|
|
return Theme.fromInteger(_prefs.getInt("pref_current_theme", Theme.SYSTEM.ordinal()));
|
2019-03-28 00:54:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setCurrentTheme(Theme theme) {
|
|
|
|
_prefs.edit().putInt("pref_current_theme", theme.ordinal()).apply();
|
|
|
|
}
|
|
|
|
|
2019-05-15 21:29:45 +02:00
|
|
|
public ViewMode getCurrentViewMode() {
|
|
|
|
return ViewMode.fromInteger(_prefs.getInt("pref_current_view_mode", 0));
|
2019-04-01 01:21:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setCurrentViewMode(ViewMode viewMode) {
|
|
|
|
_prefs.edit().putInt("pref_current_view_mode", viewMode.ordinal()).apply();
|
|
|
|
}
|
|
|
|
|
2018-05-11 20:08:51 +02:00
|
|
|
public int getTimeout() {
|
|
|
|
return _prefs.getInt("pref_timeout", -1);
|
|
|
|
}
|
2019-06-22 09:58:35 +02:00
|
|
|
|
|
|
|
public Locale getLocale() {
|
|
|
|
String lang = _prefs.getString("pref_lang", "system");
|
|
|
|
|
|
|
|
if (lang.equals("system")) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
return Resources.getSystem().getConfiguration().getLocales().get(0);
|
|
|
|
} else {
|
|
|
|
return Resources.getSystem().getConfiguration().locale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-05 12:00:08 +02:00
|
|
|
String[] parts = lang.split("_");
|
|
|
|
if (parts.length == 1) {
|
|
|
|
return new Locale(parts[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Locale(parts[0], parts[1]);
|
2019-06-22 09:58:35 +02:00
|
|
|
}
|
2020-01-04 22:06:59 +01:00
|
|
|
|
|
|
|
public boolean isBackupsEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_backups", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsBackupsEnabled(boolean enabled) {
|
|
|
|
_prefs.edit().putBoolean("pref_backups", enabled).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Uri getBackupsLocation() {
|
|
|
|
String str = _prefs.getString("pref_backups_location", null);
|
|
|
|
if (str != null) {
|
|
|
|
return Uri.parse(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBackupsLocation(Uri location) {
|
|
|
|
_prefs.edit().putString("pref_backups_location", location == null ? null : location.toString()).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getBackupsVersionCount() {
|
|
|
|
return _prefs.getInt("pref_backups_versions", 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBackupsVersionCount(int versions) {
|
|
|
|
_prefs.edit().putInt("pref_backups_versions", versions).apply();
|
|
|
|
}
|
2020-05-03 16:57:51 +02:00
|
|
|
|
2020-06-13 12:45:02 +02:00
|
|
|
public void setBackupsError(Exception e) {
|
|
|
|
_prefs.edit().putString("pref_backups_error", e == null ? null : e.toString()).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getBackupsError() {
|
|
|
|
return _prefs.getString("pref_backups_error", null);
|
|
|
|
}
|
|
|
|
|
2020-07-05 19:27:44 +02:00
|
|
|
public boolean isPinKeyboardEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_pin_keyboard", false);
|
|
|
|
}
|
|
|
|
|
2020-05-03 16:57:51 +02:00
|
|
|
public boolean isTimeSyncWarningEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_warn_time_sync", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsTimeSyncWarningEnabled(boolean enabled) {
|
|
|
|
_prefs.edit().putBoolean("pref_warn_time_sync", enabled).apply();
|
|
|
|
}
|
2020-05-25 15:49:37 +02:00
|
|
|
|
|
|
|
public boolean isCopyOnTapEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_copy_on_tap", false);
|
|
|
|
}
|
2018-05-11 20:08:51 +02:00
|
|
|
}
|