From 1e6f0e5b97b2d8aff875b6d3b155b93e61164f86 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 30 Jul 2022 23:48:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/defaultData/directLinkUpload.json | 4 +- .../io/legado/app/data/entities/BookSource.kt | 3 +- .../io/legado/app/data/entities/RssSource.kt | 3 +- .../java/io/legado/app/help/CacheManager.kt | 11 ++-- .../io/legado/app/help/DirectLinkUpload.kt | 65 ++++++++----------- .../java/io/legado/app/help/storage/Backup.kt | 6 ++ .../io/legado/app/help/storage/Restore.kt | 11 ++++ .../io/legado/app/ui/about/DonateFragment.kt | 2 +- .../legado/app/ui/book/cache/CacheActivity.kt | 10 +-- .../ui/book/local/rule/TxtTocRuleActivity.kt | 2 +- .../ui/book/read/config/SpeakEngineDialog.kt | 2 +- .../app/ui/book/read/config/TocRegexDialog.kt | 2 +- .../book/source/manage/BookSourceActivity.kt | 2 +- .../legado/app/ui/browser/WebViewActivity.kt | 6 +- .../app/ui/config/DirectLinkUploadConfig.kt | 14 ++-- .../app/ui/main/explore/ExploreAdapter.kt | 4 +- .../app/ui/replace/ReplaceRuleActivity.kt | 2 +- .../legado/app/ui/rss/read/ReadRssActivity.kt | 6 +- .../ui/rss/source/manage/RssSourceActivity.kt | 2 +- .../main/java/io/legado/app/utils/ACache.kt | 6 +- 20 files changed, 82 insertions(+), 81 deletions(-) diff --git a/app/src/main/assets/defaultData/directLinkUpload.json b/app/src/main/assets/defaultData/directLinkUpload.json index 2a2c9c01e..effbbee27 100644 --- a/app/src/main/assets/defaultData/directLinkUpload.json +++ b/app/src/main/assets/defaultData/directLinkUpload.json @@ -1,5 +1,5 @@ { - "UploadUrl": "http://sy.mgz6.cc/shuyuan,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}", - "DownloadUrlRule": "$.data@js:if (result == '') \n '' \n else \n 'http://shuyuan.mgz6.cc/shuyuan/' + result", + "uploadUrl": "http://sy.mgz6.cc/shuyuan,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}", + "downloadUrlRule": "$.data@js:if (result == '') \n '' \n else \n 'http://shuyuan.mgz6.cc/shuyuan/' + result", "summary": "有效期2天" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 72d2b7589..9f27a31a7 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -10,7 +10,6 @@ import io.legado.app.help.SourceAnalyzer import io.legado.app.utils.* import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize -import splitties.init.appCtx import java.io.InputStream @Suppress("unused") @@ -98,7 +97,7 @@ data class BookSource( if (exploreUrl.startsWith("", false) || exploreUrl.startsWith("@js:", false) ) { - val aCache = ACache.get(appCtx, "explore") + val aCache = ACache.get("explore") ruleStr = aCache.getAsString(bookSourceUrl) ?: "" if (ruleStr.isBlank()) { val jsStr = if (exploreUrl.startsWith("@")) { diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index dd4eaa9b5..6c99095f0 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -8,7 +8,6 @@ import androidx.room.PrimaryKey import com.jayway.jsonpath.DocumentContext import io.legado.app.utils.* import kotlinx.parcelize.Parcelize -import splitties.init.appCtx @Parcelize @Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))]) @@ -121,7 +120,7 @@ data class RssSource( if (sortUrl?.startsWith("", false) == true || sortUrl?.startsWith("@js:", false) == true ) { - val aCache = ACache.get(appCtx, "rssSortUrl") + val aCache = ACache.get("rssSortUrl") a = aCache.getAsString(sourceUrl) ?: "" if (a.isBlank()) { val jsStr = if (sortUrl!!.startsWith("@")) { diff --git a/app/src/main/java/io/legado/app/help/CacheManager.kt b/app/src/main/java/io/legado/app/help/CacheManager.kt index 9cdac800d..90309071b 100644 --- a/app/src/main/java/io/legado/app/help/CacheManager.kt +++ b/app/src/main/java/io/legado/app/help/CacheManager.kt @@ -5,7 +5,6 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Cache import io.legado.app.model.analyzeRule.QueryTTF import io.legado.app.utils.ACache -import splitties.init.appCtx @Suppress("unused") object CacheManager { @@ -22,7 +21,7 @@ object CacheManager { if (saveTime == 0) 0 else System.currentTimeMillis() + saveTime * 1000 when (value) { is QueryTTF -> queryTTFMap[key] = Pair(deadline, value) - is ByteArray -> ACache.get(appCtx).put(key, value, saveTime) + is ByteArray -> ACache.get().put(key, value, saveTime) else -> { val cache = Cache(key, value.toString(), deadline) putMemory(key, value.toString()) @@ -73,7 +72,7 @@ object CacheManager { } fun getByteArray(key: String): ByteArray? { - return ACache.get(appCtx).getAsBinary(key) + return ACache.get().getAsBinary(key) } fun getQueryTTF(key: String): QueryTTF? { @@ -87,16 +86,16 @@ object CacheManager { } fun putFile(key: String, value: String, saveTime: Int = 0) { - ACache.get(appCtx).put(key, value, saveTime) + ACache.get().put(key, value, saveTime) } fun getFile(key: String): String? { - return ACache.get(appCtx).getAsString(key) + return ACache.get().getAsString(key) } fun delete(key: String) { appDb.cacheDao.delete(key) deleteMemory(key) - ACache.get(appCtx).remove(key) + ACache.get().remove(key) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt b/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt index e25537bbd..e4b4bf007 100644 --- a/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt +++ b/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt @@ -3,25 +3,27 @@ package io.legado.app.help import io.legado.app.exception.NoStackTraceException import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl -import io.legado.app.utils.jsonPath -import io.legado.app.utils.readString +import io.legado.app.utils.ACache +import io.legado.app.utils.GSON +import io.legado.app.utils.fromJsonObject import splitties.init.appCtx import java.io.File +@Suppress("MemberVisibilityCanBePrivate") object DirectLinkUpload { - private const val uploadUrlKey = "directLinkUploadUrl" - private const val downloadUrlRuleKey = "directLinkDownloadUrlRule" - private const val summaryKey = "directSummary" + const val ruleFileName = "directLinkUploadRule.json" @Throws(NoStackTraceException::class) suspend fun upLoad(fileName: String, file: Any, contentType: String): String { - val url = getUploadUrl() - if (url.isNullOrBlank()) { + val rule = defaultRule ?: getConfigRule() + rule ?: throw NoStackTraceException("直链上传规则未配置") + val url = rule.uploadUrl + if (url.isBlank()) { throw NoStackTraceException("上传url未配置") } - val downloadUrlRule = getDownloadUrlRule() - if (downloadUrlRule.isNullOrBlank()) { + val downloadUrlRule = rule.downloadUrlRule + if (downloadUrlRule.isBlank()) { throw NoStackTraceException("下载地址规则未配置") } val analyzeUrl = AnalyzeUrl(url) @@ -34,49 +36,36 @@ object DirectLinkUpload { return downloadUrl } - private val ruleDoc by lazy { + private val defaultRule: Rule? by lazy { val json = String( appCtx.assets.open("defaultData${File.separator}directLinkUpload.json") .readBytes() ) - jsonPath.parse(json) + GSON.fromJsonObject(json).getOrNull() } - fun getUploadUrl(): String? { - return CacheManager.get(uploadUrlKey) - ?: ruleDoc.readString("$.UploadUrl") + fun getConfigRule(): Rule? { + val json = ACache.get(cacheDir = false).getAsString(ruleFileName) + return GSON.fromJsonObject(json).getOrNull() } - fun putUploadUrl(url: String) { - CacheManager.put(uploadUrlKey, url) + fun putConfigRule(uploadUrl: String, downloadUrlRule: String, summary: String?) { + val rule = Rule(uploadUrl, downloadUrlRule, summary) + ACache.get(cacheDir = false).put(ruleFileName, GSON.toJson(rule)) } - fun getDownloadUrlRule(): String? { - return CacheManager.get(downloadUrlRuleKey) - ?: ruleDoc.readString("$.DownloadUrlRule") - } - - fun putDownloadUrlRule(rule: String) { - CacheManager.put(downloadUrlRuleKey, rule) + fun delConfigRule() { + ACache.get(cacheDir = false).remove(ruleFileName) } fun getSummary(): String? { - return CacheManager.get(summaryKey) - ?: ruleDoc.readString("summary") - } - - fun putSummary(summary: String?) { - if (summary != null) { - CacheManager.put(summaryKey, summary) - } else { - CacheManager.delete(summaryKey) - } + return getConfigRule()?.summary } - fun delete() { - CacheManager.delete(uploadUrlKey) - CacheManager.delete(downloadUrlRuleKey) - CacheManager.delete(summaryKey) - } + data class Rule( + var uploadUrl: String, + var downloadUrlRule: String, + var summary: String? + ) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 702d28ecc..98e490980 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -7,6 +7,7 @@ import io.legado.app.constant.AppLog import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.help.AppWebDav +import io.legado.app.help.DirectLinkUpload import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ThemeConfig @@ -41,6 +42,7 @@ object Backup { "txtTocRule.json", "httpTTS.json", "keyboardAssists.json", + DirectLinkUpload.ruleFileName, ReadBookConfig.configFileName, ReadBookConfig.shareConfigFileName, ThemeConfig.configFileName, @@ -92,6 +94,10 @@ object Backup { FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName) .writeText(it) } + DirectLinkUpload.getConfigRule()?.let { + FileUtils.createFileIfNotExist(backupPath + File.separator + DirectLinkUpload.ruleFileName) + .writeText(GSON.toJson(it)) + } Preferences.getSharedPreferences(appCtx, backupPath, "config")?.let { sp -> val edit = sp.edit() appCtx.defaultSharedPreferences.all.forEach { (key, value) -> diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index b1e2b00bb..2bd99b040 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -11,6 +11,7 @@ import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.data.entities.* +import io.legado.app.help.DirectLinkUpload import io.legado.app.help.LauncherIconHelp import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.ReadBookConfig @@ -118,6 +119,16 @@ object Restore { suspend fun restoreConfig(path: String = Backup.backupPath) { withContext(IO) { + try { + val file = + FileUtils.createFileIfNotExist("$path${File.separator}${DirectLinkUpload.ruleFileName}") + if (file.exists()) { + val json = file.readText() + ACache.get(cacheDir = false).put(DirectLinkUpload.ruleFileName, json) + } + } catch (e: Exception) { + AppLog.put("直链上传出错\n${e.localizedMessage}", e) + } try { val file = FileUtils.createFileIfNotExist("$path${File.separator}${ThemeConfig.configFileName}") diff --git a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt index 87059bb97..7e4e7a67a 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt @@ -53,7 +53,7 @@ class DonateFragment : PreferenceFragmentCompat() { } catch (e: Exception) { e.printOnDebug() } finally { - ACache.get(requireContext(), cacheDir = false) + ACache.get(cacheDir = false) .put("proTime", System.currentTimeMillis()) } } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 5b5b1c74b..36a6ad667 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -54,11 +54,11 @@ class CacheActivity : VMBaseActivity() private val exportDir = registerForActivityResult(HandleFileContract()) { result -> result.uri?.let { uri -> if (uri.isContentScheme()) { - ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString()) + ACache.get().put(exportBookPathKey, uri.toString()) startExport(uri.toString(), result.requestCode) } else { uri.path?.let { path -> - ACache.get(this@CacheActivity).put(exportBookPathKey, path) + ACache.get().put(exportBookPathKey, path) startExport(path, result.requestCode) } } @@ -244,7 +244,7 @@ class CacheActivity : VMBaseActivity() } override fun export(position: Int) { - val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey) + val path = ACache.get().getAsString(exportBookPathKey) if (path.isNullOrEmpty()) { selectExportFolder(position) } else { @@ -253,7 +253,7 @@ class CacheActivity : VMBaseActivity() } private fun exportAll() { - val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey) + val path = ACache.get().getAsString(exportBookPathKey) if (path.isNullOrEmpty()) { selectExportFolder(-10) } else { @@ -263,7 +263,7 @@ class CacheActivity : VMBaseActivity() private fun selectExportFolder(exportPosition: Int) { val default = arrayListOf>() - val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey) + val path = ACache.get().getAsString(exportBookPathKey) if (!path.isNullOrEmpty()) { default.add(SelectItem(path, -1)) } diff --git a/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt index 29fc96d7e..0eb4a00b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt @@ -156,7 +156,7 @@ class TxtTocRuleActivity : VMBaseActivity = aCache .getAsString(importTocRuleKey) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 1f9462daa..722563a4a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -163,7 +163,7 @@ class SpeakEngineDialog(val callBack: CallBack) : BaseDialogFragment(R.layout.di } private fun importAlert() { - val aCache = ACache.get(requireContext(), cacheDir = false) + val aCache = ACache.get(cacheDir = false) val cacheUrls: MutableList = aCache .getAsString(ttsUrlKey) ?.splitNotBlank(",") diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index f77c31e02..371914b7c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -127,7 +127,7 @@ class TocRegexDialog() : BaseDialogFragment(R.layout.dialog_toc_regex), @SuppressLint("InflateParams") private fun showImportDialog() { - val aCache = ACache.get(requireContext(), cacheDir = false) + val aCache = ACache.get(cacheDir = false) val defaultUrl = "https://gitee.com/fisher52/YueDuJson/raw/master/myTxtChapterRule.json" val cacheUrls: MutableList = aCache .getAsString(importTocRuleKey) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 6df26267a..bd9cd1cf9 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -447,7 +447,7 @@ class BookSourceActivity : VMBaseActivity = aCache .getAsString(importRecordKey) ?.splitNotBlank(",") diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt index ad0265c60..f42771a13 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt @@ -38,7 +38,7 @@ class WebViewActivity : VMBaseActivity() { private var webPic: String? = null private val saveImage = registerForActivityResult(HandleFileContract()) { it.uri?.let { uri -> - ACache.get(this).put(imagePathKey, uri.toString()) + ACache.get().put(imagePathKey, uri.toString()) viewModel.saveImage(webPic, uri.toString()) } } @@ -140,7 +140,7 @@ class WebViewActivity : VMBaseActivity() { private fun saveImage(webPic: String) { this.webPic = webPic - val path = ACache.get(this).getAsString(imagePathKey) + val path = ACache.get().getAsString(imagePathKey) if (path.isNullOrEmpty()) { selectSaveFolder() } else { @@ -149,7 +149,7 @@ class WebViewActivity : VMBaseActivity() { } private fun selectSaveFolder() { val default = arrayListOf>() - val path = ACache.get(this).getAsString(imagePathKey) + val path = ACache.get().getAsString(imagePathKey) if (!path.isNullOrEmpty()) { default.add(SelectItem(path, -1)) } diff --git a/app/src/main/java/io/legado/app/ui/config/DirectLinkUploadConfig.kt b/app/src/main/java/io/legado/app/ui/config/DirectLinkUploadConfig.kt index 9f18c6098..595150fe2 100644 --- a/app/src/main/java/io/legado/app/ui/config/DirectLinkUploadConfig.kt +++ b/app/src/main/java/io/legado/app/ui/config/DirectLinkUploadConfig.kt @@ -24,14 +24,16 @@ class DirectLinkUploadConfig : BaseDialogFragment(R.layout.dialog_direct_link_up override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { binding.toolBar.setBackgroundColor(primaryColor) - binding.editUploadUrl.setText(DirectLinkUpload.getUploadUrl()) - binding.editDownloadUrlRule.setText(DirectLinkUpload.getDownloadUrlRule()) - binding.editSummary.setText(DirectLinkUpload.getSummary()) + DirectLinkUpload.getConfigRule()?.let { + binding.editUploadUrl.setText(it.uploadUrl) + binding.editDownloadUrlRule.setText(it.downloadUrlRule) + binding.editSummary.setText(it.summary) + } binding.tvCancel.onClick { dismiss() } binding.tvFooterLeft.onClick { - DirectLinkUpload.delete() + DirectLinkUpload.delConfigRule() dismiss() } binding.tvOk.onClick { @@ -46,9 +48,7 @@ class DirectLinkUploadConfig : BaseDialogFragment(R.layout.dialog_direct_link_up toastOnUi("下载Url规则不能为空") return@onClick } - DirectLinkUpload.putUploadUrl(uploadUrl) - DirectLinkUpload.putDownloadUrlRule(downloadUrlRule) - DirectLinkUpload.putSummary(summary) + DirectLinkUpload.putConfigRule(uploadUrl, downloadUrlRule, summary) dismiss() } } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 7e763e5e0..71a61d82c 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -77,7 +77,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) : } private fun upKindList(flexbox: FlexboxLayout, sourceUrl: String, kinds: List) { - if (!kinds.isNullOrEmpty()) kotlin.runCatching { + if (kinds.isNotEmpty()) kotlin.runCatching { recyclerFlexbox(flexbox) flexbox.visible() kinds.forEach { kind -> @@ -168,7 +168,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) : putExtra("key", source.bookSourceUrl) } R.id.menu_refresh -> Coroutine.async(callBack.scope) { - ACache.get(context, "explore").remove(source.bookSourceUrl) + ACache.get("explore").remove(source.bookSourceUrl) }.onSuccess { callBack.refreshData() } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 624997962..5a06c74d9 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -266,7 +266,7 @@ class ReplaceRuleActivity : VMBaseActivity = aCache .getAsString(importRecordKey) ?.splitNotBlank(",") diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 9dec07ee4..0e37f5787 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -45,7 +45,7 @@ class ReadRssActivity : VMBaseActivity private var webPic: String? = null private val saveImage = registerForActivityResult(HandleFileContract()) { it.uri?.let { uri -> - ACache.get(this).put(imagePathKey, uri.toString()) + ACache.get().put(imagePathKey, uri.toString()) viewModel.saveImage(webPic, uri) } } @@ -154,7 +154,7 @@ class ReadRssActivity : VMBaseActivity private fun saveImage(webPic: String) { this.webPic = webPic - val path = ACache.get(this@ReadRssActivity).getAsString(imagePathKey) + val path = ACache.get().getAsString(imagePathKey) if (path.isNullOrEmpty()) { selectSaveFolder() } else { @@ -164,7 +164,7 @@ class ReadRssActivity : VMBaseActivity private fun selectSaveFolder() { val default = arrayListOf>() - val path = ACache.get(this@ReadRssActivity).getAsString(imagePathKey) + val path = ACache.get().getAsString(imagePathKey) if (!path.isNullOrEmpty()) { default.add(SelectItem(path, -1)) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 61872cd0e..470e243cb 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -270,7 +270,7 @@ class RssSourceActivity : VMBaseActivity = aCache .getAsString(importRecordKey) ?.splitNotBlank(",") diff --git a/app/src/main/java/io/legado/app/utils/ACache.kt b/app/src/main/java/io/legado/app/utils/ACache.kt index cd41ad72d..214d11ad2 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -1,7 +1,6 @@ //Copyright (c) 2017. 章钦豪. All rights reserved. package io.legado.app.utils -import android.content.Context import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.Canvas @@ -11,7 +10,6 @@ import android.graphics.drawable.Drawable import org.json.JSONArray import org.json.JSONObject import splitties.init.appCtx - import java.io.* import java.util.* import java.util.concurrent.atomic.AtomicInteger @@ -34,13 +32,13 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) @JvmOverloads fun get( - ctx: Context, cacheName: String = "ACache", maxSize: Long = MAX_SIZE.toLong(), maxCount: Int = MAX_COUNT, cacheDir: Boolean = true ): ACache { - val f = if (cacheDir) File(ctx.cacheDir, cacheName) else File(ctx.filesDir, cacheName) + val f = + if (cacheDir) File(appCtx.cacheDir, cacheName) else File(appCtx.filesDir, cacheName) return get(f, maxSize, maxCount) }