kunfei il y a 4 ans
Parent
commit
7a06b757cf

+ 2 - 2
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天"
   "summary": "有效期2天"
 }
 }

+ 1 - 2
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 io.legado.app.utils.*
 import kotlinx.parcelize.IgnoredOnParcel
 import kotlinx.parcelize.IgnoredOnParcel
 import kotlinx.parcelize.Parcelize
 import kotlinx.parcelize.Parcelize
-import splitties.init.appCtx
 import java.io.InputStream
 import java.io.InputStream
 
 
 @Suppress("unused")
 @Suppress("unused")
@@ -98,7 +97,7 @@ data class BookSource(
                 if (exploreUrl.startsWith("<js>", false)
                 if (exploreUrl.startsWith("<js>", false)
                     || exploreUrl.startsWith("@js:", false)
                     || exploreUrl.startsWith("@js:", false)
                 ) {
                 ) {
-                    val aCache = ACache.get(appCtx, "explore")
+                    val aCache = ACache.get("explore")
                     ruleStr = aCache.getAsString(bookSourceUrl) ?: ""
                     ruleStr = aCache.getAsString(bookSourceUrl) ?: ""
                     if (ruleStr.isBlank()) {
                     if (ruleStr.isBlank()) {
                         val jsStr = if (exploreUrl.startsWith("@")) {
                         val jsStr = if (exploreUrl.startsWith("@")) {

+ 1 - 2
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 com.jayway.jsonpath.DocumentContext
 import io.legado.app.utils.*
 import io.legado.app.utils.*
 import kotlinx.parcelize.Parcelize
 import kotlinx.parcelize.Parcelize
-import splitties.init.appCtx
 
 
 @Parcelize
 @Parcelize
 @Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))])
 @Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))])
@@ -121,7 +120,7 @@ data class RssSource(
             if (sortUrl?.startsWith("<js>", false) == true
             if (sortUrl?.startsWith("<js>", false) == true
                 || sortUrl?.startsWith("@js:", false) == true
                 || sortUrl?.startsWith("@js:", false) == true
             ) {
             ) {
-                val aCache = ACache.get(appCtx, "rssSortUrl")
+                val aCache = ACache.get("rssSortUrl")
                 a = aCache.getAsString(sourceUrl) ?: ""
                 a = aCache.getAsString(sourceUrl) ?: ""
                 if (a.isBlank()) {
                 if (a.isBlank()) {
                     val jsStr = if (sortUrl!!.startsWith("@")) {
                     val jsStr = if (sortUrl!!.startsWith("@")) {

+ 5 - 6
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.data.entities.Cache
 import io.legado.app.model.analyzeRule.QueryTTF
 import io.legado.app.model.analyzeRule.QueryTTF
 import io.legado.app.utils.ACache
 import io.legado.app.utils.ACache
-import splitties.init.appCtx
 
 
 @Suppress("unused")
 @Suppress("unused")
 object CacheManager {
 object CacheManager {
@@ -22,7 +21,7 @@ object CacheManager {
             if (saveTime == 0) 0 else System.currentTimeMillis() + saveTime * 1000
             if (saveTime == 0) 0 else System.currentTimeMillis() + saveTime * 1000
         when (value) {
         when (value) {
             is QueryTTF -> queryTTFMap[key] = Pair(deadline, 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 -> {
             else -> {
                 val cache = Cache(key, value.toString(), deadline)
                 val cache = Cache(key, value.toString(), deadline)
                 putMemory(key, value.toString())
                 putMemory(key, value.toString())
@@ -73,7 +72,7 @@ object CacheManager {
     }
     }
 
 
     fun getByteArray(key: String): ByteArray? {
     fun getByteArray(key: String): ByteArray? {
-        return ACache.get(appCtx).getAsBinary(key)
+        return ACache.get().getAsBinary(key)
     }
     }
 
 
     fun getQueryTTF(key: String): QueryTTF? {
     fun getQueryTTF(key: String): QueryTTF? {
@@ -87,16 +86,16 @@ object CacheManager {
     }
     }
 
 
     fun putFile(key: String, value: String, saveTime: Int = 0) {
     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? {
     fun getFile(key: String): String? {
-        return ACache.get(appCtx).getAsString(key)
+        return ACache.get().getAsString(key)
     }
     }
 
 
     fun delete(key: String) {
     fun delete(key: String) {
         appDb.cacheDao.delete(key)
         appDb.cacheDao.delete(key)
         deleteMemory(key)
         deleteMemory(key)
-        ACache.get(appCtx).remove(key)
+        ACache.get().remove(key)
     }
     }
 }
 }

+ 27 - 38
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.exception.NoStackTraceException
 import io.legado.app.model.analyzeRule.AnalyzeRule
 import io.legado.app.model.analyzeRule.AnalyzeRule
 import io.legado.app.model.analyzeRule.AnalyzeUrl
 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 splitties.init.appCtx
 import java.io.File
 import java.io.File
 
 
+@Suppress("MemberVisibilityCanBePrivate")
 object DirectLinkUpload {
 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)
     @Throws(NoStackTraceException::class)
     suspend fun upLoad(fileName: String, file: Any, contentType: String): String {
     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未配置")
             throw NoStackTraceException("上传url未配置")
         }
         }
-        val downloadUrlRule = getDownloadUrlRule()
-        if (downloadUrlRule.isNullOrBlank()) {
+        val downloadUrlRule = rule.downloadUrlRule
+        if (downloadUrlRule.isBlank()) {
             throw NoStackTraceException("下载地址规则未配置")
             throw NoStackTraceException("下载地址规则未配置")
         }
         }
         val analyzeUrl = AnalyzeUrl(url)
         val analyzeUrl = AnalyzeUrl(url)
@@ -34,49 +36,36 @@ object DirectLinkUpload {
         return downloadUrl
         return downloadUrl
     }
     }
 
 
-    private val ruleDoc by lazy {
+    private val defaultRule: Rule? by lazy {
         val json = String(
         val json = String(
             appCtx.assets.open("defaultData${File.separator}directLinkUpload.json")
             appCtx.assets.open("defaultData${File.separator}directLinkUpload.json")
                 .readBytes()
                 .readBytes()
         )
         )
-        jsonPath.parse(json)
+        GSON.fromJsonObject<Rule>(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<Rule>(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? {
     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?
+    )
 
 
 }
 }

+ 6 - 0
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.constant.PreferKey
 import io.legado.app.data.appDb
 import io.legado.app.data.appDb
 import io.legado.app.help.AppWebDav
 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.LocalConfig
 import io.legado.app.help.config.ReadBookConfig
 import io.legado.app.help.config.ReadBookConfig
 import io.legado.app.help.config.ThemeConfig
 import io.legado.app.help.config.ThemeConfig
@@ -41,6 +42,7 @@ object Backup {
             "txtTocRule.json",
             "txtTocRule.json",
             "httpTTS.json",
             "httpTTS.json",
             "keyboardAssists.json",
             "keyboardAssists.json",
+            DirectLinkUpload.ruleFileName,
             ReadBookConfig.configFileName,
             ReadBookConfig.configFileName,
             ReadBookConfig.shareConfigFileName,
             ReadBookConfig.shareConfigFileName,
             ThemeConfig.configFileName,
             ThemeConfig.configFileName,
@@ -92,6 +94,10 @@ object Backup {
                 FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName)
                 FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName)
                     .writeText(it)
                     .writeText(it)
             }
             }
+            DirectLinkUpload.getConfigRule()?.let {
+                FileUtils.createFileIfNotExist(backupPath + File.separator + DirectLinkUpload.ruleFileName)
+                    .writeText(GSON.toJson(it))
+            }
             Preferences.getSharedPreferences(appCtx, backupPath, "config")?.let { sp ->
             Preferences.getSharedPreferences(appCtx, backupPath, "config")?.let { sp ->
                 val edit = sp.edit()
                 val edit = sp.edit()
                 appCtx.defaultSharedPreferences.all.forEach { (key, value) ->
                 appCtx.defaultSharedPreferences.all.forEach { (key, value) ->

+ 11 - 0
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.constant.PreferKey
 import io.legado.app.data.appDb
 import io.legado.app.data.appDb
 import io.legado.app.data.entities.*
 import io.legado.app.data.entities.*
+import io.legado.app.help.DirectLinkUpload
 import io.legado.app.help.LauncherIconHelp
 import io.legado.app.help.LauncherIconHelp
 import io.legado.app.help.config.LocalConfig
 import io.legado.app.help.config.LocalConfig
 import io.legado.app.help.config.ReadBookConfig
 import io.legado.app.help.config.ReadBookConfig
@@ -118,6 +119,16 @@ object Restore {
 
 
     suspend fun restoreConfig(path: String = Backup.backupPath) {
     suspend fun restoreConfig(path: String = Backup.backupPath) {
         withContext(IO) {
         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 {
             try {
                 val file =
                 val file =
                     FileUtils.createFileIfNotExist("$path${File.separator}${ThemeConfig.configFileName}")
                     FileUtils.createFileIfNotExist("$path${File.separator}${ThemeConfig.configFileName}")

+ 1 - 1
app/src/main/java/io/legado/app/ui/about/DonateFragment.kt

@@ -53,7 +53,7 @@ class DonateFragment : PreferenceFragmentCompat() {
         } catch (e: Exception) {
         } catch (e: Exception) {
             e.printOnDebug()
             e.printOnDebug()
         } finally {
         } finally {
-            ACache.get(requireContext(), cacheDir = false)
+            ACache.get(cacheDir = false)
                 .put("proTime", System.currentTimeMillis())
                 .put("proTime", System.currentTimeMillis())
         }
         }
     }
     }

+ 5 - 5
app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt

@@ -54,11 +54,11 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
     private val exportDir = registerForActivityResult(HandleFileContract()) { result ->
     private val exportDir = registerForActivityResult(HandleFileContract()) { result ->
         result.uri?.let { uri ->
         result.uri?.let { uri ->
             if (uri.isContentScheme()) {
             if (uri.isContentScheme()) {
-                ACache.get(this@CacheActivity).put(exportBookPathKey, uri.toString())
+                ACache.get().put(exportBookPathKey, uri.toString())
                 startExport(uri.toString(), result.requestCode)
                 startExport(uri.toString(), result.requestCode)
             } else {
             } else {
                 uri.path?.let { path ->
                 uri.path?.let { path ->
-                    ACache.get(this@CacheActivity).put(exportBookPathKey, path)
+                    ACache.get().put(exportBookPathKey, path)
                     startExport(path, result.requestCode)
                     startExport(path, result.requestCode)
                 }
                 }
             }
             }
@@ -244,7 +244,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
     }
     }
 
 
     override fun export(position: Int) {
     override fun export(position: Int) {
-        val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey)
+        val path = ACache.get().getAsString(exportBookPathKey)
         if (path.isNullOrEmpty()) {
         if (path.isNullOrEmpty()) {
             selectExportFolder(position)
             selectExportFolder(position)
         } else {
         } else {
@@ -253,7 +253,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
     }
     }
 
 
     private fun exportAll() {
     private fun exportAll() {
-        val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey)
+        val path = ACache.get().getAsString(exportBookPathKey)
         if (path.isNullOrEmpty()) {
         if (path.isNullOrEmpty()) {
             selectExportFolder(-10)
             selectExportFolder(-10)
         } else {
         } else {
@@ -263,7 +263,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
 
 
     private fun selectExportFolder(exportPosition: Int) {
     private fun selectExportFolder(exportPosition: Int) {
         val default = arrayListOf<SelectItem<Int>>()
         val default = arrayListOf<SelectItem<Int>>()
-        val path = ACache.get(this@CacheActivity).getAsString(exportBookPathKey)
+        val path = ACache.get().getAsString(exportBookPathKey)
         if (!path.isNullOrEmpty()) {
         if (!path.isNullOrEmpty()) {
             default.add(SelectItem(path, -1))
             default.add(SelectItem(path, -1))
         }
         }

+ 1 - 1
app/src/main/java/io/legado/app/ui/book/local/rule/TxtTocRuleActivity.kt

@@ -156,7 +156,7 @@ class TxtTocRuleActivity : VMBaseActivity<ActivityTxtTocRuleBinding, TxtTocRuleV
 
 
     @SuppressLint("InflateParams")
     @SuppressLint("InflateParams")
     private fun showImportDialog() {
     private fun showImportDialog() {
-        val aCache = ACache.get(this, cacheDir = false)
+        val aCache = ACache.get(cacheDir = false)
         val defaultUrl = "https://gitee.com/fisher52/YueDuJson/raw/master/myTxtChapterRule.json"
         val defaultUrl = "https://gitee.com/fisher52/YueDuJson/raw/master/myTxtChapterRule.json"
         val cacheUrls: MutableList<String> = aCache
         val cacheUrls: MutableList<String> = aCache
             .getAsString(importTocRuleKey)
             .getAsString(importTocRuleKey)

+ 1 - 1
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() {
     private fun importAlert() {
-        val aCache = ACache.get(requireContext(), cacheDir = false)
+        val aCache = ACache.get(cacheDir = false)
         val cacheUrls: MutableList<String> = aCache
         val cacheUrls: MutableList<String> = aCache
             .getAsString(ttsUrlKey)
             .getAsString(ttsUrlKey)
             ?.splitNotBlank(",")
             ?.splitNotBlank(",")

+ 1 - 1
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")
     @SuppressLint("InflateParams")
     private fun showImportDialog() {
     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 defaultUrl = "https://gitee.com/fisher52/YueDuJson/raw/master/myTxtChapterRule.json"
         val cacheUrls: MutableList<String> = aCache
         val cacheUrls: MutableList<String> = aCache
             .getAsString(importTocRuleKey)
             .getAsString(importTocRuleKey)

+ 1 - 1
app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt

@@ -447,7 +447,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
 
 
     @SuppressLint("InflateParams")
     @SuppressLint("InflateParams")
     private fun showImportDialog() {
     private fun showImportDialog() {
-        val aCache = ACache.get(this, cacheDir = false)
+        val aCache = ACache.get(cacheDir = false)
         val cacheUrls: MutableList<String> = aCache
         val cacheUrls: MutableList<String> = aCache
             .getAsString(importRecordKey)
             .getAsString(importRecordKey)
             ?.splitNotBlank(",")
             ?.splitNotBlank(",")

+ 3 - 3
app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt

@@ -38,7 +38,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
     private var webPic: String? = null
     private var webPic: String? = null
     private val saveImage = registerForActivityResult(HandleFileContract()) {
     private val saveImage = registerForActivityResult(HandleFileContract()) {
         it.uri?.let { uri ->
         it.uri?.let { uri ->
-            ACache.get(this).put(imagePathKey, uri.toString())
+            ACache.get().put(imagePathKey, uri.toString())
             viewModel.saveImage(webPic, uri.toString())
             viewModel.saveImage(webPic, uri.toString())
         }
         }
     }
     }
@@ -140,7 +140,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
 
 
     private fun saveImage(webPic: String) {
     private fun saveImage(webPic: String) {
         this.webPic = webPic
         this.webPic = webPic
-        val path = ACache.get(this).getAsString(imagePathKey)
+        val path = ACache.get().getAsString(imagePathKey)
         if (path.isNullOrEmpty()) {
         if (path.isNullOrEmpty()) {
             selectSaveFolder()
             selectSaveFolder()
         } else {
         } else {
@@ -149,7 +149,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
     }
     }
     private fun selectSaveFolder() {
     private fun selectSaveFolder() {
         val default = arrayListOf<SelectItem<Int>>()
         val default = arrayListOf<SelectItem<Int>>()
-        val path = ACache.get(this).getAsString(imagePathKey)
+        val path = ACache.get().getAsString(imagePathKey)
         if (!path.isNullOrEmpty()) {
         if (!path.isNullOrEmpty()) {
             default.add(SelectItem(path, -1))
             default.add(SelectItem(path, -1))
         }
         }

+ 7 - 7
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?) {
     override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
         binding.toolBar.setBackgroundColor(primaryColor)
         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 {
         binding.tvCancel.onClick {
             dismiss()
             dismiss()
         }
         }
         binding.tvFooterLeft.onClick {
         binding.tvFooterLeft.onClick {
-            DirectLinkUpload.delete()
+            DirectLinkUpload.delConfigRule()
             dismiss()
             dismiss()
         }
         }
         binding.tvOk.onClick {
         binding.tvOk.onClick {
@@ -46,9 +48,7 @@ class DirectLinkUploadConfig : BaseDialogFragment(R.layout.dialog_direct_link_up
                 toastOnUi("下载Url规则不能为空")
                 toastOnUi("下载Url规则不能为空")
                 return@onClick
                 return@onClick
             }
             }
-            DirectLinkUpload.putUploadUrl(uploadUrl)
-            DirectLinkUpload.putDownloadUrlRule(downloadUrlRule)
-            DirectLinkUpload.putSummary(summary)
+            DirectLinkUpload.putConfigRule(uploadUrl, downloadUrlRule, summary)
             dismiss()
             dismiss()
         }
         }
     }
     }

+ 2 - 2
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<ExploreKind>) {
     private fun upKindList(flexbox: FlexboxLayout, sourceUrl: String, kinds: List<ExploreKind>) {
-        if (!kinds.isNullOrEmpty()) kotlin.runCatching {
+        if (kinds.isNotEmpty()) kotlin.runCatching {
             recyclerFlexbox(flexbox)
             recyclerFlexbox(flexbox)
             flexbox.visible()
             flexbox.visible()
             kinds.forEach { kind ->
             kinds.forEach { kind ->
@@ -168,7 +168,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
                     putExtra("key", source.bookSourceUrl)
                     putExtra("key", source.bookSourceUrl)
                 }
                 }
                 R.id.menu_refresh -> Coroutine.async(callBack.scope) {
                 R.id.menu_refresh -> Coroutine.async(callBack.scope) {
-                    ACache.get(context, "explore").remove(source.bookSourceUrl)
+                    ACache.get("explore").remove(source.bookSourceUrl)
                 }.onSuccess {
                 }.onSuccess {
                     callBack.refreshData()
                     callBack.refreshData()
                 }
                 }

+ 1 - 1
app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt

@@ -266,7 +266,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
 
 
     @SuppressLint("InflateParams")
     @SuppressLint("InflateParams")
     private fun showImportDialog() {
     private fun showImportDialog() {
-        val aCache = ACache.get(this, cacheDir = false)
+        val aCache = ACache.get(cacheDir = false)
         val cacheUrls: MutableList<String> = aCache
         val cacheUrls: MutableList<String> = aCache
             .getAsString(importRecordKey)
             .getAsString(importRecordKey)
             ?.splitNotBlank(",")
             ?.splitNotBlank(",")

+ 3 - 3
app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt

@@ -45,7 +45,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
     private var webPic: String? = null
     private var webPic: String? = null
     private val saveImage = registerForActivityResult(HandleFileContract()) {
     private val saveImage = registerForActivityResult(HandleFileContract()) {
         it.uri?.let { uri ->
         it.uri?.let { uri ->
-            ACache.get(this).put(imagePathKey, uri.toString())
+            ACache.get().put(imagePathKey, uri.toString())
             viewModel.saveImage(webPic, uri)
             viewModel.saveImage(webPic, uri)
         }
         }
     }
     }
@@ -154,7 +154,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
 
 
     private fun saveImage(webPic: String) {
     private fun saveImage(webPic: String) {
         this.webPic = webPic
         this.webPic = webPic
-        val path = ACache.get(this@ReadRssActivity).getAsString(imagePathKey)
+        val path = ACache.get().getAsString(imagePathKey)
         if (path.isNullOrEmpty()) {
         if (path.isNullOrEmpty()) {
             selectSaveFolder()
             selectSaveFolder()
         } else {
         } else {
@@ -164,7 +164,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
 
 
     private fun selectSaveFolder() {
     private fun selectSaveFolder() {
         val default = arrayListOf<SelectItem<Int>>()
         val default = arrayListOf<SelectItem<Int>>()
-        val path = ACache.get(this@ReadRssActivity).getAsString(imagePathKey)
+        val path = ACache.get().getAsString(imagePathKey)
         if (!path.isNullOrEmpty()) {
         if (!path.isNullOrEmpty()) {
             default.add(SelectItem(path, -1))
             default.add(SelectItem(path, -1))
         }
         }

+ 1 - 1
app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@@ -270,7 +270,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
 
 
     @SuppressLint("InflateParams")
     @SuppressLint("InflateParams")
     private fun showImportDialog() {
     private fun showImportDialog() {
-        val aCache = ACache.get(this, cacheDir = false)
+        val aCache = ACache.get(cacheDir = false)
         val cacheUrls: MutableList<String> = aCache
         val cacheUrls: MutableList<String> = aCache
             .getAsString(importRecordKey)
             .getAsString(importRecordKey)
             ?.splitNotBlank(",")
             ?.splitNotBlank(",")

+ 2 - 4
app/src/main/java/io/legado/app/utils/ACache.kt

@@ -1,7 +1,6 @@
 //Copyright (c) 2017. 章钦豪. All rights reserved.
 //Copyright (c) 2017. 章钦豪. All rights reserved.
 package io.legado.app.utils
 package io.legado.app.utils
 
 
-import android.content.Context
 import android.graphics.Bitmap
 import android.graphics.Bitmap
 import android.graphics.BitmapFactory
 import android.graphics.BitmapFactory
 import android.graphics.Canvas
 import android.graphics.Canvas
@@ -11,7 +10,6 @@ import android.graphics.drawable.Drawable
 import org.json.JSONArray
 import org.json.JSONArray
 import org.json.JSONObject
 import org.json.JSONObject
 import splitties.init.appCtx
 import splitties.init.appCtx
-
 import java.io.*
 import java.io.*
 import java.util.*
 import java.util.*
 import java.util.concurrent.atomic.AtomicInteger
 import java.util.concurrent.atomic.AtomicInteger
@@ -34,13 +32,13 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
 
 
         @JvmOverloads
         @JvmOverloads
         fun get(
         fun get(
-            ctx: Context,
             cacheName: String = "ACache",
             cacheName: String = "ACache",
             maxSize: Long = MAX_SIZE.toLong(),
             maxSize: Long = MAX_SIZE.toLong(),
             maxCount: Int = MAX_COUNT,
             maxCount: Int = MAX_COUNT,
             cacheDir: Boolean = true
             cacheDir: Boolean = true
         ): ACache {
         ): 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)
             return get(f, maxSize, maxCount)
         }
         }