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;
|
|
|
|
|
2021-05-26 10:46:49 +02:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
2022-02-17 14:25:32 +01:00
|
|
|
import org.json.JSONObject;
|
2021-05-26 10:46:49 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2021-05-16 13:04:58 +02:00
|
|
|
import java.util.Collections;
|
2020-01-19 13:53:08 +01:00
|
|
|
import java.util.Date;
|
2021-06-02 18:02:38 +02:00
|
|
|
import java.util.HashMap;
|
2022-02-17 14:25:32 +01:00
|
|
|
import java.util.List;
|
2019-06-22 09:58:35 +02:00
|
|
|
import java.util.Locale;
|
2021-06-02 18:02:38 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
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
|
|
|
|
2021-07-28 11:45:32 +02:00
|
|
|
public boolean isPauseFocusedEnabled() {
|
|
|
|
boolean dependenciesEnabled = isTapToRevealEnabled() || isEntryHighlightEnabled();
|
|
|
|
if (!dependenciesEnabled) return false;
|
|
|
|
return _prefs.getBoolean("pref_pause_entry", false);
|
|
|
|
}
|
|
|
|
|
2020-08-16 22:45:02 +02:00
|
|
|
public boolean isPanicTriggerEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_panic_trigger", false);
|
|
|
|
}
|
|
|
|
|
2022-02-17 14:25:32 +01:00
|
|
|
public void setIsPanicTriggerEnabled(boolean enabled) {
|
|
|
|
_prefs.edit().putBoolean("pref_panic_trigger", enabled).apply();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-06-02 18:02:38 +02:00
|
|
|
public Integer getUsageCount(UUID uuid) {
|
|
|
|
Integer usageCount = getUsageCounts().get(uuid);
|
|
|
|
|
|
|
|
return usageCount != null ? usageCount : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetUsageCount(UUID uuid) {
|
|
|
|
Map<UUID, Integer> usageCounts = getUsageCounts();
|
|
|
|
usageCounts.put(uuid, 0);
|
|
|
|
|
|
|
|
setUsageCount(usageCounts);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearUsageCount() {
|
|
|
|
_prefs.edit().remove("pref_usage_count").apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<UUID, Integer> getUsageCounts() {
|
|
|
|
Map<UUID, Integer> usageCounts = new HashMap<>();
|
|
|
|
String usageCount = _prefs.getString("pref_usage_count", "");
|
|
|
|
try {
|
|
|
|
JSONArray arr = new JSONArray(usageCount);
|
|
|
|
for(int i = 0; i < arr.length(); i++) {
|
|
|
|
JSONObject json = arr.getJSONObject(i);
|
|
|
|
usageCounts.put(UUID.fromString(json.getString("uuid")), json.getInt("count"));
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return usageCounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUsageCount(Map<UUID, Integer> usageCounts) {
|
|
|
|
JSONArray usageCountJson = new JSONArray();
|
|
|
|
for (Map.Entry<UUID, Integer> entry : usageCounts.entrySet()) {
|
|
|
|
JSONObject entryJson = new JSONObject();
|
|
|
|
try {
|
|
|
|
entryJson.put("uuid", entry.getKey());
|
|
|
|
entryJson.put("count", entry.getValue());
|
|
|
|
usageCountJson.put(entryJson);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_prefs.edit().putString("pref_usage_count", usageCountJson.toString()).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
|
|
|
|
2021-01-03 18:19:16 +01:00
|
|
|
public boolean isAndroidBackupsEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_android_backups", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsAndroidBackupsEnabled(boolean enabled) {
|
|
|
|
_prefs.edit().putBoolean("pref_android_backups", enabled).apply();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-11-04 15:41:17 +05:30
|
|
|
public boolean getFocusSearchEnabled() {
|
|
|
|
return _prefs.getBoolean("pref_focus_search", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setFocusSearch(boolean enabled) {
|
|
|
|
_prefs.edit().putBoolean("pref_focus_search", enabled).apply();
|
|
|
|
}
|
|
|
|
|
2020-01-04 22:06:59 +01:00
|
|
|
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);
|
|
|
|
}
|
2021-05-16 13:04:58 +02:00
|
|
|
|
|
|
|
public void setGroupFilter(List<String> groupFilter) {
|
2021-05-26 10:46:49 +02:00
|
|
|
JSONArray json = new JSONArray(groupFilter);
|
|
|
|
_prefs.edit().putString("pref_group_filter", json.toString()).apply();
|
2021-05-16 13:04:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getGroupFilter() {
|
2021-05-26 10:46:49 +02:00
|
|
|
String raw = _prefs.getString("pref_group_filter", null);
|
|
|
|
if (raw == null || raw.isEmpty()) {
|
2021-05-16 13:04:58 +02:00
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
|
2021-05-26 10:46:49 +02:00
|
|
|
try {
|
|
|
|
JSONArray json = new JSONArray(raw);
|
|
|
|
List<String> filter = new ArrayList<>();
|
|
|
|
for (int i = 0; i < json.length(); i++) {
|
|
|
|
filter.add(json.getString(i));
|
|
|
|
}
|
|
|
|
return filter;
|
|
|
|
} catch (JSONException e) {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
2021-05-16 13:04:58 +02:00
|
|
|
}
|
2018-05-11 20:08:51 +02:00
|
|
|
}
|