From e9cb0836724da51dc4d837e16734c1b23414a65b Mon Sep 17 00:00:00 2001 From: tarsin Date: Thu, 1 Jun 2023 17:16:23 +0800 Subject: [PATCH] Move some property to delegate --- .../main/java/com/hippo/ehviewer/Settings.kt | 56 +++---------------- .../com/hippo/ehviewer/ui/CommonOperations.kt | 4 +- .../ehviewer/ui/fragment/PrivacyFragment.kt | 2 +- .../hippo/ehviewer/ui/scene/FavoritesScene.kt | 13 ++--- .../ehviewer/ui/scene/GalleryListScene.kt | 4 +- 5 files changed, 19 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt index 49125cc18..e6004a71e 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt @@ -506,54 +506,16 @@ object Settings : DefaultPreferences() { .apply() } - val favLocalCount: Int - get() = sSettingsPre.getInt(KEY_FAV_LOCAL, DEFAULT_FAV_COUNT) + var favLocalCount by intPref(KEY_FAV_LOCAL, DEFAULT_FAV_COUNT) + var favCloudCount by intPref(KEY_FAV_CLOUD, DEFAULT_FAV_COUNT) + var recentFavCat by intPref(KEY_RECENT_FAV_CAT, DEFAULT_RECENT_FAV_CAT) + var defaultFavSlot by intPref(KEY_DEFAULT_FAV_SLOT, DEFAULT_DEFAULT_FAV_SLOT) + var qSSaveProgress by boolPref(KEY_QS_SAVE_PROGRESS, DEFAULT_QS_SAVE_PROGRESS) + val saveParseErrorBody by boolPref(KEY_SAVE_PARSE_ERROR_BODY, DEFAULT_SAVE_PARSE_ERROR_BODY) + val saveCrashLog by boolPref(KEY_SAVE_CRASH_LOG, DEFAULT_SAVE_CRASH_LOG) + var security by boolPref(KEY_SECURITY, false) + val securityDelay by intPref(KEY_SECURITY_DELAY, 0) - fun putFavLocalCount(count: Int) { - 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() - } - - val recentFavCat: Int - get() = getInt(KEY_RECENT_FAV_CAT, DEFAULT_RECENT_FAV_CAT) - - fun putRecentFavCat(value: Int) { - putInt(KEY_RECENT_FAV_CAT, value) - } - - val defaultFavSlot: Int - get() = getInt(KEY_DEFAULT_FAV_SLOT, DEFAULT_DEFAULT_FAV_SLOT) - - fun putDefaultFavSlot(value: Int) { - putInt(KEY_DEFAULT_FAV_SLOT, value) - } - - val qSSaveProgress: Boolean - get() = getBoolean(KEY_QS_SAVE_PROGRESS, DEFAULT_QS_SAVE_PROGRESS) - - fun putQSSaveProgress(value: Boolean) { - putBoolean(KEY_QS_SAVE_PROGRESS, 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) - } - - val securityDelay: Int - get() = getInt(KEY_SECURITY_DELAY, 0) val readCacheSize: Int get() = getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE) 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 508c8e28e..ed31ce3a1 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.kt @@ -233,9 +233,9 @@ suspend fun Context.addToFavorites(galleryInfo: GalleryInfo, select: Boolean = f val newFavoriteName = if (slot1 in 0..9) items[slot1 + 1] else null doAddToFavorites(slot1, newFavoriteName) if (checked) { - Settings.putDefaultFavSlot(slot1) + Settings.defaultFavSlot = slot1 } else { - Settings.putDefaultFavSlot(Settings.INVALID_DEFAULT_FAV_SLOT) + Settings.defaultFavSlot = Settings.INVALID_DEFAULT_FAV_SLOT } } } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/PrivacyFragment.kt b/app/src/main/java/com/hippo/ehviewer/ui/fragment/PrivacyFragment.kt index dd45e4b61..e93b01ed7 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/PrivacyFragment.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/PrivacyFragment.kt @@ -50,7 +50,7 @@ class PrivacyFragment : BasePreferenceFragment() { override fun onStart() { super.onStart() if (!requireContext().isAuthenticationSupported()) { - Settings.putSecurity(false) + Settings.security = false requireUnlock.isEnabled = false requireUnlock.isChecked = false unlockDelay.isEnabled = false 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 4d53fab64..e56d6ee4e 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 @@ -214,7 +214,7 @@ class FavoritesScene : mContentLayout.setHelper(mHelper!!) mContentLayout.fastScroller.setOnDragHandlerListener(this) mContentLayout.setFitPaddingTop(paddingTopSB) - mAdapter = FavoritesAdapter(inflater, resources, mRecyclerView!!, Settings.listMode) + mAdapter = FavoritesAdapter(resources, mRecyclerView!!, Settings.listMode) mRecyclerView!!.clipToPadding = false mRecyclerView!!.clipChildren = false mRecyclerView!!.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM) @@ -292,7 +292,7 @@ class FavoritesScene : mOldKeyword = keyword // Save recent fav cat - Settings.putRecentFavCat(mUrlBuilder!!.favCat) + Settings.recentFavCat = mUrlBuilder!!.favCat } // Hide jump fab on local fav cat @@ -351,9 +351,7 @@ class FavoritesScene : BaseDialogBuilder(requireContext()) .setTitle(R.string.default_favorites_collection) .setItems(items) { _: DialogInterface?, which: Int -> - Settings.putDefaultFavSlot( - which - 2, - ) + Settings.defaultFavSlot = which - 2 } .show() return@setOnMenuItemClickListener true @@ -641,7 +639,7 @@ class FavoritesScene : for (i in 0..9) { mFavCountSum += mFavCountArray!![i] } - Settings.putFavCloudCount(mFavCountSum) + Settings.favCloudCount = mFavCountSum updateSearchBar() mHelper!!.onGetPageData(taskId, 0, 0, result.prev, result.next, result.galleryInfoList) if (mDrawerAdapter != null) { @@ -670,7 +668,7 @@ class FavoritesScene : } if (TextUtils.isEmpty(keyword)) { mFavLocalCount = list.size - Settings.putFavLocalCount(mFavLocalCount) + Settings.favLocalCount = mFavLocalCount if (mDrawerAdapter != null) { mDrawerAdapter!!.notifyDataSetChanged() } @@ -819,7 +817,6 @@ class FavoritesScene : } private inner class FavoritesAdapter( - inflater: LayoutInflater, resources: Resources, recyclerView: RecyclerView, type: Int, 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 b84697108..e7e0da4dc 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 @@ -504,9 +504,9 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H } if (checked[0] && next != null) { text += next - Settings.putQSSaveProgress(true) + Settings.qSSaveProgress = true } else { - Settings.putQSSaveProgress(false) + Settings.qSSaveProgress = false } // Check name duplicate