Cleanup Settings

This commit is contained in:
tarsin committed 2023-06-02 15:09:40 +08:00
1 parent 62d7d09886
commit 90e6918db0
4 files changed
+9 -29

No files matched your search

@@ -16,13 +16,11 @@
package com.hippo.ehviewer
import android.annotation.SuppressLint
import com.hippo.ehviewer.Settings.getInt
import com.hippo.ehviewer.Settings.putInt
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.yorozuya.IntIdGenerator
class FavouriteStatusRouter {
private val idGenerator = IntIdGenerator(getInt(KEY_DATA_MAP_NEXT_ID, 0))
private val idGenerator = IntIdGenerator(Settings.dataMapNextId)
@SuppressLint("UseSparseArrays")
private val maps = HashMap<Int, MutableMap<Long, GalleryInfo>>()
@@ -30,7 +28,7 @@ class FavouriteStatusRouter {
fun saveDataMap(map: MutableMap<Long, GalleryInfo>): Int {
val id = idGenerator.nextId()
maps[id] = map
putInt(KEY_DATA_MAP_NEXT_ID, idGenerator.nextId())
Settings.dataMapNextId = idGenerator.nextId()
return id
}
@@ -61,8 +59,4 @@ class FavouriteStatusRouter {
fun interface Listener {
fun onModifyFavourites(gid: Long, slot: Int)
}
companion object {
private const val KEY_DATA_MAP_NEXT_ID = "data_map_next_id"
}
}
@@ -47,8 +47,6 @@ object Settings : DefaultPreferences() {
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,
@@ -98,21 +96,6 @@ object Settings : DefaultPreferences() {
}
}
@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
}
}
@JvmStatic
fun putInt(key: String, value: Int) {
sSettingsPre.edit().putInt(key, value).apply()
}
private fun getString(key: String, defValue: String?): String? {
return try {
sSettingsPre.getString(key, defValue)
@@ -201,6 +184,9 @@ object Settings : DefaultPreferences() {
var proxyPort by intPref("proxy_port", -1)
var clipboardTextHashCode by intPref("clipboard_text_hash_code", 0)
val listThumbSize by intPref(KEY_LIST_THUMB_SIZE, 40)
var requestNewsTimerHour by intPref("request_news_timer_hour", -1)
var requestNewsTimerMinute by intPref("request_news_timer_minute", -1)
var dataMapNextId by intPref("data_map_next_id", 0)
var recentDownloadLabel by stringOrNullPref("recent_download_label", null)
var defaultDownloadLabel by stringOrNullPref("default_download_label", null)
@@ -41,10 +41,10 @@ class DailyCheckWork(context: Context, workerParams: WorkerParameters) :
}
val schedHour
get() = Settings.getInt(Settings.KEY_REQUEST_NEWS_TIMER_HOUR, -1).takeUnless { it == -1 }
get() = Settings.requestNewsTimerHour.takeUnless { it == -1 }
val schedMinute
get() = Settings.getInt(Settings.KEY_REQUEST_NEWS_TIMER_MINUTE, -1).takeUnless { it == -1 }
get() = Settings.requestNewsTimerMinute.takeUnless { it == -1 }
private val whenToWork
get() = LocalDateTime.now()
@@ -87,8 +87,8 @@ class EhFragment : BasePreferenceFragment() {
.build()
.apply {
addOnPositiveButtonClickListener {
Settings.putInt(Settings.KEY_REQUEST_NEWS_TIMER_HOUR, hour)
Settings.putInt(Settings.KEY_REQUEST_NEWS_TIMER_MINUTE, minute)
Settings.requestNewsTimerHour = hour
Settings.requestNewsTimerMinute = minute
updateDailyCheckWork(requireContext())
}
}