From d8e33b1d9c4406b03ba60728706738a6232f9a6b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 25 Sep 2019 21:45:02 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/data/entities/BookSource.kt | 4 ++-- .../app/ui/book/source/manage/BookSourceActivity.kt | 2 +- .../java/io/legado/app/ui/main/explore/ExploreAdapter.kt | 2 +- app/src/main/java/io/legado/app/utils/ACache.kt | 8 +++----- 4 files changed, 7 insertions(+), 9 deletions(-) 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 d2a61e330..a8a88e4cb 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 @@ -126,7 +126,7 @@ data class BookSource( try { if (it.startsWith("", false)) { val aCache = ACache.get(App.INSTANCE, "explore") - a = aCache?.getAsString(bookSourceUrl) ?: "" + a = aCache.getAsString(bookSourceUrl) ?: "" if (a.isBlank()) { val bindings = SimpleBindings() bindings["baseUrl"] = bookSourceUrl @@ -135,7 +135,7 @@ data class BookSource( it.substring(4, it.lastIndexOf("<")), bindings ).toString() - aCache?.put(bookSourceUrl, a) + aCache.put(bookSourceUrl, a) } } val b = a.split("(&&|\n)+".toRegex()) 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 c00d4167f..df1202bc8 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 @@ -167,7 +167,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private fun showImportDialog() { val cacheUrls: List? = ACache .get(this, "cacheUrls", cacheDir = false) - ?.getAsString("sourceUrl") + .getAsString("sourceUrl") ?.splitNotBlank(";") ?.toMutableList() alert(titleResource = R.string.import_book_source_on_line) { 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 136d7d4bf..0bc6c0891 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 @@ -48,7 +48,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca R.id.menu_edit -> callBack.editSource(item.bookSourceUrl) R.id.menu_top -> callBack.toTop(item) R.id.menu_refresh -> { - ACache.get(context, "explore")?.remove(item.bookSourceUrl) + ACache.get(context, "explore").remove(item.bookSourceUrl) notifyItemChanged(holder.layoutPosition) } } 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 c9b2fda3d..570560e76 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -776,7 +776,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) maxSize: Long = MAX_SIZE.toLong(), maxCount: Int = MAX_COUNT, cacheDir: Boolean = true - ): ACache? { + ): ACache { val f = if (cacheDir) File(ctx.cacheDir, cacheName) else File(ctx.filesDir, cacheName) return get(f, maxSize, maxCount) } @@ -786,17 +786,15 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) cacheDir: File, maxSize: Long = MAX_SIZE.toLong(), maxCount: Int = MAX_COUNT - ): ACache? { - try { + ): ACache { + synchronized(this) { var manager = mInstanceMap[cacheDir.absoluteFile.toString() + myPid()] if (manager == null) { manager = ACache(cacheDir, maxSize, maxCount) mInstanceMap[cacheDir.absolutePath + myPid()] = manager } return manager - } catch (ignored: Exception) { } - return null } private fun myPid(): String {