diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt index 7ff4bad91..49125cc18 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt @@ -208,10 +208,10 @@ object Settings : DefaultPreferences() { if ("CN" == Locale.getDefault().country) { // Enable domain fronting if the country is CN if (!sSettingsPre.contains(KEY_BUILT_IN_HOSTS)) { - putBuiltInHosts(true) + builtInHosts = true } if (!sSettingsPre.contains(KEY_DOMAIN_FRONTING)) { - putDF(true) + dF = true } // Enable show tag translations if the country is CN if (!sSettingsPre.contains(KEY_SHOW_TAG_TRANSLATIONS)) { @@ -556,58 +556,15 @@ object Settings : DefaultPreferences() { get() = getInt(KEY_SECURITY_DELAY, 0) val readCacheSize: Int get() = getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE) - val builtInHosts: Boolean - get() = getBoolean(KEY_BUILT_IN_HOSTS, DEFAULT_BUILT_IN_HOSTS) - private fun putBuiltInHosts(value: Boolean) { - putBoolean(KEY_BUILT_IN_HOSTS, value) - } - - val dF: Boolean - get() = getBoolean(KEY_DOMAIN_FRONTING, DEFAULT_FRONTING) - - private fun putDF(value: Boolean) { - putBoolean(KEY_DOMAIN_FRONTING, value) - } - - val dohUrl: String - get() = getString(KEY_DOH_URL, "")!! - - fun putDohUrl(url: String) = putString(KEY_DOH_URL, url) - - val bypassVpn: Boolean - get() = getBoolean(KEY_BYPASS_VPN, DEFAULT_BYPASS_VPN) - - @JvmStatic - val proxyType: Int - get() = getInt(KEY_PROXY_TYPE, DEFAULT_PROXY_TYPE) - - fun putProxyType(value: Int) { - putInt(KEY_PROXY_TYPE, value) - } - - @JvmStatic - val proxyIp: String? - get() = getString(KEY_PROXY_IP, DEFAULT_PROXY_IP) - - fun putProxyIp(value: String?) { - putString(KEY_PROXY_IP, value) - } - - @JvmStatic - val proxyPort: Int - get() = getInt(KEY_PROXY_PORT, DEFAULT_PROXY_PORT) - - fun putProxyPort(value: Int) { - putInt(KEY_PROXY_PORT, value) - } - - val clipboardTextHashCode: Int - get() = getInt(KEY_CLIPBOARD_TEXT_HASH_CODE, DEFAULT_CLIPBOARD_TEXT_HASH_CODE) - - fun putClipboardTextHashCode(value: Int) { - putInt(KEY_CLIPBOARD_TEXT_HASH_CODE, value) - } + var builtInHosts by boolPref(KEY_BUILT_IN_HOSTS, DEFAULT_BUILT_IN_HOSTS) + var dF by boolPref(KEY_DOMAIN_FRONTING, DEFAULT_FRONTING) + var dohUrl by stringPref(KEY_DOH_URL, "") + val bypassVpn by boolPref(KEY_BYPASS_VPN, DEFAULT_BYPASS_VPN) + var proxyType by intPref(KEY_PROXY_TYPE, DEFAULT_PROXY_TYPE) + var proxyIp by stringOrNullPref(KEY_PROXY_IP, DEFAULT_PROXY_IP) + var proxyPort by intPref(KEY_PROXY_PORT, DEFAULT_PROXY_PORT) + var clipboardTextHashCode by intPref(KEY_CLIPBOARD_TEXT_HASH_CODE, DEFAULT_CLIPBOARD_TEXT_HASH_CODE) val archivePasswds: Set? get() = getStringSet(KEY_ARCHIVE_PASSWDS) @@ -627,6 +584,5 @@ object Settings : DefaultPreferences() { return size } - val preloadThumbAggressively: Boolean - get() = getBoolean(KEY_PRELOAD_THUMB_AGGRESIVELY, DEFAULT_PRELOAD_THUMB_AGGRESIVELY) + val preloadThumbAggressively by boolPref(KEY_PRELOAD_THUMB_AGGRESIVELY, DEFAULT_PRELOAD_THUMB_AGGRESIVELY) } diff --git a/app/src/main/java/com/hippo/ehviewer/preference/DohPreference.kt b/app/src/main/java/com/hippo/ehviewer/preference/DohPreference.kt index 296544bc8..4644f1ee8 100644 --- a/app/src/main/java/com/hippo/ehviewer/preference/DohPreference.kt +++ b/app/src/main/java/com/hippo/ehviewer/preference/DohPreference.kt @@ -30,7 +30,7 @@ class DohPreference @JvmOverloads constructor( }.onFailure { builder.setError("Invalid URL!") }.onSuccess { - Settings.putDohUrl(text) + Settings.dohUrl = text dialog.dismiss() } } diff --git a/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt b/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt index 6c6987a8a..69d41a33a 100644 --- a/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt +++ b/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt @@ -161,9 +161,9 @@ class ProxyPreference @JvmOverloads constructor( } } mPortInputLayout!!.error = null - Settings.putProxyType(type) - Settings.putProxyIp(ip) - Settings.putProxyPort(port) + Settings.proxyType = type + Settings.proxyIp = ip + Settings.proxyPort = port updateSummary(type, ip, port) EhApplication.ehProxySelector.updateProxy() dialog.dismiss() diff --git a/app/src/main/java/com/hippo/ehviewer/ui/GalleryInfoBottomSheet.kt b/app/src/main/java/com/hippo/ehviewer/ui/GalleryInfoBottomSheet.kt index e2269fe39..5c655ad13 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/GalleryInfoBottomSheet.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/GalleryInfoBottomSheet.kt @@ -131,7 +131,7 @@ fun GalleryInfoBottomSheet( context tellClipboardWithToast data[index] if (index == INDEX_URL) { // Save it to avoid detect the gallery - Settings.putClipboardTextHashCode(data[index].hashCode()) + Settings.clipboardTextHashCode = data[index].hashCode() } } }.fillMaxWidth(), diff --git a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt index 743d62c73..7e5573024 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt @@ -388,7 +388,7 @@ class MainActivity : EhActivity() { } } } - Settings.putClipboardTextHashCode(hashCode) + Settings.clipboardTextHashCode = hashCode } @SuppressLint("RtlHardcoded")