diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt index fe77debb5..0362855ab 100644 --- a/app/src/main/java/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt @@ -670,7 +670,7 @@ object Settings { putBoolean(KEY_APP_LINK_VERIFY_TIP, value) } - val favCat: Array + var favCat: Array get() = arrayOf( sSettingsPre.getString(KEY_FAV_CAT_0, DEFAULT_FAV_CAT_0)!!, sSettingsPre.getString(KEY_FAV_CAT_1, DEFAULT_FAV_CAT_1)!!, @@ -683,23 +683,23 @@ object Settings { sSettingsPre.getString(KEY_FAV_CAT_8, DEFAULT_FAV_CAT_8)!!, sSettingsPre.getString(KEY_FAV_CAT_9, DEFAULT_FAV_CAT_9)!!, ) - 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() - } - - val favCount: IntArray + set(value) { + 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() + } + + var favCount: IntArray get() = intArrayOf( sSettingsPre.getInt(KEY_FAV_COUNT_0, DEFAULT_FAV_COUNT), sSettingsPre.getInt(KEY_FAV_COUNT_1, DEFAULT_FAV_COUNT), @@ -712,21 +712,21 @@ object Settings { sSettingsPre.getInt(KEY_FAV_COUNT_8, DEFAULT_FAV_COUNT), sSettingsPre.getInt(KEY_FAV_COUNT_9, DEFAULT_FAV_COUNT), ) - 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() - } + set(count) { + 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() + } val favLocalCount: Int get() = sSettingsPre.getInt(KEY_FAV_LOCAL, DEFAULT_FAV_COUNT) 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 260bbd5fd..fd27bf70d 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt @@ -46,6 +46,7 @@ import com.hippo.ehviewer.client.parser.HomeParser import com.hippo.ehviewer.client.parser.ProfileParser import com.hippo.ehviewer.client.parser.RateGalleryParser import com.hippo.ehviewer.client.parser.TorrentParser +import com.hippo.ehviewer.client.parser.UserConfigParser import com.hippo.ehviewer.client.parser.VoteCommentParser import com.hippo.ehviewer.client.parser.VoteTagParser import com.hippo.network.StatusCodeException @@ -72,7 +73,6 @@ private val okHttpClient = EhApplication.okHttpClient private val MEDIA_TYPE_JSON: MediaType = "application/json; charset=utf-8".toMediaType() private const val TAG = "EhEngine" private const val MAX_REQUEST_SIZE = 25 -private const val U_CONFIG_TEXT = "Selected Profile" private val MEDIA_TYPE_JPEG: MediaType = "image/jpeg".toMediaType() private var sEhFilter = EhFilter @@ -551,9 +551,7 @@ object EhEngine { private suspend fun getUConfigInternal(url: String) { Log.d(TAG, url) - EhRequestBuilder(url).executeAndParsingWith { - check(contains(U_CONFIG_TEXT)) { "U_CONFIG_TEXT not found!" } - } + EhRequestBuilder(url).executeAndParsingWith(UserConfigParser::parse) } suspend fun getUConfig(url: String = EhUrl.uConfigUrl) { diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/FavoritesParser.kt b/app/src/main/java/com/hippo/ehviewer/client/parser/FavoritesParser.kt index 8db44328d..fe462f9c5 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/parser/FavoritesParser.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/FavoritesParser.kt @@ -45,11 +45,11 @@ object FavoritesParser { throw ParseException("Parse favorites error") } val result = GalleryListParser.parse(d, body) - return Result(catArray, countArray, result) + return Result(catArray.requireNoNulls(), countArray, result) } class Result( - val catArray: Array, + val catArray: Array, val countArray: IntArray, galleryListResult: GalleryListParser.Result, ) { diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/UserConfigParser.kt b/app/src/main/java/com/hippo/ehviewer/client/parser/UserConfigParser.kt new file mode 100644 index 000000000..781d6d557 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/client/parser/UserConfigParser.kt @@ -0,0 +1,16 @@ +package com.hippo.ehviewer.client.parser + +import com.hippo.ehviewer.Settings +import com.hippo.yorozuya.unescapeXml + +object UserConfigParser { + private const val U_CONFIG_TEXT = "Selected Profile" + private val FAV_CAT_PATTERN = Regex("(context) { override fun onSuccess(result: FavoritesParser.Result) { // Put fav cat - Settings.putFavCat(result.catArray) - Settings.putFavCount(result.countArray) + Settings.favCat = result.catArray + Settings.favCount = result.countArray val scene = this@FavoritesScene scene.updateHistoryFavSlot(mGidArray, mSlot) if (mLocal) {