Drop GetText

This commit is contained in:
tarsin committed 2023-06-03 15:06:42 +08:00
1 parent 5d13e29300
commit b2d1660e95
8 files changed
+30 -63

No files matched your search

@@ -1,29 +0,0 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer
import androidx.annotation.StringRes
import splitties.init.appCtx
object GetText {
fun getString(@StringRes id: Int): String {
return appCtx.getString(id)
}
fun getString(@StringRes id: Int, vararg formatArgs: Any?): String {
return appCtx.getString(id, *formatArgs)
}
}
@@ -19,7 +19,6 @@ import android.util.Log
import arrow.fx.coroutines.parMap
import arrow.fx.coroutines.parZip
import com.hippo.ehviewer.AppConfig
import com.hippo.ehviewer.GetText
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.data.GalleryInfo
@@ -57,6 +56,7 @@ import okhttp3.Request
import okhttp3.RequestBody.Companion.asRequestBody
import org.json.JSONArray
import org.jsoup.Jsoup
import splitties.init.appCtx
import java.io.File
import kotlin.math.ceil
@@ -85,7 +85,7 @@ private fun rethrowExactly(code: Int, headers: Headers, body: String, e: Throwab
// Check kokomade
if (body.contains(KOKOMADE_URL)) {
throw EhException("今回はここまで ${GetText.getString(R.string.kokomade_tip)}".trimIndent())
throw EhException("今回はここまで ${appCtx.getString(R.string.kokomade_tip)}".trimIndent())
}
// Check Gallery Not Available
@@ -103,12 +103,12 @@ private fun rethrowExactly(code: Int, headers: Headers, body: String, e: Throwab
if (e is ParseException) {
if (body.isEmpty()) {
throw EhException(GetText.getString(R.string.error_empty_html))
throw EhException(appCtx.getString(R.string.error_empty_html))
} else if ("<" !in body) {
throw EhException(body)
} else {
if (Settings.saveParseErrorBody) AppConfig.saveParseErrorBody(e)
throw EhException(GetText.getString(R.string.error_parse_error))
throw EhException(appCtx.getString(R.string.error_parse_error))
}
}
@@ -15,18 +15,18 @@
*/
package com.hippo.ehviewer.client.parser
import com.hippo.ehviewer.GetText.getString
import com.hippo.ehviewer.R
import com.hippo.ehviewer.client.exception.EhException
import com.hippo.ehviewer.client.exception.ParseException
import com.hippo.ehviewer.util.ExceptionUtils
import com.hippo.ehviewer.util.JsoupUtils
import org.jsoup.Jsoup
import splitties.init.appCtx
object FavoritesParser {
fun parse(body: String): Result {
if (body.contains("This page requires you to log on.</p>")) {
throw EhException(getString(R.string.need_sign_in))
throw EhException(appCtx.getString(R.string.need_sign_in))
}
val catArray = arrayOfNulls<String>(10)
val countArray = IntArray(10)
@@ -17,7 +17,6 @@ package com.hippo.ehviewer.preference
import android.content.Context
import android.util.AttributeSet
import com.hippo.ehviewer.GetText
import com.hippo.ehviewer.R
import com.hippo.ehviewer.download.downloadLocation
import com.hippo.unifile.UniFile
@@ -25,14 +24,12 @@ import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.lang.withUIContext
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import splitties.init.appCtx
import com.hippo.ehviewer.download.DownloadManager as downloadManager
private val NO_REDUNDANCY =
GetText.getString(R.string.settings_download_clean_redundancy_no_redundancy)
private val CLEAR_REDUNDANCY_DONE =
{ cnt: Int -> GetText.getString(R.string.settings_download_clean_redundancy_done, cnt) }
private val FINAL_CLEAR_REDUNDANCY_MSG =
{ cnt: Int -> if (cnt == 0) NO_REDUNDANCY else CLEAR_REDUNDANCY_DONE(cnt) }
private val NO_REDUNDANCY = appCtx.getString(R.string.settings_download_clean_redundancy_no_redundancy)
private val CLEAR_REDUNDANCY_DONE = { cnt: Int -> appCtx.getString(R.string.settings_download_clean_redundancy_done, cnt) }
private val FINAL_CLEAR_REDUNDANCY_MSG = { cnt: Int -> if (cnt == 0) NO_REDUNDANCY else CLEAR_REDUNDANCY_DONE(cnt) }
class CleanRedundancyPreference @JvmOverloads constructor(
context: Context,
@@ -18,7 +18,6 @@ package com.hippo.ehviewer.preference
import android.content.Context
import android.util.AttributeSet
import com.hippo.ehviewer.EhDB
import com.hippo.ehviewer.GetText
import com.hippo.ehviewer.R
import com.hippo.ehviewer.client.EhEngine.fillGalleryListByApi
import com.hippo.ehviewer.client.EhUrl
@@ -34,12 +33,12 @@ import eu.kanade.tachiyomi.util.lang.withUIContext
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import moe.tarsin.coroutines.runSuspendCatching
import splitties.init.appCtx
import com.hippo.ehviewer.download.DownloadManager as downloadManager
private val RESTORE_NOT_FOUND = GetText.getString(R.string.settings_download_restore_not_found)
private val RESTORE_FAILED = GetText.getString(R.string.settings_download_restore_failed)
private val RESTORE_COUNT_MSG =
{ cnt: Int -> if (cnt == 0) RESTORE_NOT_FOUND else GetText.getString(R.string.settings_download_restore_successfully, cnt) }
private val RESTORE_NOT_FOUND = appCtx.getString(R.string.settings_download_restore_not_found)
private val RESTORE_FAILED = appCtx.getString(R.string.settings_download_restore_failed)
private val RESTORE_COUNT_MSG = { cnt: Int -> if (cnt == 0) RESTORE_NOT_FOUND else appCtx.getString(R.string.settings_download_restore_successfully, cnt) }
class RestoreDownloadPreference @JvmOverloads constructor(
context: Context,
@@ -20,7 +20,6 @@ import android.util.Log
import androidx.annotation.IntDef
import androidx.collection.LongSparseArray
import androidx.collection.set
import com.hippo.ehviewer.GetText
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhEngine
@@ -54,6 +53,7 @@ import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.sync.withPermit
import moe.tarsin.coroutines.runSuspendCatching
import splitties.init.appCtx
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger
@@ -459,7 +459,7 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
// Get default error
if (state == STATE_FAILED) {
mPageErrorMap[index] = error ?: GetText.getString(R.string.error_unknown)
mPageErrorMap[index] = error ?: appCtx.getString(R.string.error_unknown)
}
}
@@ -815,10 +815,10 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
}
}
private val PTOKEN_FAILED_MESSAGE = GetText.getString(R.string.error_get_ptoken_error)
private val ERROR_509 = GetText.getString(R.string.error_509)
private val NETWORK_ERROR = GetText.getString(R.string.error_socket)
private val DECODE_ERROR = GetText.getString(R.string.error_decoding_failed)
private val PTOKEN_FAILED_MESSAGE = appCtx.getString(R.string.error_get_ptoken_error)
private val ERROR_509 = appCtx.getString(R.string.error_509)
private val NETWORK_ERROR = appCtx.getString(R.string.error_socket)
private val DECODE_ERROR = appCtx.getString(R.string.error_decoding_failed)
private val URL_509_ARRAY = arrayOf(
"https://ehgt.org/g/509.gif",
"https://ehgt.org/g/509s.gif",
@@ -32,7 +32,6 @@ import androidx.compose.ui.res.stringResource
import androidx.core.content.ContextCompat
import com.hippo.ehviewer.EhDB
import com.hippo.ehviewer.FavouriteStatusRouter
import com.hippo.ehviewer.GetText
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhEngine
@@ -57,6 +56,7 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import moe.tarsin.coroutines.runSuspendCatching
import rikka.core.util.ContextUtils.requireActivity
import splitties.init.appCtx
import kotlin.coroutines.resume
object CommonOperations {
@@ -316,7 +316,7 @@ suspend fun DialogState.confirmRemoveDownload(info: GalleryInfo): Boolean = show
)
suspend fun DialogState.showMoveDownloadLabel(info: GalleryInfo) {
val defaultLabel = GetText.getString(R.string.default_download_label_name)
val defaultLabel = appCtx.getString(R.string.default_download_label_name)
val labels = DownloadManager.labelList.mapNotNull { it.label }.toTypedArray()
val selected = showSelectItem(defaultLabel, *labels, title = R.string.download_move_dialog_title)
val downloadInfo = DownloadManager.getDownloadInfo(info.gid) ?: return
@@ -15,10 +15,10 @@
*/
package com.hippo.ehviewer.util
import com.hippo.ehviewer.GetText.getString
import com.hippo.ehviewer.R
import com.hippo.ehviewer.client.exception.EhException
import com.hippo.ehviewer.network.StatusCodeException
import splitties.init.appCtx
import java.net.MalformedURLException
import java.net.ProtocolException
import java.net.SocketException
@@ -30,26 +30,26 @@ object ExceptionUtils {
fun getReadableString(e: Throwable): String {
e.printStackTrace()
return if (e is MalformedURLException) {
getString(R.string.error_invalid_url)
appCtx.getString(R.string.error_invalid_url)
} else if (e is SocketTimeoutException) {
getString(R.string.error_timeout)
appCtx.getString(R.string.error_timeout)
} else if (e is UnknownHostException) {
getString(R.string.error_unknown_host)
appCtx.getString(R.string.error_unknown_host)
} else if (e is StatusCodeException) {
val sb = StringBuilder()
sb.append(getString(R.string.error_bad_status_code, e.responseCode))
sb.append(appCtx.getString(R.string.error_bad_status_code, e.responseCode))
if (e.isIdentifiedResponseCode) {
sb.append(", ").append(e.message)
}
sb.toString()
} else if (e is ProtocolException && e.message!!.startsWith("Too many follow-up requests:")) {
getString(R.string.error_redirection)
appCtx.getString(R.string.error_redirection)
} else if (e is ProtocolException || e is SocketException || e is SSLException) {
getString(R.string.error_socket)
appCtx.getString(R.string.error_socket)
} else if (e is EhException) {
e.message!!
} else {
getString(R.string.error_unknown)
appCtx.getString(R.string.error_unknown)
}
}