diff --git a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt index b4342065a..3a3c1ce93 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt +++ b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt @@ -75,7 +75,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor val handler = Thread.getDefaultUncaughtExceptionHandler() Thread.setDefaultUncaughtExceptionHandler { t, e -> try { - if (Settings.getSaveCrashLog()) { + if (Settings.saveCrashLog) { Crash.saveCrashLog(e) } } catch (ignored: Throwable) { @@ -89,7 +89,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor ReadableTime.initialize(this) AppConfig.initialize(this) EhTagDatabase.update() - AppCompatDelegate.setDefaultNightMode(Settings.getTheme()) + AppCompatDelegate.setDefaultNightMode(Settings.theme) launchIO { launchIO { ehDatabase @@ -106,8 +106,8 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor private fun cleanupDownload() { try { - val downloadLocation = Settings.getDownloadLocation() - if (Settings.getMediaScan()) { + val downloadLocation = Settings.downloadLocation + if (Settings.mediaScan) { CommonOperations.removeNoMediaFile(downloadLocation) } else { CommonOperations.ensureNoMediaFile(downloadLocation) @@ -212,7 +212,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor .dns(EhDns) .proxySelector(ehProxySelector) - if (Settings.getDF()) { + if (Settings.dF) { val factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())!! factory.init(null as KeyStore?) diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt index bb967a156..ab7564a05 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt @@ -13,697 +13,626 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package com.hippo.ehviewer -package com.hippo.ehviewer; +import android.content.SharedPreferences +import android.net.Uri +import android.util.Log +import androidx.annotation.DimenRes +import androidx.preference.PreferenceManager +import com.hippo.ehviewer.EhApplication.Companion.application +import com.hippo.ehviewer.client.data.FavListUrlBuilder +import com.hippo.ehviewer.ui.CommonOperations.ensureNoMediaFile +import com.hippo.ehviewer.ui.CommonOperations.removeNoMediaFile +import com.hippo.ehviewer.ui.scene.GalleryListScene +import com.hippo.unifile.UniFile +import com.hippo.yorozuya.NumberUtils +import java.util.Locale -import android.content.SharedPreferences; -import android.net.Uri; -import android.util.Log; - -import androidx.annotation.DimenRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.preference.PreferenceManager; - -import com.hippo.ehviewer.client.data.FavListUrlBuilder; -import com.hippo.ehviewer.ui.CommonOperations; -import com.hippo.ehviewer.ui.scene.GalleryListScene; -import com.hippo.unifile.UniFile; -import com.hippo.yorozuya.AssertUtilsKt; -import com.hippo.yorozuya.NumberUtils; - -import java.util.Locale; -import java.util.Set; - -public class Settings { +object Settings { + /******************** + * Eh + */ + const val KEY_THEME = "theme" + const val KEY_ACCOUNT = "account" + const val KEY_IMAGE_LIMITS = "image_limits" + const val KEY_U_CONFIG = "uconfig" + const val KEY_MY_TAGS = "mytags" + const val KEY_BLACK_DARK_THEME = "black_dark_theme" + const val DEFAULT_BLACK_DARK_THEME = false + const val THEME_SYSTEM = -1 + const val KEY_GALLERY_SITE = "gallery_site" + const val KEY_LIST_MODE = "list_mode" + const val KEY_DETAIL_SIZE = "detail_size" + const val KEY_THUMB_SIZE = "thumb_size_" + const val KEY_THUMB_RESOLUTION = "thumb_resolution" + const val KEY_SHOW_JPN_TITLE = "show_jpn_title" + const val KEY_SHOW_TAG_TRANSLATIONS = "show_tag_translations" + const val KEY_TAG_TRANSLATIONS_SOURCE = "tag_translations_source" + const val KEY_REQUEST_NEWS = "request_news" + const val KEY_REQUEST_NEWS_TIMER = "request_news_timer" + const val KEY_REQUEST_NEWS_TIMER_HOUR = "request_news_timer_hour" + const val KEY_REQUEST_NEWS_TIMER_MINUTE = "request_news_timer_minute" + const val KEY_HIDE_HV_EVENTS = "hide_hv_events" + val SIGN_IN_REQUIRED = arrayOf( + KEY_IMAGE_LIMITS, + KEY_GALLERY_SITE, + KEY_U_CONFIG, + KEY_MY_TAGS, + KEY_SHOW_JPN_TITLE, + KEY_REQUEST_NEWS, + KEY_REQUEST_NEWS_TIMER, + KEY_HIDE_HV_EVENTS + ) /******************** - ****** Eh - ********************/ + * Privacy and Security + */ + const val KEY_SEC_SECURITY = "enable_secure" + const val VALUE_SEC_SECURITY = false - public static final String KEY_THEME = "theme"; + /******************** + * Download + */ + const val KEY_DOWNLOAD_SAVE_SCHEME = "image_scheme" + const val KEY_DOWNLOAD_SAVE_AUTHORITY = "image_authority" + const val KEY_DOWNLOAD_SAVE_PATH = "image_path" + const val KEY_NOTIFICATION_REQUIRED = "notification_required" + const val KEY_DOWNLOAD_SAVE_QUERY = "image_query" + const val KEY_DOWNLOAD_SAVE_FRAGMENT = "image_fragment" + const val KEY_MEDIA_SCAN = "media_scan" + const val INVALID_DEFAULT_FAV_SLOT = -2 - public static final String KEY_ACCOUNT = "account"; - public static final String KEY_IMAGE_LIMITS = "image_limits"; - public static final String KEY_U_CONFIG = "uconfig"; - public static final String KEY_MY_TAGS = "mytags"; - public static final String KEY_BLACK_DARK_THEME = "black_dark_theme"; - public static final int THEME_SYSTEM = -1; - public static final String KEY_GALLERY_SITE = "gallery_site"; - public static final String KEY_LIST_MODE = "list_mode"; - public static final String KEY_DETAIL_SIZE = "detail_size"; - public static final String KEY_THUMB_SIZE = "thumb_size_"; - public static final String KEY_THUMB_RESOLUTION = "thumb_resolution"; - public static final String KEY_SHOW_JPN_TITLE = "show_jpn_title"; - public static final String KEY_SHOW_TAG_TRANSLATIONS = "show_tag_translations"; - public static final String KEY_TAG_TRANSLATIONS_SOURCE = "tag_translations_source"; - public static final String KEY_REQUEST_NEWS = "request_news"; - public static final String KEY_REQUEST_NEWS_TIMER = "request_news_timer"; - public static final String KEY_REQUEST_NEWS_TIMER_HOUR = "request_news_timer_hour"; - public static final String KEY_REQUEST_NEWS_TIMER_MINUTE = "request_news_timer_minute"; - public static final String KEY_HIDE_HV_EVENTS = "hide_hv_events"; - public static final String[] SIGN_IN_REQUIRED = { - KEY_IMAGE_LIMITS, - KEY_GALLERY_SITE, - KEY_U_CONFIG, - KEY_MY_TAGS, - KEY_SHOW_JPN_TITLE, - KEY_REQUEST_NEWS, - KEY_REQUEST_NEWS_TIMER, - KEY_HIDE_HV_EVENTS - }; /******************** - ****** Privacy and Security - ********************/ - public static final String KEY_SEC_SECURITY = "enable_secure"; - public static final boolean VALUE_SEC_SECURITY = false; + * Advanced + */ + const val KEY_SAVE_PARSE_ERROR_BODY = "save_parse_error_body" + const val KEY_SECURITY = "require_unlock" + const val KEY_SECURITY_DELAY = "require_unlock_delay" + const val KEY_READ_CACHE_SIZE = "read_cache_size" + const val DEFAULT_READ_CACHE_SIZE = 320 + const val KEY_BUILT_IN_HOSTS = "built_in_hosts_2" + const val KEY_DOMAIN_FRONTING = "domain_fronting" + const val KEY_BYPASS_VPN = "bypass_vpn" + const val KEY_LIST_THUMB_SIZE = "list_tile_size" + private const val DEFAULT_HIDE_HV_EVENTS = false + private const val KEY_SHOW_COMMENTS = "show_gallery_comments" + private const val DEFAULT_SHOW_COMMENTS = true + private val TAG = Settings::class.java.simpleName + private const val KEY_DISPLAY_NAME = "display_name" + private val DEFAULT_DISPLAY_NAME: String? = null + private const val DEFAULT_LIST_THUMB_SIZE = 40 + private const val KEY_AVATAR = "avatar" + private const val KEY_REMOVE_IMAGE_FILES = "include_pic" + private const val DEFAULT_REMOVE_IMAGE_FILES = true + private const val KEY_NEED_SIGN_IN = "need_sign_in" + private const val DEFAULT_NEED_SIGN_IN = true + private const val KEY_SELECT_SITE = "select_site" + private const val DEFAULT_SELECT_SITE = true + private const val DEFAULT_THEME = THEME_SYSTEM + private const val DEFAULT_GALLERY_SITE = 1 + private const val KEY_LAUNCH_PAGE = "launch_page" + private const val DEFAULT_LAUNCH_PAGE = 0 + private const val DEFAULT_LIST_MODE = 0 + private const val DEFAULT_DETAIL_SIZE = 0 + private const val DEFAULT_THUMB_SIZE = 120 + private const val DEFAULT_THUMB_RESOLUTION = 0 + private const val DEFAULT_SHOW_JPN_TITLE = false + private const val KEY_SHOW_GALLERY_PAGES = "show_gallery_pages" + private const val DEFAULT_SHOW_GALLERY_PAGES = false + private const val DEFAULT_SHOW_TAG_TRANSLATIONS = false + private const val KEY_METERED_NETWORK_WARNING = "cellular_network_warning" + private const val DEFAULT_METERED_NETWORK_WARNING = false + private const val KEY_APP_LINK_VERIFY_TIP = "app_link_verify_tip" + private const val DEFAULT_APP_LINK_VERIFY_TIP = false + private const val DEFAULT_MEDIA_SCAN = false + private const val KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label" + private val DEFAULT_RECENT_DOWNLOAD_LABEL: String? = null + private const val KEY_HAS_DEFAULT_DOWNLOAD_LABEL = "has_default_download_label" + private const val DEFAULT_HAS_DOWNLOAD_LABEL = false + private const val KEY_DEFAULT_DOWNLOAD_LABEL = "default_download_label" + private val DEFAULT_DOWNLOAD_LABEL: String? = null + private const val KEY_MULTI_THREAD_DOWNLOAD = "download_thread" + private const val DEFAULT_MULTI_THREAD_DOWNLOAD = 3 + private const val KEY_PRELOAD_IMAGE = "preload_image" + private const val DEFAULT_PRELOAD_IMAGE = 5 + private const val KEY_DOWNLOAD_ORIGIN_IMAGE = "download_origin_image" + private const val DEFAULT_DOWNLOAD_ORIGIN_IMAGE = false + /******************** - ****** Download - ********************/ - public static final String KEY_DOWNLOAD_SAVE_SCHEME = "image_scheme"; - public static final String KEY_DOWNLOAD_SAVE_AUTHORITY = "image_authority"; - public static final String KEY_DOWNLOAD_SAVE_PATH = "image_path"; - public static final String KEY_NOTIFICATION_REQUIRED = "notification_required"; - public static final String KEY_DOWNLOAD_SAVE_QUERY = "image_query"; - public static final String KEY_DOWNLOAD_SAVE_FRAGMENT = "image_fragment"; - public static final String KEY_MEDIA_SCAN = "media_scan"; - public static final int INVALID_DEFAULT_FAV_SLOT = -2; - /******************** - ****** Advanced - ********************/ - public static final String KEY_SAVE_PARSE_ERROR_BODY = "save_parse_error_body"; - public static final String KEY_SECURITY = "require_unlock"; - public static final String KEY_SECURITY_DELAY = "require_unlock_delay"; - public static final String KEY_READ_CACHE_SIZE = "read_cache_size"; - public static final int DEFAULT_READ_CACHE_SIZE = 320; - public static final String KEY_BUILT_IN_HOSTS = "built_in_hosts_2"; - public static final String KEY_DOMAIN_FRONTING = "domain_fronting"; - public static final String KEY_BYPASS_VPN = "bypass_vpn"; - public static final String KEY_LIST_THUMB_SIZE = "list_tile_size"; - private static final boolean DEFAULT_HIDE_HV_EVENTS = false; - private static final String KEY_SHOW_COMMENTS = "show_gallery_comments"; - private static final boolean DEFAULT_SHOW_COMMENTS = true; - private static final String TAG = Settings.class.getSimpleName(); - private static final String KEY_DISPLAY_NAME = "display_name"; - private static final String DEFAULT_DISPLAY_NAME = null; - private static final int DEFAULT_LIST_THUMB_SIZE = 40; - private static final String KEY_AVATAR = "avatar"; - private static final String KEY_REMOVE_IMAGE_FILES = "include_pic"; - private static final boolean DEFAULT_REMOVE_IMAGE_FILES = true; - private static final String KEY_NEED_SIGN_IN = "need_sign_in"; - private static final boolean DEFAULT_NEED_SIGN_IN = true; - private static final String KEY_SELECT_SITE = "select_site"; - private static final boolean DEFAULT_SELECT_SITE = true; - private static final int DEFAULT_THEME = THEME_SYSTEM; - private static final int DEFAULT_GALLERY_SITE = 1; - private static final String KEY_LAUNCH_PAGE = "launch_page"; - private static final int DEFAULT_LAUNCH_PAGE = 0; - private static final int DEFAULT_LIST_MODE = 0; - private static final int DEFAULT_DETAIL_SIZE = 0; - private static final int DEFAULT_THUMB_SIZE = 120; - private static final int DEFAULT_THUMB_RESOLUTION = 0; - private static final boolean DEFAULT_SHOW_JPN_TITLE = false; - private static final String KEY_SHOW_GALLERY_PAGES = "show_gallery_pages"; - private static final boolean DEFAULT_SHOW_GALLERY_PAGES = false; - private static final boolean DEFAULT_SHOW_TAG_TRANSLATIONS = false; - private static final String KEY_METERED_NETWORK_WARNING = "cellular_network_warning"; - private static final boolean DEFAULT_METERED_NETWORK_WARNING = false; - private static final String KEY_APP_LINK_VERIFY_TIP = "app_link_verify_tip"; - private static final boolean DEFAULT_APP_LINK_VERIFY_TIP = false; - private static final boolean DEFAULT_MEDIA_SCAN = false; - private static final String KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label"; - private static final String DEFAULT_RECENT_DOWNLOAD_LABEL = null; - private static final String KEY_HAS_DEFAULT_DOWNLOAD_LABEL = "has_default_download_label"; - private static final boolean DEFAULT_HAS_DOWNLOAD_LABEL = false; - private static final String KEY_DEFAULT_DOWNLOAD_LABEL = "default_download_label"; - private static final String DEFAULT_DOWNLOAD_LABEL = null; - private static final String KEY_MULTI_THREAD_DOWNLOAD = "download_thread"; - private static final int DEFAULT_MULTI_THREAD_DOWNLOAD = 3; - private static final String KEY_PRELOAD_IMAGE = "preload_image"; - private static final int DEFAULT_PRELOAD_IMAGE = 5; - private static final String KEY_DOWNLOAD_ORIGIN_IMAGE = "download_origin_image"; - private static final boolean DEFAULT_DOWNLOAD_ORIGIN_IMAGE = false; - /******************** - ****** Favorites - ********************/ - private static final String KEY_FAV_CAT_0 = "fav_cat_0"; - private static final String KEY_FAV_CAT_1 = "fav_cat_1"; - private static final String KEY_FAV_CAT_2 = "fav_cat_2"; - private static final String KEY_FAV_CAT_3 = "fav_cat_3"; - private static final String KEY_FAV_CAT_4 = "fav_cat_4"; - private static final String KEY_FAV_CAT_5 = "fav_cat_5"; - private static final String KEY_FAV_CAT_6 = "fav_cat_6"; - private static final String KEY_FAV_CAT_7 = "fav_cat_7"; - private static final String KEY_FAV_CAT_8 = "fav_cat_8"; - private static final String KEY_FAV_CAT_9 = "fav_cat_9"; - private static final String DEFAULT_FAV_CAT_0 = "Favorites 0"; - private static final String DEFAULT_FAV_CAT_1 = "Favorites 1"; - private static final String DEFAULT_FAV_CAT_2 = "Favorites 2"; - private static final String DEFAULT_FAV_CAT_3 = "Favorites 3"; - private static final String DEFAULT_FAV_CAT_4 = "Favorites 4"; - private static final String DEFAULT_FAV_CAT_5 = "Favorites 5"; - private static final String DEFAULT_FAV_CAT_6 = "Favorites 6"; - private static final String DEFAULT_FAV_CAT_7 = "Favorites 7"; - private static final String DEFAULT_FAV_CAT_8 = "Favorites 8"; - private static final String DEFAULT_FAV_CAT_9 = "Favorites 9"; - private static final String KEY_FAV_COUNT_0 = "fav_count_0"; - private static final String KEY_FAV_COUNT_1 = "fav_count_1"; - private static final String KEY_FAV_COUNT_2 = "fav_count_2"; - private static final String KEY_FAV_COUNT_3 = "fav_count_3"; - private static final String KEY_FAV_COUNT_4 = "fav_count_4"; - private static final String KEY_FAV_COUNT_5 = "fav_count_5"; - private static final String KEY_FAV_COUNT_6 = "fav_count_6"; - private static final String KEY_FAV_COUNT_7 = "fav_count_7"; - private static final String KEY_FAV_COUNT_8 = "fav_count_8"; - private static final String KEY_FAV_COUNT_9 = "fav_count_9"; - private static final String KEY_FAV_LOCAL = "fav_local"; - private static final String KEY_FAV_CLOUD = "fav_cloud"; - private static final int DEFAULT_FAV_COUNT = 0; - private static final String KEY_RECENT_FAV_CAT = "recent_fav_cat"; - private static final int DEFAULT_RECENT_FAV_CAT = FavListUrlBuilder.FAV_CAT_ALL; + * Favorites + */ + private const val KEY_FAV_CAT_0 = "fav_cat_0" + private const val KEY_FAV_CAT_1 = "fav_cat_1" + private const val KEY_FAV_CAT_2 = "fav_cat_2" + private const val KEY_FAV_CAT_3 = "fav_cat_3" + private const val KEY_FAV_CAT_4 = "fav_cat_4" + private const val KEY_FAV_CAT_5 = "fav_cat_5" + private const val KEY_FAV_CAT_6 = "fav_cat_6" + private const val KEY_FAV_CAT_7 = "fav_cat_7" + private const val KEY_FAV_CAT_8 = "fav_cat_8" + private const val KEY_FAV_CAT_9 = "fav_cat_9" + private const val DEFAULT_FAV_CAT_0 = "Favorites 0" + private const val DEFAULT_FAV_CAT_1 = "Favorites 1" + private const val DEFAULT_FAV_CAT_2 = "Favorites 2" + private const val DEFAULT_FAV_CAT_3 = "Favorites 3" + private const val DEFAULT_FAV_CAT_4 = "Favorites 4" + private const val DEFAULT_FAV_CAT_5 = "Favorites 5" + private const val DEFAULT_FAV_CAT_6 = "Favorites 6" + private const val DEFAULT_FAV_CAT_7 = "Favorites 7" + private const val DEFAULT_FAV_CAT_8 = "Favorites 8" + private const val DEFAULT_FAV_CAT_9 = "Favorites 9" + private const val KEY_FAV_COUNT_0 = "fav_count_0" + private const val KEY_FAV_COUNT_1 = "fav_count_1" + private const val KEY_FAV_COUNT_2 = "fav_count_2" + private const val KEY_FAV_COUNT_3 = "fav_count_3" + private const val KEY_FAV_COUNT_4 = "fav_count_4" + private const val KEY_FAV_COUNT_5 = "fav_count_5" + private const val KEY_FAV_COUNT_6 = "fav_count_6" + private const val KEY_FAV_COUNT_7 = "fav_count_7" + private const val KEY_FAV_COUNT_8 = "fav_count_8" + private const val KEY_FAV_COUNT_9 = "fav_count_9" + private const val KEY_FAV_LOCAL = "fav_local" + private const val KEY_FAV_CLOUD = "fav_cloud" + private const val DEFAULT_FAV_COUNT = 0 + private const val KEY_RECENT_FAV_CAT = "recent_fav_cat" + private const val DEFAULT_RECENT_FAV_CAT = FavListUrlBuilder.FAV_CAT_ALL + // -1 for local, 0 - 9 for cloud favorite, other for no default fav slot - private static final String KEY_DEFAULT_FAV_SLOT = "default_favorite_2"; - private static final int DEFAULT_DEFAULT_FAV_SLOT = INVALID_DEFAULT_FAV_SLOT; - private static final boolean DEFAULT_SAVE_PARSE_ERROR_BODY = true; - private static final String KEY_SAVE_CRASH_LOG = "save_crash_log"; - private static final boolean DEFAULT_SAVE_CRASH_LOG = true; - private static final boolean DEFAULT_BUILT_IN_HOSTS = false; - private static final boolean DEFAULT_FRONTING = false; - private static final boolean DEFAULT_BYPASS_VPN = true; - private static final String KEY_PROXY_TYPE = "proxy_type"; - private static final int DEFAULT_PROXY_TYPE = EhProxySelector.TYPE_SYSTEM; - private static final String KEY_PROXY_IP = "proxy_ip"; - private static final String DEFAULT_PROXY_IP = null; - private static final String KEY_PROXY_PORT = "proxy_port"; - private static final int DEFAULT_PROXY_PORT = -1; - private static final String KEY_CLIPBOARD_TEXT_HASH_CODE = "clipboard_text_hash_code"; - private static final int DEFAULT_CLIPBOARD_TEXT_HASH_CODE = 0; - private static final String KEY_DOWNLOAD_DELAY = "download_delay"; - private static final int DEFAULT_DOWNLOAD_DELAY = 0; - private static final boolean DEFAULT_REQUEST_NEWS = false; - private static final String KEY_ARCHIVE_PASSWDS = "archive_passwds"; - private static final String KEY_QS_SAVE_PROGRESS = "qs_save_progress"; - private static final boolean DEFAULT_QS_SAVE_PROGRESS = true; - public static boolean LIST_THUMB_SIZE_INITED = false; - public static SharedPreferences sSettingsPre; - private static int LIST_THUMB_SIZE = 40; - - public static void initialize() { - sSettingsPre = PreferenceManager.getDefaultSharedPreferences(EhApplication.getApplication()); - fixDefaultValue(); + private const val KEY_DEFAULT_FAV_SLOT = "default_favorite_2" + private const val DEFAULT_DEFAULT_FAV_SLOT = INVALID_DEFAULT_FAV_SLOT + private const val DEFAULT_SAVE_PARSE_ERROR_BODY = true + private const val KEY_SAVE_CRASH_LOG = "save_crash_log" + private const val DEFAULT_SAVE_CRASH_LOG = true + private const val DEFAULT_BUILT_IN_HOSTS = false + private const val DEFAULT_FRONTING = false + private const val DEFAULT_BYPASS_VPN = true + private const val KEY_PROXY_TYPE = "proxy_type" + private const val DEFAULT_PROXY_TYPE = EhProxySelector.TYPE_SYSTEM + private const val KEY_PROXY_IP = "proxy_ip" + private val DEFAULT_PROXY_IP: String? = null + private const val KEY_PROXY_PORT = "proxy_port" + private const val DEFAULT_PROXY_PORT = -1 + private const val KEY_CLIPBOARD_TEXT_HASH_CODE = "clipboard_text_hash_code" + private const val DEFAULT_CLIPBOARD_TEXT_HASH_CODE = 0 + private const val KEY_DOWNLOAD_DELAY = "download_delay" + private const val DEFAULT_DOWNLOAD_DELAY = 0 + private const val DEFAULT_REQUEST_NEWS = false + private const val KEY_ARCHIVE_PASSWDS = "archive_passwds" + private const val KEY_QS_SAVE_PROGRESS = "qs_save_progress" + private const val DEFAULT_QS_SAVE_PROGRESS = true + var LIST_THUMB_SIZE_INITED = false + private lateinit var sSettingsPre: SharedPreferences + private var LIST_THUMB_SIZE = 40 + fun initialize() { + sSettingsPre = PreferenceManager.getDefaultSharedPreferences(application) + fixDefaultValue() } - private static void fixDefaultValue() { - if ("CN".equals(Locale.getDefault().getCountry())) { + private fun fixDefaultValue() { + if ("CN" == Locale.getDefault().country) { // Enable domain fronting if the country is CN if (!sSettingsPre.contains(KEY_BUILT_IN_HOSTS)) { - putBuiltInHosts(true); + putBuiltInHosts(true) } if (!sSettingsPre.contains(KEY_DOMAIN_FRONTING)) { - putDF(true); + putDF(true) } // Enable show tag translations if the country is CN if (!sSettingsPre.contains(KEY_SHOW_TAG_TRANSLATIONS)) { - putShowTagTranslations(true); - + putShowTagTranslations(true) } } } - public static boolean getBoolean(String key, boolean defValue) { - try { - return sSettingsPre.getBoolean(key, defValue); - } catch (ClassCastException e) { - Log.d(TAG, "Get ClassCastException when get " + key + " value", e); - return defValue; + private fun getBoolean(key: String, defValue: Boolean): Boolean { + return try { + sSettingsPre.getBoolean(key, defValue) + } catch (e: ClassCastException) { + Log.d(TAG, "Get ClassCastException when get $key value", e) + defValue } } - public static void putBoolean(String key, boolean value) { - sSettingsPre.edit().putBoolean(key, value).apply(); + private fun putBoolean(key: String, value: Boolean) { + sSettingsPre.edit().putBoolean(key, value).apply() } - public static int getInt(String key, int defValue) { - try { - return sSettingsPre.getInt(key, defValue); - } catch (ClassCastException e) { - Log.d(TAG, "Get ClassCastException when get " + key + " value", e); - return defValue; + @JvmStatic + fun getInt(key: String, defValue: Int): Int { + return try { + sSettingsPre.getInt(key, defValue) + } catch (e: ClassCastException) { + Log.d(TAG, "Get ClassCastException when get $key value", e) + defValue } } - public static void putInt(String key, int value) { - sSettingsPre.edit().putInt(key, value).apply(); + @JvmStatic + fun putInt(key: String, value: Int) { + sSettingsPre.edit().putInt(key, value).apply() } - public static String getString(String key, String defValue) { - try { - return sSettingsPre.getString(key, defValue); - } catch (ClassCastException e) { - Log.d(TAG, "Get ClassCastException when get " + key + " value", e); - return defValue; + private fun getString(key: String, defValue: String?): String? { + return try { + sSettingsPre.getString(key, defValue) + } catch (e: ClassCastException) { + Log.d(TAG, "Get ClassCastException when get $key value", e) + defValue } } - public static void putString(String key, String value) { - sSettingsPre.edit().putString(key, value).apply(); + private fun putString(key: String, value: String?) { + sSettingsPre.edit().putString(key, value).apply() } - public static Set getStringSet(String key) { - return sSettingsPre.getStringSet(key, null); + private fun getStringSet(key: String): MutableSet? { + return sSettingsPre.getStringSet(key, null) } - public static void putStringToStringSet(String key, String value) { - Set set = getStringSet(key); - if (set == null) - set = Set.of(value); - else if (set.contains(value)) - return; - else - set.add(value); - sSettingsPre.edit().putStringSet(key, set).apply(); + private fun putStringToStringSet(key: String, value: String) { + var set = getStringSet(key) + if (set == null) set = + mutableSetOf(value) else if (set.contains(value)) return else set.add(value) + sSettingsPre.edit().putStringSet(key, set).apply() } - public static int getIntFromStr(String key, int defValue) { - try { - return NumberUtils.parseIntSafely(sSettingsPre.getString(key, Integer.toString(defValue)), defValue); - } catch (ClassCastException e) { - Log.d(TAG, "Get ClassCastException when get " + key + " value", e); - return defValue; + private fun getIntFromStr(key: String, defValue: Int): Int { + return try { + NumberUtils.parseIntSafely( + sSettingsPre.getString(key, defValue.toString()), + defValue + ) + } catch (e: ClassCastException) { + Log.d(TAG, "Get ClassCastException when get $key value", e) + defValue } } - public static void putIntToStr(String key, int value) { - sSettingsPre.edit().putString(key, Integer.toString(value)).apply(); + private fun putIntToStr(key: String, value: Int) { + sSettingsPre.edit().putString(key, value.toString()).apply() } - @Nullable - public static String getDisplayName() { - return getString(KEY_DISPLAY_NAME, DEFAULT_DISPLAY_NAME); + val displayName: String? + get() = getString(KEY_DISPLAY_NAME, DEFAULT_DISPLAY_NAME) + + fun putDisplayName(value: String?) { + putString(KEY_DISPLAY_NAME, value) } - public static void putDisplayName(String value) { - putString(KEY_DISPLAY_NAME, value); + fun putAvatar(value: String?) { + putString(KEY_AVATAR, value) } - public static void putAvatar(String value) { - putString(KEY_AVATAR, value); + val removeImageFiles: Boolean + get() = getBoolean(KEY_REMOVE_IMAGE_FILES, DEFAULT_REMOVE_IMAGE_FILES) + + fun putRemoveImageFiles(value: Boolean) { + putBoolean(KEY_REMOVE_IMAGE_FILES, value) } - public static boolean getRemoveImageFiles() { - return getBoolean(KEY_REMOVE_IMAGE_FILES, DEFAULT_REMOVE_IMAGE_FILES); + val needSignIn: Boolean + get() = getBoolean(KEY_NEED_SIGN_IN, DEFAULT_NEED_SIGN_IN) + + fun putNeedSignIn(value: Boolean) { + putBoolean(KEY_NEED_SIGN_IN, value) } - public static void putRemoveImageFiles(boolean value) { - putBoolean(KEY_REMOVE_IMAGE_FILES, value); + val selectSite: Boolean + get() = getBoolean(KEY_SELECT_SITE, DEFAULT_SELECT_SITE) + + fun putSelectSite(value: Boolean) { + putBoolean(KEY_SELECT_SITE, value) } - public static boolean getNeedSignIn() { - return getBoolean(KEY_NEED_SIGN_IN, DEFAULT_NEED_SIGN_IN); + val theme: Int + get() = getIntFromStr(KEY_THEME, DEFAULT_THEME) + val blackDarkTheme + get() = getBoolean(KEY_BLACK_DARK_THEME, DEFAULT_BLACK_DARK_THEME) + val gallerySite: Int + get() = getIntFromStr(KEY_GALLERY_SITE, DEFAULT_GALLERY_SITE) + + fun putGallerySite(value: Int) { + putIntToStr(KEY_GALLERY_SITE, value) } - public static void putNeedSignIn(boolean value) { - putBoolean(KEY_NEED_SIGN_IN, value); + val launchPageGalleryListSceneAction: String + get() { + return when (val value = getIntFromStr(KEY_LAUNCH_PAGE, DEFAULT_LAUNCH_PAGE)) { + 0 -> GalleryListScene.ACTION_HOMEPAGE + 1 -> GalleryListScene.ACTION_SUBSCRIPTION + 2 -> GalleryListScene.ACTION_WHATS_HOT + 3 -> GalleryListScene.ACTION_TOP_LIST + else -> throw IllegalStateException("Unexpected value: $value") + } + } + val listMode: Int + get() = getIntFromStr(KEY_LIST_MODE, DEFAULT_LIST_MODE) + private val detailSize: Int + get() = getIntFromStr(KEY_DETAIL_SIZE, DEFAULT_DETAIL_SIZE) + + @get:DimenRes + val detailSizeResId: Int + get() = when (detailSize) { + 0 -> R.dimen.gallery_list_column_width_long + 1 -> R.dimen.gallery_list_column_width_short + else -> throw IllegalStateException("Unexpected value: $detailSize") + } + val thumbSize: Int + get() = dip2px(getInt(KEY_THUMB_SIZE, DEFAULT_THUMB_SIZE)) + + private fun dip2px(dpValue: Int): Int { + val scale = application.resources.displayMetrics.density + return (dpValue * scale + 0.5f).toInt() } - public static boolean getSelectSite() { - return getBoolean(KEY_SELECT_SITE, DEFAULT_SELECT_SITE); + val thumbResolution: Int + get() = getIntFromStr(KEY_THUMB_RESOLUTION, DEFAULT_THUMB_RESOLUTION) + val showComments: Boolean + get() = getBoolean(KEY_SHOW_COMMENTS, DEFAULT_SHOW_COMMENTS) + val requestNews: Boolean + get() = getBoolean(KEY_REQUEST_NEWS, DEFAULT_REQUEST_NEWS) + val hideHvEvents: Boolean + get() = getBoolean(KEY_HIDE_HV_EVENTS, DEFAULT_HIDE_HV_EVENTS) + val showJpnTitle: Boolean + get() = getBoolean(KEY_SHOW_JPN_TITLE, DEFAULT_SHOW_JPN_TITLE) + val showGalleryPages: Boolean + get() = getBoolean(KEY_SHOW_GALLERY_PAGES, DEFAULT_SHOW_GALLERY_PAGES) + val showTagTranslations: Boolean + get() = getBoolean(KEY_SHOW_TAG_TRANSLATIONS, DEFAULT_SHOW_TAG_TRANSLATIONS) + + private fun putShowTagTranslations(value: Boolean) { + putBoolean(KEY_SHOW_TAG_TRANSLATIONS, value) } - public static void putSelectSite(boolean value) { - putBoolean(KEY_SELECT_SITE, value); + val meteredNetworkWarning: Boolean + get() = getBoolean(KEY_METERED_NETWORK_WARNING, DEFAULT_METERED_NETWORK_WARNING) + val appLinkVerifyTip: Boolean + get() = getBoolean(KEY_APP_LINK_VERIFY_TIP, DEFAULT_APP_LINK_VERIFY_TIP) + + fun putAppLinkVerifyTip(value: Boolean) { + putBoolean(KEY_APP_LINK_VERIFY_TIP, value) } - public static int getTheme() { - return getIntFromStr(KEY_THEME, DEFAULT_THEME); - } + val enabledSecurity: Boolean + get() = getBoolean(KEY_SEC_SECURITY, VALUE_SEC_SECURITY) + val downloadLocation: UniFile? + get() { + val dir: UniFile? + val builder = Uri.Builder() + builder.scheme(getString(KEY_DOWNLOAD_SAVE_SCHEME, null)) + builder.encodedAuthority(getString(KEY_DOWNLOAD_SAVE_AUTHORITY, null)) + builder.encodedPath(getString(KEY_DOWNLOAD_SAVE_PATH, null)) + builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null)) + builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null)) + dir = UniFile.fromUri(application, builder.build()) + return dir ?: UniFile.fromFile(AppConfig.getDefaultDownloadDir()) + } - public static int getGallerySite() { - return getIntFromStr(KEY_GALLERY_SITE, DEFAULT_GALLERY_SITE); - } - - public static void putGallerySite(int value) { - putIntToStr(KEY_GALLERY_SITE, value); - } - - public static String getLaunchPageGalleryListSceneAction() { - int value = getIntFromStr(KEY_LAUNCH_PAGE, DEFAULT_LAUNCH_PAGE); - return switch (value) { - case 0 -> GalleryListScene.ACTION_HOMEPAGE; - case 1 -> GalleryListScene.ACTION_SUBSCRIPTION; - case 2 -> GalleryListScene.ACTION_WHATS_HOT; - case 3 -> GalleryListScene.ACTION_TOP_LIST; - default -> throw new IllegalStateException("Unexpected value: " + value); - }; - } - - public static int getListMode() { - return getIntFromStr(KEY_LIST_MODE, DEFAULT_LIST_MODE); - } - - public static int getDetailSize() { - return getIntFromStr(KEY_DETAIL_SIZE, DEFAULT_DETAIL_SIZE); - } - - @DimenRes - public static int getDetailSizeResId() { - return switch (getDetailSize()) { - case 0 -> R.dimen.gallery_list_column_width_long; - case 1 -> R.dimen.gallery_list_column_width_short; - default -> throw new IllegalStateException("Unexpected value: " + getDetailSize()); - }; - } - - public static int getThumbSize() { - return dip2px(getInt(KEY_THUMB_SIZE, DEFAULT_THUMB_SIZE)); - } - - public static int dip2px(int dpValue) { - final float scale = EhApplication.getApplication().getResources().getDisplayMetrics().density; - return (int) (dpValue * scale + 0.5f); - } - - public static int getThumbResolution() { - return getIntFromStr(KEY_THUMB_RESOLUTION, DEFAULT_THUMB_RESOLUTION); - } - - public static boolean getShowComments() { - return getBoolean(KEY_SHOW_COMMENTS, DEFAULT_SHOW_COMMENTS); - } - - public static boolean getRequestNews() { - return getBoolean(KEY_REQUEST_NEWS, DEFAULT_REQUEST_NEWS); - } - - public static boolean getHideHvEvents() { - return getBoolean(KEY_HIDE_HV_EVENTS, DEFAULT_HIDE_HV_EVENTS); - } - - public static boolean getShowJpnTitle() { - return getBoolean(KEY_SHOW_JPN_TITLE, DEFAULT_SHOW_JPN_TITLE); - } - - public static boolean getShowGalleryPages() { - return getBoolean(KEY_SHOW_GALLERY_PAGES, DEFAULT_SHOW_GALLERY_PAGES); - } - - public static boolean getShowTagTranslations() { - return getBoolean(KEY_SHOW_TAG_TRANSLATIONS, DEFAULT_SHOW_TAG_TRANSLATIONS); - } - - public static void putShowTagTranslations(boolean value) { - putBoolean(KEY_SHOW_TAG_TRANSLATIONS, value); - } - - public static boolean getMeteredNetworkWarning() { - return getBoolean(KEY_METERED_NETWORK_WARNING, DEFAULT_METERED_NETWORK_WARNING); - } - - public static boolean getAppLinkVerifyTip() { - return getBoolean(KEY_APP_LINK_VERIFY_TIP, DEFAULT_APP_LINK_VERIFY_TIP); - } - - public static void putAppLinkVerifyTip(boolean value) { - putBoolean(KEY_APP_LINK_VERIFY_TIP, value); - } - - public static boolean getEnabledSecurity() { - return getBoolean(KEY_SEC_SECURITY, VALUE_SEC_SECURITY); - } - - @Nullable - public static UniFile getDownloadLocation() { - UniFile dir; - Uri.Builder builder = new Uri.Builder(); - builder.scheme(getString(KEY_DOWNLOAD_SAVE_SCHEME, null)); - builder.encodedAuthority(getString(KEY_DOWNLOAD_SAVE_AUTHORITY, null)); - builder.encodedPath(getString(KEY_DOWNLOAD_SAVE_PATH, null)); - builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null)); - builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null)); - dir = UniFile.fromUri(EhApplication.getApplication(), builder.build()); - return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir()); - } - - public static void putDownloadLocation(@NonNull UniFile location) { - Uri uri = location.getUri(); - putString(KEY_DOWNLOAD_SAVE_SCHEME, uri.getScheme()); - putString(KEY_DOWNLOAD_SAVE_AUTHORITY, uri.getEncodedAuthority()); - putString(KEY_DOWNLOAD_SAVE_PATH, uri.getEncodedPath()); - putString(KEY_DOWNLOAD_SAVE_QUERY, uri.getEncodedQuery()); - putString(KEY_DOWNLOAD_SAVE_FRAGMENT, uri.getEncodedFragment()); - - if (getMediaScan()) { - CommonOperations.removeNoMediaFile(location); + fun putDownloadLocation(location: UniFile) { + val uri = location.uri + putString(KEY_DOWNLOAD_SAVE_SCHEME, uri.scheme) + putString(KEY_DOWNLOAD_SAVE_AUTHORITY, uri.encodedAuthority) + putString(KEY_DOWNLOAD_SAVE_PATH, uri.encodedPath) + putString(KEY_DOWNLOAD_SAVE_QUERY, uri.encodedQuery) + putString(KEY_DOWNLOAD_SAVE_FRAGMENT, uri.encodedFragment) + if (mediaScan) { + removeNoMediaFile(location) } else { - CommonOperations.ensureNoMediaFile(location); + ensureNoMediaFile(location) } } - public static boolean getMediaScan() { - return getBoolean(KEY_MEDIA_SCAN, DEFAULT_MEDIA_SCAN); + val mediaScan: Boolean + get() = getBoolean(KEY_MEDIA_SCAN, DEFAULT_MEDIA_SCAN) + val recentDownloadLabel: String? + get() = getString(KEY_RECENT_DOWNLOAD_LABEL, DEFAULT_RECENT_DOWNLOAD_LABEL) + + fun putRecentDownloadLabel(value: String?) { + putString(KEY_RECENT_DOWNLOAD_LABEL, value) } - public static String getRecentDownloadLabel() { - return getString(KEY_RECENT_DOWNLOAD_LABEL, DEFAULT_RECENT_DOWNLOAD_LABEL); + val hasDefaultDownloadLabel: Boolean + get() = getBoolean(KEY_HAS_DEFAULT_DOWNLOAD_LABEL, DEFAULT_HAS_DOWNLOAD_LABEL) + + fun putHasDefaultDownloadLabel(hasDefaultDownloadLabel: Boolean) { + putBoolean(KEY_HAS_DEFAULT_DOWNLOAD_LABEL, hasDefaultDownloadLabel) } - public static void putRecentDownloadLabel(String value) { - putString(KEY_RECENT_DOWNLOAD_LABEL, value); + val defaultDownloadLabel: String? + get() = getString(KEY_DEFAULT_DOWNLOAD_LABEL, DEFAULT_DOWNLOAD_LABEL) + + fun putDefaultDownloadLabel(value: String?) { + putString(KEY_DEFAULT_DOWNLOAD_LABEL, value) } - public static boolean getHasDefaultDownloadLabel() { - return getBoolean(KEY_HAS_DEFAULT_DOWNLOAD_LABEL, DEFAULT_HAS_DOWNLOAD_LABEL); - } + val multiThreadDownload: Int + get() = getIntFromStr(KEY_MULTI_THREAD_DOWNLOAD, DEFAULT_MULTI_THREAD_DOWNLOAD) + val downloadDelay: Int + get() = getIntFromStr(KEY_DOWNLOAD_DELAY, DEFAULT_DOWNLOAD_DELAY) + val preloadImage: Int + get() = getIntFromStr(KEY_PRELOAD_IMAGE, DEFAULT_PRELOAD_IMAGE) + val downloadOriginImage: Boolean + get() = getBoolean(KEY_DOWNLOAD_ORIGIN_IMAGE, DEFAULT_DOWNLOAD_ORIGIN_IMAGE) + val favCat: Array + get() = arrayOf( + sSettingsPre.getString(KEY_FAV_CAT_0, DEFAULT_FAV_CAT_0)!!, + sSettingsPre.getString(KEY_FAV_CAT_1, DEFAULT_FAV_CAT_1)!!, + sSettingsPre.getString(KEY_FAV_CAT_2, DEFAULT_FAV_CAT_2)!!, + sSettingsPre.getString(KEY_FAV_CAT_3, DEFAULT_FAV_CAT_3)!!, + sSettingsPre.getString(KEY_FAV_CAT_4, DEFAULT_FAV_CAT_4)!!, + sSettingsPre.getString(KEY_FAV_CAT_5, DEFAULT_FAV_CAT_5)!!, + sSettingsPre.getString(KEY_FAV_CAT_6, DEFAULT_FAV_CAT_6)!!, + sSettingsPre.getString(KEY_FAV_CAT_7, DEFAULT_FAV_CAT_7)!!, + sSettingsPre.getString(KEY_FAV_CAT_8, DEFAULT_FAV_CAT_8)!!, + sSettingsPre.getString(KEY_FAV_CAT_9, DEFAULT_FAV_CAT_9)!! + ) - public static void putHasDefaultDownloadLabel(boolean hasDefaultDownloadLabel) { - putBoolean(KEY_HAS_DEFAULT_DOWNLOAD_LABEL, hasDefaultDownloadLabel); - } - - public static String getDefaultDownloadLabel() { - return getString(KEY_DEFAULT_DOWNLOAD_LABEL, DEFAULT_DOWNLOAD_LABEL); - } - - public static void putDefaultDownloadLabel(String value) { - putString(KEY_DEFAULT_DOWNLOAD_LABEL, value); - } - - public static int getMultiThreadDownload() { - return getIntFromStr(KEY_MULTI_THREAD_DOWNLOAD, DEFAULT_MULTI_THREAD_DOWNLOAD); - } - - public static int getDownloadDelay() { - return getIntFromStr(KEY_DOWNLOAD_DELAY, DEFAULT_DOWNLOAD_DELAY); - } - - public static int getPreloadImage() { - return getIntFromStr(KEY_PRELOAD_IMAGE, DEFAULT_PRELOAD_IMAGE); - } - - public static boolean getDownloadOriginImage() { - return getBoolean(KEY_DOWNLOAD_ORIGIN_IMAGE, DEFAULT_DOWNLOAD_ORIGIN_IMAGE); - } - - public static String[] getFavCat() { - String[] favCat = new String[10]; - favCat[0] = sSettingsPre.getString(KEY_FAV_CAT_0, DEFAULT_FAV_CAT_0); - favCat[1] = sSettingsPre.getString(KEY_FAV_CAT_1, DEFAULT_FAV_CAT_1); - favCat[2] = sSettingsPre.getString(KEY_FAV_CAT_2, DEFAULT_FAV_CAT_2); - favCat[3] = sSettingsPre.getString(KEY_FAV_CAT_3, DEFAULT_FAV_CAT_3); - favCat[4] = sSettingsPre.getString(KEY_FAV_CAT_4, DEFAULT_FAV_CAT_4); - favCat[5] = sSettingsPre.getString(KEY_FAV_CAT_5, DEFAULT_FAV_CAT_5); - favCat[6] = sSettingsPre.getString(KEY_FAV_CAT_6, DEFAULT_FAV_CAT_6); - favCat[7] = sSettingsPre.getString(KEY_FAV_CAT_7, DEFAULT_FAV_CAT_7); - favCat[8] = sSettingsPre.getString(KEY_FAV_CAT_8, DEFAULT_FAV_CAT_8); - favCat[9] = sSettingsPre.getString(KEY_FAV_CAT_9, DEFAULT_FAV_CAT_9); - return favCat; - } - - public static void putFavCat(String[] value) { - AssertUtilsKt.assertEquals(10, value.length); + fun putFavCat(value: Array) { + check(value.size == 10) sSettingsPre.edit() - .putString(KEY_FAV_CAT_0, value[0]) - .putString(KEY_FAV_CAT_1, value[1]) - .putString(KEY_FAV_CAT_2, value[2]) - .putString(KEY_FAV_CAT_3, value[3]) - .putString(KEY_FAV_CAT_4, value[4]) - .putString(KEY_FAV_CAT_5, value[5]) - .putString(KEY_FAV_CAT_6, value[6]) - .putString(KEY_FAV_CAT_7, value[7]) - .putString(KEY_FAV_CAT_8, value[8]) - .putString(KEY_FAV_CAT_9, value[9]) - .apply(); + .putString(KEY_FAV_CAT_0, value[0]) + .putString(KEY_FAV_CAT_1, value[1]) + .putString(KEY_FAV_CAT_2, value[2]) + .putString(KEY_FAV_CAT_3, value[3]) + .putString(KEY_FAV_CAT_4, value[4]) + .putString(KEY_FAV_CAT_5, value[5]) + .putString(KEY_FAV_CAT_6, value[6]) + .putString(KEY_FAV_CAT_7, value[7]) + .putString(KEY_FAV_CAT_8, value[8]) + .putString(KEY_FAV_CAT_9, value[9]) + .apply() } - public static int[] getFavCount() { - int[] favCount = new int[10]; - favCount[0] = sSettingsPre.getInt(KEY_FAV_COUNT_0, DEFAULT_FAV_COUNT); - favCount[1] = sSettingsPre.getInt(KEY_FAV_COUNT_1, DEFAULT_FAV_COUNT); - favCount[2] = sSettingsPre.getInt(KEY_FAV_COUNT_2, DEFAULT_FAV_COUNT); - favCount[3] = sSettingsPre.getInt(KEY_FAV_COUNT_3, DEFAULT_FAV_COUNT); - favCount[4] = sSettingsPre.getInt(KEY_FAV_COUNT_4, DEFAULT_FAV_COUNT); - favCount[5] = sSettingsPre.getInt(KEY_FAV_COUNT_5, DEFAULT_FAV_COUNT); - favCount[6] = sSettingsPre.getInt(KEY_FAV_COUNT_6, DEFAULT_FAV_COUNT); - favCount[7] = sSettingsPre.getInt(KEY_FAV_COUNT_7, DEFAULT_FAV_COUNT); - favCount[8] = sSettingsPre.getInt(KEY_FAV_COUNT_8, DEFAULT_FAV_COUNT); - favCount[9] = sSettingsPre.getInt(KEY_FAV_COUNT_9, DEFAULT_FAV_COUNT); - return favCount; - } + val favCount: IntArray + get() = intArrayOf( + sSettingsPre.getInt(KEY_FAV_COUNT_0, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_1, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_2, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_3, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_4, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_5, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_6, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_7, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_8, DEFAULT_FAV_COUNT), + sSettingsPre.getInt(KEY_FAV_COUNT_9, DEFAULT_FAV_COUNT) + ) - public static void putFavCount(int[] count) { - AssertUtilsKt.assertEquals(10, count.length); + fun putFavCount(count: IntArray) { + check(count.size == 10) sSettingsPre.edit() - .putInt(KEY_FAV_COUNT_0, count[0]) - .putInt(KEY_FAV_COUNT_1, count[1]) - .putInt(KEY_FAV_COUNT_2, count[2]) - .putInt(KEY_FAV_COUNT_3, count[3]) - .putInt(KEY_FAV_COUNT_4, count[4]) - .putInt(KEY_FAV_COUNT_5, count[5]) - .putInt(KEY_FAV_COUNT_6, count[6]) - .putInt(KEY_FAV_COUNT_7, count[7]) - .putInt(KEY_FAV_COUNT_8, count[8]) - .putInt(KEY_FAV_COUNT_9, count[9]) - .apply(); + .putInt(KEY_FAV_COUNT_0, count[0]) + .putInt(KEY_FAV_COUNT_1, count[1]) + .putInt(KEY_FAV_COUNT_2, count[2]) + .putInt(KEY_FAV_COUNT_3, count[3]) + .putInt(KEY_FAV_COUNT_4, count[4]) + .putInt(KEY_FAV_COUNT_5, count[5]) + .putInt(KEY_FAV_COUNT_6, count[6]) + .putInt(KEY_FAV_COUNT_7, count[7]) + .putInt(KEY_FAV_COUNT_8, count[8]) + .putInt(KEY_FAV_COUNT_9, count[9]) + .apply() } - public static int getFavLocalCount() { - return sSettingsPre.getInt(KEY_FAV_LOCAL, DEFAULT_FAV_COUNT); + val favLocalCount: Int + get() = sSettingsPre.getInt(KEY_FAV_LOCAL, DEFAULT_FAV_COUNT) + + fun putFavLocalCount(count: Int) { + sSettingsPre.edit().putInt(KEY_FAV_LOCAL, count).apply() } - public static void putFavLocalCount(int count) { - sSettingsPre.edit().putInt(KEY_FAV_LOCAL, count).apply(); + val favCloudCount: Int + get() = sSettingsPre.getInt(KEY_FAV_CLOUD, DEFAULT_FAV_COUNT) + + fun putFavCloudCount(count: Int) { + sSettingsPre.edit().putInt(KEY_FAV_CLOUD, count).apply() } - public static int getFavCloudCount() { - return sSettingsPre.getInt(KEY_FAV_CLOUD, DEFAULT_FAV_COUNT); + val recentFavCat: Int + get() = getInt(KEY_RECENT_FAV_CAT, DEFAULT_RECENT_FAV_CAT) + + fun putRecentFavCat(value: Int) { + putInt(KEY_RECENT_FAV_CAT, value) } - public static void putFavCloudCount(int count) { - sSettingsPre.edit().putInt(KEY_FAV_CLOUD, count).apply(); + val defaultFavSlot: Int + get() = getInt(KEY_DEFAULT_FAV_SLOT, DEFAULT_DEFAULT_FAV_SLOT) + + fun putDefaultFavSlot(value: Int) { + putInt(KEY_DEFAULT_FAV_SLOT, value) } - public static int getRecentFavCat() { - return getInt(KEY_RECENT_FAV_CAT, DEFAULT_RECENT_FAV_CAT); + val qSSaveProgress: Boolean + get() = getBoolean(KEY_QS_SAVE_PROGRESS, DEFAULT_QS_SAVE_PROGRESS) + + fun putQSSaveProgress(value: Boolean) { + putBoolean(KEY_QS_SAVE_PROGRESS, value) } - public static void putRecentFavCat(int value) { - putInt(KEY_RECENT_FAV_CAT, value); + val saveParseErrorBody: Boolean + get() = getBoolean(KEY_SAVE_PARSE_ERROR_BODY, DEFAULT_SAVE_PARSE_ERROR_BODY) + val saveCrashLog: Boolean + get() = getBoolean(KEY_SAVE_CRASH_LOG, DEFAULT_SAVE_CRASH_LOG) + val security: Boolean + get() = getBoolean(KEY_SECURITY, false) + + fun putSecurity(value: Boolean) { + putBoolean(KEY_SECURITY, value) } - public static int getDefaultFavSlot() { - return getInt(KEY_DEFAULT_FAV_SLOT, DEFAULT_DEFAULT_FAV_SLOT); + val securityDelay: Int + 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) } - public static void putDefaultFavSlot(int value) { - putInt(KEY_DEFAULT_FAV_SLOT, value); + val dF: Boolean + get() = getBoolean(KEY_DOMAIN_FRONTING, DEFAULT_FRONTING) + + private fun putDF(value: Boolean) { + putBoolean(KEY_DOMAIN_FRONTING, value) } - public static boolean getQSSaveProgress() { - return getBoolean(KEY_QS_SAVE_PROGRESS, DEFAULT_QS_SAVE_PROGRESS); + 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) } - public static void putQSSaveProgress(boolean value) { - putBoolean(KEY_QS_SAVE_PROGRESS, value); + @JvmStatic + val proxyIp: String? + get() = getString(KEY_PROXY_IP, DEFAULT_PROXY_IP) + + fun putProxyIp(value: String?) { + putString(KEY_PROXY_IP, value) } - public static boolean getSaveParseErrorBody() { - return getBoolean(KEY_SAVE_PARSE_ERROR_BODY, DEFAULT_SAVE_PARSE_ERROR_BODY); + @JvmStatic + val proxyPort: Int + get() = getInt(KEY_PROXY_PORT, DEFAULT_PROXY_PORT) + + fun putProxyPort(value: Int) { + putInt(KEY_PROXY_PORT, value) } - public static boolean getSaveCrashLog() { - return getBoolean(KEY_SAVE_CRASH_LOG, DEFAULT_SAVE_CRASH_LOG); + 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) } - public static boolean getSecurity() { - return getBoolean(KEY_SECURITY, false); + val archivePasswds: Set? + get() = getStringSet(KEY_ARCHIVE_PASSWDS) + + fun putPasswdToArchivePasswds(value: String) { + putStringToStringSet(KEY_ARCHIVE_PASSWDS, value) } - public static void putSecurity(boolean value) { - putBoolean(KEY_SECURITY, value); - } - - public static int getSecurityDelay() { - return getInt(KEY_SECURITY_DELAY, 0); - } - - public static int getReadCacheSize() { - return getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE); - } - - public static boolean getBuiltInHosts() { - return getBoolean(KEY_BUILT_IN_HOSTS, DEFAULT_BUILT_IN_HOSTS); - } - - public static void putBuiltInHosts(boolean value) { - putBoolean(KEY_BUILT_IN_HOSTS, value); - } - - public static boolean getDF() { - return getBoolean(KEY_DOMAIN_FRONTING, DEFAULT_FRONTING); - } - - public static void putDF(boolean value) { - putBoolean(KEY_DOMAIN_FRONTING, value); - } - - public static boolean getBypassVpn() { - return getBoolean(KEY_BYPASS_VPN, DEFAULT_BYPASS_VPN); - } - - public static int getProxyType() { - return getInt(KEY_PROXY_TYPE, DEFAULT_PROXY_TYPE); - } - - public static void putProxyType(int value) { - putInt(KEY_PROXY_TYPE, value); - } - - public static String getProxyIp() { - return getString(KEY_PROXY_IP, DEFAULT_PROXY_IP); - } - - public static void putProxyIp(String value) { - putString(KEY_PROXY_IP, value); - } - - public static int getProxyPort() { - return getInt(KEY_PROXY_PORT, DEFAULT_PROXY_PORT); - } - - public static void putProxyPort(int value) { - putInt(KEY_PROXY_PORT, value); - } - - public static int getClipboardTextHashCode() { - return getInt(KEY_CLIPBOARD_TEXT_HASH_CODE, DEFAULT_CLIPBOARD_TEXT_HASH_CODE); - } - - public static void putClipboardTextHashCode(int value) { - putInt(KEY_CLIPBOARD_TEXT_HASH_CODE, value); - } - - public static Set getArchivePasswds() { - return getStringSet(KEY_ARCHIVE_PASSWDS); - } - - public static void putPasswdToArchivePasswds(String value) { - putStringToStringSet(KEY_ARCHIVE_PASSWDS, value); - } - - public static int getListThumbSize() { - if (LIST_THUMB_SIZE_INITED) { - return LIST_THUMB_SIZE; + val listThumbSize: Int + get() { + if (LIST_THUMB_SIZE_INITED) { + return LIST_THUMB_SIZE + } + val size = 3 * getInt(KEY_LIST_THUMB_SIZE, DEFAULT_LIST_THUMB_SIZE) + LIST_THUMB_SIZE = size + LIST_THUMB_SIZE_INITED = true + return size } - int size = 3 * getInt(KEY_LIST_THUMB_SIZE, DEFAULT_LIST_THUMB_SIZE); - LIST_THUMB_SIZE = size; - LIST_THUMB_SIZE_INITED = true; - return size; - } + val notificationRequired: Boolean + get() = getBoolean(KEY_NOTIFICATION_REQUIRED, false) - public static boolean getNotificationRequired() { - return getBoolean(KEY_NOTIFICATION_REQUIRED, false); + fun putNotificationRequired() { + putBoolean(KEY_NOTIFICATION_REQUIRED, true) } - - public static void putNotificationRequired() { - putBoolean(KEY_NOTIFICATION_REQUIRED, true); - } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhDns.kt b/app/src/main/java/com/hippo/ehviewer/client/EhDns.kt index f41a3c3a8..f5a00dd2e 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhDns.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhDns.kt @@ -114,17 +114,17 @@ object EhDns : Dns { vararg ips: Pair ) { map[host] = ips.mapNotNull { pair -> - Hosts.toInetAddress(host, pair.first).takeUnless { Settings.getDF() && pair.second } + Hosts.toInetAddress(host, pair.first).takeUnless { Settings.dF && pair.second } } } @Throws(UnknownHostException::class) override fun lookup(hostname: String): List { - return hosts[hostname] ?: builtInHosts[hostname].takeIf { Settings.getBuiltInHosts() } + return hosts[hostname] ?: builtInHosts[hostname].takeIf { Settings.builtInHosts } ?: Dns.SYSTEM.lookup(hostname) } fun isInHosts(hostname: String): Boolean { - return hosts.contains(hostname) || (builtInHosts.contains(hostname) && Settings.getBuiltInHosts()) + return hosts.contains(hostname) || (builtInHosts.contains(hostname) && Settings.builtInHosts) } } diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt index ac8de4572..d8d90198f 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt @@ -109,7 +109,7 @@ object EhEngine { } else if (body != null && !body.contains("<")) { throw EhException(body) } else { - if (Settings.getSaveParseErrorBody()) { + if (Settings.saveParseErrorBody) { AppConfig.saveParseErrorBody(e as ParseException?) } throw EhException(GetText.getString(R.string.error_parse_error)) @@ -186,7 +186,7 @@ object EhEngine { } } val needApi = - filter && sEhFilter.needTags() && !hasTags || Settings.getShowGalleryPages() && !hasPages || + filter && sEhFilter.needTags() && !hasTags || Settings.showGalleryPages && !hasPages || hasRated if (needApi) { fillGalleryListByApi(list, url) diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhUrl.kt b/app/src/main/java/com/hippo/ehviewer/client/EhUrl.kt index 7be84f565..a0933e477 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhUrl.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhUrl.kt @@ -55,21 +55,21 @@ object EhUrl { const val URL_PREFIX_THUMB_EX = "https://exhentai.org/t/" val host: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> HOST_E SITE_EX -> HOST_EX else -> HOST_E } val favoritesUrl: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> URL_FAVORITES_E SITE_EX -> URL_FAVORITES_EX else -> URL_FAVORITES_E } val apiUrl: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> API_E SITE_EX -> API_EX else -> API_E @@ -77,14 +77,14 @@ object EhUrl { @JvmStatic val referer: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> REFERER_E SITE_EX -> REFERER_EX else -> REFERER_E } val origin: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> ORIGIN_E SITE_EX -> ORIGIN_EX else -> ORIGIN_E @@ -92,7 +92,7 @@ object EhUrl { @JvmStatic val uConfigUrl: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> URL_UCONFIG_E SITE_EX -> URL_UCONFIG_EX else -> URL_UCONFIG_E @@ -100,28 +100,28 @@ object EhUrl { @JvmStatic val myTagsUrl: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> URL_MY_TAGS_E SITE_EX -> URL_MY_TAGS_EX else -> URL_MY_TAGS_E } val popularUrl: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> URL_POPULAR_E SITE_EX -> URL_POPULAR_EX else -> URL_POPULAR_E } val imageSearchUrl: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> URL_IMAGE_SEARCH_E SITE_EX -> URL_IMAGE_SEARCH_EX else -> URL_IMAGE_SEARCH_E } val watchedUrl: String - get() = when (Settings.getGallerySite()) { + get() = when (Settings.gallerySite) { SITE_E -> URL_WATCHED_E SITE_EX -> URL_WATCHED_EX else -> URL_WATCHED_E @@ -167,7 +167,7 @@ object EhUrl { } fun getThumbUrlPrefix(): String { - return when (Settings.getGallerySite()) { + return when (Settings.gallerySite) { SITE_E -> URL_PREFIX_THUMB_E SITE_EX -> URL_PREFIX_THUMB_EX else -> URL_PREFIX_THUMB_E diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhUtils.kt b/app/src/main/java/com/hippo/ehviewer/client/EhUtils.kt index 619f0f607..be763fca4 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhUtils.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhUtils.kt @@ -78,7 +78,7 @@ object EhUtils { private val CATEGORY_STRINGS = CATEGORY_VALUES.entries.map { (k, v) -> v to k } val isExHentai: Boolean - get() = Settings.getGallerySite() == EhUrl.SITE_EX + get() = Settings.gallerySite == EhUrl.SITE_EX @JvmStatic fun getCategory(type: String?): Int { @@ -120,12 +120,12 @@ object EhUtils { } fun needSignedIn(): Boolean { - return Settings.getNeedSignIn() && !ehCookieStore.hasSignedIn() + return Settings.needSignIn && !ehCookieStore.hasSignedIn() } @JvmStatic fun getSuitableTitle(gi: GalleryInfo): String { - return if (Settings.getShowJpnTitle()) { + return if (Settings.showJpnTitle) { if (TextUtils.isEmpty(gi.titleJpn)) gi.title else gi.titleJpn } else { if (TextUtils.isEmpty(gi.title)) gi.titleJpn else gi.title @@ -156,7 +156,7 @@ object EhUtils { if (null == url) { return null } - val resolution = when (Settings.getThumbResolution()) { + val resolution = when (Settings.thumbResolution) { 0 -> return url 1 -> "250" 2 -> "300" diff --git a/app/src/main/java/com/hippo/ehviewer/dailycheck/DailyCheckWork.kt b/app/src/main/java/com/hippo/ehviewer/dailycheck/DailyCheckWork.kt index e76a62a5e..123a23ecf 100644 --- a/app/src/main/java/com/hippo/ehviewer/dailycheck/DailyCheckWork.kt +++ b/app/src/main/java/com/hippo/ehviewer/dailycheck/DailyCheckWork.kt @@ -43,7 +43,7 @@ class DailyCheckWork(val context: Context, workerParams: WorkerParameters) : @SuppressLint("MissingPermission") private fun showEventPane(html: String) { - if (Settings.getHideHvEvents() && html.contains("You have encountered a monster!")) { + if (Settings.hideHvEvents && html.contains("You have encountered a monster!")) { return } val notificationManager = NotificationManagerCompat.from(context) @@ -93,7 +93,7 @@ private fun getDailyCheckWorkRequest(): PeriodicWorkRequest { private const val workName = "DailyCheckWork" fun updateDailyCheckWork(context: Context) { - if (Settings.getRequestNews()) { + if (Settings.requestNews) { WorkManager.getInstance(context).enqueueUniquePeriodicWork( workName, ExistingPeriodicWorkPolicy.UPDATE, diff --git a/app/src/main/java/com/hippo/ehviewer/gallery/ArchivePageLoader.kt b/app/src/main/java/com/hippo/ehviewer/gallery/ArchivePageLoader.kt index b73661905..fe13a5f10 100644 --- a/app/src/main/java/com/hippo/ehviewer/gallery/ArchivePageLoader.kt +++ b/app/src/main/java/com/hippo/ehviewer/gallery/ArchivePageLoader.kt @@ -49,7 +49,7 @@ class ArchivePageLoader(context: Context, uri: Uri, passwdFlow: Flow) : } archiveAccessor.run { if (needPassword()) { - Settings.getArchivePasswds()?.forEach { + Settings.archivePasswds?.forEach { if (providePassword(it)) return@launch } passwdFlow.collect { diff --git a/app/src/main/java/com/hippo/ehviewer/preference/CleanRedundancyPreference.kt b/app/src/main/java/com/hippo/ehviewer/preference/CleanRedundancyPreference.kt index cbd97487f..4dd6ab2b0 100644 --- a/app/src/main/java/com/hippo/ehviewer/preference/CleanRedundancyPreference.kt +++ b/app/src/main/java/com/hippo/ehviewer/preference/CleanRedundancyPreference.kt @@ -52,7 +52,7 @@ class CleanRedundancyPreference @JvmOverloads constructor( } private fun doRealWork(): Int { - return Settings.getDownloadLocation()?.listFiles()?.sumOf { clearFile(it).compareTo(false) } ?: 0 + return Settings.downloadLocation?.listFiles()?.sumOf { clearFile(it).compareTo(false) } ?: 0 } override fun launchJob() { 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 bce06eaf1..9ff186c78 100644 --- a/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt +++ b/app/src/main/java/com/hippo/ehviewer/preference/ProxyPreference.kt @@ -47,7 +47,7 @@ class ProxyPreference @JvmOverloads constructor( init { mArray = context.resources.getStringArray(R.array.proxy_types) dialogLayoutResource = R.layout.preference_dialog_proxy - updateSummary(Settings.getProxyType(), Settings.getProxyIp(), Settings.getProxyPort()) + updateSummary(Settings.proxyType, Settings.proxyIp, Settings.proxyPort) } private fun getProxyTypeText(type: Int): String { @@ -93,7 +93,7 @@ class ProxyPreference @JvmOverloads constructor( mIp = ViewUtils.`$$`(dialog, R.id.ip) as EditText mPortInputLayout = ViewUtils.`$$`(dialog, R.id.port_input_layout) as TextInputLayout mPort = ViewUtils.`$$`(dialog, R.id.port) as EditText - val type = Settings.getProxyType() + val type = Settings.proxyType (mType!!.editText as AutoCompleteTextView).setText( array[MathUtils.clamp( type, @@ -101,9 +101,9 @@ class ProxyPreference @JvmOverloads constructor( array.size )], false ) - mIp!!.setText(Settings.getProxyIp()) + mIp!!.setText(Settings.proxyIp) val portString: String? - val port = Settings.getProxyPort() + val port = Settings.proxyPort portString = if (!InetValidator.isValidInetPort(port)) { null } else { diff --git a/app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt b/app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt index 6c0aca96a..13668d697 100644 --- a/app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt +++ b/app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt @@ -71,7 +71,7 @@ class RestoreDownloadPreference @JvmOverloads constructor( } private suspend fun doRealWork(): List? { - val dir = Settings.getDownloadLocation() ?: return null + val dir = Settings.downloadLocation ?: return null val files = dir.listFiles() ?: return null val restoreItemList = files.mapNotNull { getRestoreItem(it) } return runSuspendCatching { diff --git a/app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.kt b/app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.kt index ce891b572..6dc1ed3f3 100644 --- a/app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.kt +++ b/app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.kt @@ -303,14 +303,14 @@ class SpiderDen(private val mGalleryInfo: GalleryInfo) { private val sCache by lazy { DiskCache.Builder().directory(File(application.cacheDir, "gallery_image")) .maxSizeBytes( - MathUtils.clamp(Settings.getReadCacheSize(), 40, 1280).toLong() * 1024 * 1024 + MathUtils.clamp(Settings.readCacheSize, 40, 1280).toLong() * 1024 * 1024 ).build() } private val COMPAT_IMAGE_EXTENSIONS = SUPPORT_IMAGE_EXTENSIONS + ".jpeg" fun getGalleryDownloadDir(gid: Long): UniFile? { - val dir = Settings.getDownloadLocation() + val dir = Settings.downloadLocation // Read from DB var dirname = EhDB.getDownloadDirname(gid) return if (dir != null && dirname != null) { diff --git a/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.kt b/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.kt index 0b0499ee1..7e5ce92bb 100644 --- a/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.kt +++ b/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.kt @@ -527,11 +527,11 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS private val mWorkerScope = object { private val mFetcherJobMap = hashMapOf() - private val mSemaphore = Semaphore(Settings.getMultiThreadDownload()) + private val mSemaphore = Semaphore(Settings.multiThreadDownload) private val pTokenLock = Mutex() private var showKey: String? = null private val showKeyLock = Mutex() - private val mDownloadDelay = Settings.getDownloadDelay() + private val mDownloadDelay = Settings.downloadDelay private var isDownloadMode = false fun cancelDecode(index: Int) { @@ -721,7 +721,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS val targetImageUrl: String? val referer: String? - if (Settings.getDownloadOriginImage() && !originImageUrl.isNullOrBlank()) { + if (Settings.downloadOriginImage && !originImageUrl.isNullOrBlank()) { targetImageUrl = originImageUrl referer = EhUrl.getPageUrl(mSpiderInfo.gid, index, pToken) } else { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt index b7cd36328..1e802e52e 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt @@ -68,9 +68,9 @@ object CommonOperations { activity: Activity, galleryInfo: GalleryInfo, listener: EhClient.Callback, select: Boolean = false ) { - val slot = Settings.getDefaultFavSlot() + val slot = Settings.defaultFavSlot val localFav = activity.getString(R.string.local_favorites) - val items = Settings.getFavCat().toMutableList().apply { add(0, localFav) } + val items = Settings.favCat.toMutableList().apply { add(0, localFav) } if (!select && slot >= -1 && slot <= 9) { val newFavoriteName = if (slot >= 0) items[slot + 1] else null doAddToFavorites( @@ -159,8 +159,8 @@ object CommonOperations { var justStart = forceDefault var label: String? = null // Get default download label - if (!justStart && Settings.getHasDefaultDownloadLabel()) { - label = Settings.getDefaultDownloadLabel() + if (!justStart && Settings.hasDefaultDownloadLabel) { + label = Settings.defaultDownloadLabel justStart = label == null || dm.containLabel(label) } // If there is no other label, just use null label diff --git a/app/src/main/java/com/hippo/ehviewer/ui/EhActivity.kt b/app/src/main/java/com/hippo/ehviewer/ui/EhActivity.kt index 4e17b2864..a9d7576b3 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/EhActivity.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/EhActivity.kt @@ -37,8 +37,7 @@ import rikka.layoutinflater.view.LayoutInflaterFactory abstract class EhActivity : AppCompatActivity() { @StyleRes fun getThemeStyleRes(): Int { - val isBlackDarkTheme = Settings.getBoolean("black_dark_theme", false) - return if (isBlackDarkTheme && isNightMode()) R.style.ThemeOverlay_Black else R.style.ThemeOverlay + return if (Settings.blackDarkTheme && isNightMode()) R.style.ThemeOverlay_Black else R.style.ThemeOverlay } override fun onApplyThemeResource(theme: Theme, resid: Int, first: Boolean) { @@ -65,13 +64,13 @@ abstract class EhActivity : AppCompatActivity() { override fun onResume() { val lockedResumeTime = System.currentTimeMillis() / 1000 val lockedDelayTime = lockedResumeTime - EhApplication.locked_last_leave_time - if (lockedDelayTime < Settings.getSecurityDelay() * 60) { + if (lockedDelayTime < Settings.securityDelay * 60) { EhApplication.locked = false - } else if (Settings.getSecurity() && isAuthenticationSupported() && EhApplication.locked) { + } else if (Settings.security && isAuthenticationSupported() && EhApplication.locked) { startActivity(Intent(this, SecurityActivity::class.java)) } super.onResume() - window.setSecureScreen(Settings.getEnabledSecurity()) + window.setSecureScreen(Settings.enabledSecurity) } private val requestPermissionLauncher = @@ -84,7 +83,7 @@ abstract class EhActivity : AppCompatActivity() { Manifest.permission.POST_NOTIFICATIONS ) == PackageManager.PERMISSION_GRANTED ) return - if (Settings.getNotificationRequired()) return + if (Settings.notificationRequired) return requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) } } 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 3f88e546f..acf1d208d 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.kt @@ -212,7 +212,7 @@ class MainActivity : EhActivity() { private fun setNavGraph() { navController.apply { graph = navInflater.inflate(R.navigation.nav_graph).apply { - when (Settings.getLaunchPageGalleryListSceneAction()) { + when (Settings.launchPageGalleryListSceneAction) { GalleryListScene.ACTION_HOMEPAGE -> setStartDestination(R.id.nav_homepage) GalleryListScene.ACTION_SUBSCRIPTION -> setStartDestination(R.id.nav_subscription) GalleryListScene.ACTION_WHATS_HOT -> setStartDestination(R.id.nav_whats_hot) @@ -223,7 +223,7 @@ class MainActivity : EhActivity() { } override fun onCreate(savedInstanceState: Bundle?) { - if (Settings.getDF() && Settings.getBypassVpn()) { + if (Settings.dF && Settings.bypassVpn) { bypassVpn() } super.onCreate(savedInstanceState) @@ -260,11 +260,11 @@ class MainActivity : EhActivity() { onNewIntent(intent) } checkDownloadLocation() - if (Settings.getMeteredNetworkWarning()) { + if (Settings.meteredNetworkWarning) { checkMeteredNetwork() } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (!Settings.getAppLinkVerifyTip()) { + if (!Settings.appLinkVerifyTip) { try { checkAppLinkVerify() } catch (ignored: PackageManager.NameNotFoundException) { @@ -332,7 +332,7 @@ class MainActivity : EhActivity() { } private fun checkDownloadLocation() { - val uniFile = Settings.getDownloadLocation() + val uniFile = Settings.downloadLocation // null == uniFile for first start if (null == uniFile || uniFile.ensureDir()) { return @@ -391,7 +391,7 @@ class MainActivity : EhActivity() { private suspend fun checkClipboardUrl() { val text = this.getClipboardManager().getUrlFromClipboard(this) val hashCode = text?.hashCode() ?: 0 - if (text != null && hashCode != 0 && Settings.getClipboardTextHashCode() != hashCode) { + if (text != null && hashCode != 0 && Settings.clipboardTextHashCode != hashCode) { val result1 = GalleryDetailUrlParser.parse(text, false) var launch: (() -> Unit)? = null if (result1 != null) { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.kt b/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.kt index 5605dcce5..8c94c85a4 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.kt @@ -246,7 +246,7 @@ class AdvancedFragment : BasePreferenceFragment() { exportData!!.onPreferenceClickListener = this backupFavorite!!.onPreferenceClickListener = this appLanguage!!.onPreferenceChangeListener = this - bypassVpn!!.isVisible = AppSettings.getDF() + bypassVpn!!.isVisible = AppSettings.dF domainFronting!!.setOnPreferenceChangeListener { _, newValue -> bypassVpn.isVisible = newValue as Boolean true @@ -342,7 +342,7 @@ class AdvancedFragment : BasePreferenceFragment() { if (result.next != null) { try { runBlocking { - delay(AppSettings.getDownloadDelay().toLong()) + delay(AppSettings.downloadDelay.toLong()) } } catch (e: InterruptedException) { e.printStackTrace() diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/DownloadFragment.kt b/app/src/main/java/com/hippo/ehviewer/ui/fragment/DownloadFragment.kt index 3b6cce1e2..5abab92aa 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/DownloadFragment.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/DownloadFragment.kt @@ -70,7 +70,7 @@ class DownloadFragment : BasePreferenceFragment() { } private fun onUpdateDownloadLocation() { - val file = Settings.getDownloadLocation() + val file = Settings.downloadLocation if (mDownloadLocation != null) { if (file != null) { mDownloadLocation!!.summary = file.uri.toString() @@ -83,9 +83,9 @@ class DownloadFragment : BasePreferenceFragment() { override fun onPreferenceClick(preference: Preference): Boolean { val key = preference.key if (KEY_DOWNLOAD_LOCATION == key) { - val file = Settings.getDownloadLocation() + val file = Settings.downloadLocation if (file != null && !UniFile.isFileUri( - Settings.getDownloadLocation()!!.uri + Settings.downloadLocation!!.uri ) ) { BaseDialogBuilder(requireContext()) @@ -126,7 +126,7 @@ class DownloadFragment : BasePreferenceFragment() { val key = preference.key if (Settings.KEY_MEDIA_SCAN == key) { if (newValue is Boolean) { - val downloadLocation = Settings.getDownloadLocation() + val downloadLocation = Settings.downloadLocation if (newValue) { removeNoMediaFile(downloadLocation) } else { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/EhFragment.kt b/app/src/main/java/com/hippo/ehviewer/ui/fragment/EhFragment.kt index 0d042886c..f05ca8b34 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/EhFragment.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/EhFragment.kt @@ -50,7 +50,7 @@ class EhFragment : BasePreferenceFragment() { val thumbResolution = findPreference(Settings.KEY_THUMB_RESOLUTION) val showTagTranslations = findPreference(Settings.KEY_SHOW_TAG_TRANSLATIONS) val tagTranslationsSource = findPreference(Settings.KEY_TAG_TRANSLATIONS_SOURCE) - Settings.getDisplayName()?.let { account?.summary = it } + Settings.displayName?.let { account?.summary = it } theme!!.onPreferenceChangeListener = this gallerySite!!.onPreferenceChangeListener = this listMode!!.onPreferenceChangeListener = this diff --git a/app/src/main/java/com/hippo/ehviewer/ui/login/LoginActivity.kt b/app/src/main/java/com/hippo/ehviewer/ui/login/LoginActivity.kt index 3cfcc7d74..dc1b17926 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/login/LoginActivity.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/login/LoginActivity.kt @@ -43,7 +43,7 @@ class LoginActivity : EhActivity() { } composable(SELECT_SITE_ROUTE_NAME) { - val selectSite by remember { mutableStateOf(Settings.getSelectSite()) } + val selectSite by remember { mutableStateOf(Settings.selectSite) } if (selectSite) { SelectSiteScreen() } else { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt index 2488991d4..51def9926 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadsScene.kt @@ -215,7 +215,7 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe private fun onInit() { if (!handleArguments(arguments)) { - mLabel = Settings.getRecentDownloadLabel() + mLabel = Settings.recentDownloadLabel updateForLabel() } } @@ -253,7 +253,7 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe mAdapter!!.setHasStableIds(true) mRecyclerView!!.adapter = mAdapter mLayoutManager = AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL) - mLayoutManager!!.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId())) + mLayoutManager!!.setColumnSize(resources.getDimensionPixelOffset(Settings.detailSizeResId)) mLayoutManager!!.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE) mRecyclerView!!.layoutManager = mLayoutManager //mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !ResourcesKt.resolveColor(getTheme(), .getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT))); @@ -579,7 +579,7 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe context, getString(R.string.download_remove_dialog_message_2, gidList!!.size), getString(R.string.download_remove_dialog_check_text), - Settings.getRemoveImageFiles() + Settings.removeImageFiles ) val helper = DeleteRangeDialogHelper( downloadInfoList!!, gidList, builder diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt index 9fbaf9cc9..c345ebc26 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/FavoritesScene.kt @@ -96,9 +96,9 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen private var mClient: EhClient? = null - private var mFavCatArray: Array? = Settings.getFavCat() + private var mFavCatArray: Array? = Settings.favCat - private var mFavCountArray: IntArray? = Settings.getFavCount() + private var mFavCountArray: IntArray? = Settings.favCount private var mUrlBuilder: FavListUrlBuilder? = null private val showNormalFabsRunnable = Runnable { @@ -132,8 +132,8 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mClient = EhClient - mFavLocalCount = Settings.getFavLocalCount() - mFavCountSum = Settings.getFavCloudCount() + mFavLocalCount = Settings.favLocalCount + mFavCountSum = Settings.favCloudCount if (savedInstanceState == null) { onInit() } else { @@ -143,7 +143,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen private fun onInit() { mUrlBuilder = FavListUrlBuilder() - mUrlBuilder!!.favCat = Settings.getRecentFavCat() + mUrlBuilder!!.favCat = Settings.recentFavCat } private fun onRestore(savedInstanceState: Bundle) { @@ -205,7 +205,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen mContentLayout.setHelper(mHelper) mContentLayout.fastScroller.setOnDragHandlerListener(this) mContentLayout.setFitPaddingTop(paddingTopSB) - mAdapter = FavoritesAdapter(inflater, resources, mRecyclerView!!, Settings.getListMode()) + mAdapter = FavoritesAdapter(inflater, resources, mRecyclerView!!, Settings.listMode) mRecyclerView!!.clipToPadding = false mRecyclerView!!.clipChildren = false mRecyclerView!!.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM) @@ -333,7 +333,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen val items = arrayOfNulls(12) items[0] = getString(R.string.let_me_select) items[1] = getString(R.string.local_favorites) - val favCat = Settings.getFavCat() + val favCat = Settings.favCat System.arraycopy(favCat, 0, items, 2, 10) BaseDialogBuilder(requireContext()) .setTitle(R.string.default_favorites_collection) @@ -548,7 +548,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen // First is local favorite, the other 10 is cloud favorite val array = arrayOfNulls(11) array[0] = getString(R.string.local_favorites) - System.arraycopy(Settings.getFavCat(), 0, array, 1, 10) + System.arraycopy(Settings.favCat, 0, array, 1, 10) BaseDialogBuilder(context) .setTitle(R.string.move_favorites_dialog_title) .setItems(array, helper) @@ -620,7 +620,7 @@ class FavoritesScene : SearchBarScene(), OnDragHandlerListener, OnClickFabListen private fun onGetFavoritesSuccess(result: FavoritesParser.Result, taskId: Int) { if (mHelper != null && mHelper!!.isCurrentTask(taskId)) { if (mFavCatArray != null) { - System.arraycopy(result.catArray, 0, mFavCatArray, 0, 10) + System.arraycopy(result.catArray, 0, mFavCatArray!!, 0, 10) } mFavCountArray = result.countArray if (mFavCountArray != null) { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt index 7a29c29b8..cb00549fb 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt @@ -64,7 +64,7 @@ internal abstract class GalleryAdapter( when (type) { TYPE_LIST -> { val columnWidth = - mResources.getDimensionPixelOffset(Settings.getDetailSizeResId()) + mResources.getDimensionPixelOffset(Settings.detailSizeResId) mLayoutManager.setColumnSize(columnWidth) mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE) if (null != mGirdDecoration) { @@ -86,7 +86,7 @@ internal abstract class GalleryAdapter( } TYPE_GRID -> { - val columnWidth = Settings.getThumbSize() + val columnWidth = Settings.thumbSize mLayoutManager.setColumnSize(columnWidth) mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_SUITABLE_SIZE) if (null != mListDecoration) { @@ -186,7 +186,7 @@ internal abstract class GalleryAdapter( category.setBackgroundColor(EhUtils.getCategoryColor(gi.category)) } holder.posted!!.text = gi.posted - if (gi.pages == 0 || !Settings.getShowGalleryPages()) { + if (gi.pages == 0 || !Settings.showGalleryPages) { holder.pages?.text = null holder.pages!!.visibility = View.GONE } else { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt index 2a39deced..c770738b0 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt @@ -397,7 +397,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl it.searchCover.setOnClickListener(this) } binding.content.actions.newerVersion.setOnClickListener(this) - if (Settings.getShowComments()) { + if (Settings.showComments) { binding.content.comments.comments.setOnClickListener(this) } else { binding.content.comments.comments.visibility = View.GONE @@ -618,7 +618,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl } tagGroups ?: return val ehTags = - if (Settings.getShowTagTranslations() && isTranslatable(requireContext())) EhTagDatabase else null + if (Settings.showTagTranslations && isTranslatable(requireContext())) EhTagDatabase else null val colorTag = theme.resolveColor(R.attr.tagBackgroundColor) val colorName = theme.resolveColor(R.attr.tagGroupBackgroundColor) for (tg in tagGroups) { @@ -719,7 +719,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl } else { previewText.setText(R.string.more_previews) } - val columnWidth = Settings.getThumbSize() + val columnWidth = Settings.thumbSize gridLayout.setColumnSize(columnWidth) gridLayout.setStrategy(SimpleGridAutoSpanLayout.STRATEGY_SUITABLE_SIZE) viewLifecycleOwner.lifecycleScope.launchIO { @@ -839,7 +839,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl context, getString(R.string.download_remove_dialog_message, galleryInfo.title), getString(R.string.download_remove_dialog_check_text), - Settings.getRemoveImageFiles() + Settings.removeImageFiles ) val helper = DeleteDialogHelper( downloadManager, galleryInfo, builder diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt index 164de988b..ae0d19ce6 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.kt @@ -364,7 +364,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H binding.contentLayout.setFitPaddingTop(paddingTopSB) mAdapter = GalleryListAdapter( inflater, resources, - binding.contentLayout.recyclerView, Settings.getListMode() + binding.contentLayout.recyclerView, Settings.listMode ) binding.contentLayout.recyclerView.clipToPadding = false binding.contentLayout.recyclerView.clipChildren = false @@ -474,7 +474,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H builder.setTitle(R.string.add_quick_search_dialog_title) builder.setPositiveButton(android.R.string.ok, null) // TODO: It's ugly - val checked = booleanArrayOf(Settings.getQSSaveProgress()) + val checked = booleanArrayOf(Settings.qSSaveProgress) val hint = arrayOf(getString(R.string.save_progress)) builder.setMultiChoiceItems( hint, diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt index b77a0d59e..161b77bcc 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt @@ -101,7 +101,7 @@ class GalleryPreviewsScene : BaseToolbarScene() { setLiftOnScrollTargetView(binding.contentLayout) mAdapter = GalleryPreviewAdapter() binding.contentLayout.recyclerView.adapter = mAdapter - val columnWidth = Settings.getThumbSize() + val columnWidth = Settings.thumbSize val layoutManager = AutoGridLayoutManager(context, columnWidth, LayoutUtils.dp2pix(context, 16f)) layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.kt index fa375a242..b86924533 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/HistoryScene.kt @@ -136,7 +136,7 @@ class HistoryScene : BaseToolbarScene() { }.flow.cachedIn(viewLifecycleOwner.lifecycleScope) binding.recyclerView.adapter = mAdapter val layoutManager = AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL) - layoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId())) + layoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.detailSizeResId)) layoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE) binding.recyclerView.layoutManager = layoutManager val itemTouchHelper = ItemTouchHelper(HistoryItemTouchHelperCallback()) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/SearchBarScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/SearchBarScene.kt index 902d10151..5111fd85d 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/SearchBarScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/SearchBarScene.kt @@ -320,7 +320,7 @@ abstract class SearchBarScene : BaseScene(), ToolBarScene { if (text.isNotEmpty() && !text.endsWith(' ')) { val keyword = text.substringAfterLast(' ') val translate = - Settings.getShowTagTranslations() && isTranslatable(requireContext()) + Settings.showTagTranslations && isTranslatable(requireContext()) suggestFlow(keyword, translate, true).collect { emit(TagSuggestion(it.first, it.second)) } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/widget/GalleryInfoCard.kt b/app/src/main/java/com/hippo/ehviewer/ui/widget/GalleryInfoCard.kt index 8d8573052..878207300 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/widget/GalleryInfoCard.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/widget/GalleryInfoCard.kt @@ -49,7 +49,7 @@ fun ListInfoCard( modifier = modifier.padding(6.dp), border = remember { BorderStroke(1.dp, Color.Transparent) } ) { - val listCardSize = remember { Settings.getListThumbSize().pxToDp } + val listCardSize = remember { Settings.listThumbSize.pxToDp } Row( modifier = Modifier .height((listCardSize * 3).dp) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/widget/GalleryListOperation.kt b/app/src/main/java/com/hippo/ehviewer/ui/widget/GalleryListOperation.kt index 1f40407dd..226e12f97 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/widget/GalleryListOperation.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/widget/GalleryListOperation.kt @@ -79,7 +79,7 @@ fun GalleryListLongClickDialog( val addToFavFailed = stringResource(id = R.string.add_to_favorite_failure) suspend fun addToFav(slot: Int) { - val favNameList = Settings.getFavCat().toMutableList().apply { add(0, localFavName) } + val favNameList = Settings.favCat.toMutableList().apply { add(0, localFavName) } runCatching { if (slot == -1) { EhDB.putLocalFavorites(info) @@ -151,7 +151,7 @@ fun GalleryListLongClickDialog( if (info.favoriteSlot == -2) { DialogSelectorItem( onClick = { - val defaultFav = Settings.getDefaultFavSlot() + val defaultFav = Settings.defaultFavSlot if (defaultFav in -1..9) { launchIO { addToFav(defaultFav) @@ -267,7 +267,7 @@ fun SelectFavouriteDialog( val localFavName = stringResource(id = R.string.local_favorites) Column { remember { - Settings.getFavCat().toMutableList().apply { add(0, localFavName) } + Settings.favCat.toMutableList().apply { add(0, localFavName) } }.forEachIndexed { index, s -> TextButton( onClick = { diff --git a/app/src/main/java/com/hippo/ehviewer/widget/ResizeableFixedThumb.kt b/app/src/main/java/com/hippo/ehviewer/widget/ResizeableFixedThumb.kt index 673adc281..a5a560561 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/ResizeableFixedThumb.kt +++ b/app/src/main/java/com/hippo/ehviewer/widget/ResizeableFixedThumb.kt @@ -8,6 +8,6 @@ class ResizeableFixedThumb @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null ) : FixedThumb(context, attrs) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - setMeasuredDimension(Settings.getListThumbSize() * 2, Settings.getListThumbSize() * 3) + setMeasuredDimension(Settings.listThumbSize * 2, Settings.listThumbSize * 3) } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/PageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/PageLoader.kt index 3399a59da..cc87db8e4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/PageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/PageLoader.kt @@ -16,7 +16,7 @@ abstract class PageLoader { (0 until size).map { ReaderPage(it) } } - private val mPreloads = MathUtils.clamp(com.hippo.ehviewer.Settings.getPreloadImage(), 0, 100) + private val mPreloads = MathUtils.clamp(com.hippo.ehviewer.Settings.preloadImage, 0, 100) abstract suspend fun awaitReady(): Boolean abstract val isReady: Boolean