pull/35/head
kunfei 5 years ago
parent 3efd936357
commit d8e33b1d9c
  1. 4
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  4. 8
      app/src/main/java/io/legado/app/utils/ACache.kt

@ -126,7 +126,7 @@ data class BookSource(
try { try {
if (it.startsWith("<js>", false)) { if (it.startsWith("<js>", false)) {
val aCache = ACache.get(App.INSTANCE, "explore") val aCache = ACache.get(App.INSTANCE, "explore")
a = aCache?.getAsString(bookSourceUrl) ?: "" a = aCache.getAsString(bookSourceUrl) ?: ""
if (a.isBlank()) { if (a.isBlank()) {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl bindings["baseUrl"] = bookSourceUrl
@ -135,7 +135,7 @@ data class BookSource(
it.substring(4, it.lastIndexOf("<")), it.substring(4, it.lastIndexOf("<")),
bindings bindings
).toString() ).toString()
aCache?.put(bookSourceUrl, a) aCache.put(bookSourceUrl, a)
} }
} }
val b = a.split("(&&|\n)+".toRegex()) val b = a.split("(&&|\n)+".toRegex())

@ -167,7 +167,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
private fun showImportDialog() { private fun showImportDialog() {
val cacheUrls: List<String>? = ACache val cacheUrls: List<String>? = ACache
.get(this, "cacheUrls", cacheDir = false) .get(this, "cacheUrls", cacheDir = false)
?.getAsString("sourceUrl") .getAsString("sourceUrl")
?.splitNotBlank(";") ?.splitNotBlank(";")
?.toMutableList() ?.toMutableList()
alert(titleResource = R.string.import_book_source_on_line) { alert(titleResource = R.string.import_book_source_on_line) {

@ -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_edit -> callBack.editSource(item.bookSourceUrl)
R.id.menu_top -> callBack.toTop(item) R.id.menu_top -> callBack.toTop(item)
R.id.menu_refresh -> { R.id.menu_refresh -> {
ACache.get(context, "explore")?.remove(item.bookSourceUrl) ACache.get(context, "explore").remove(item.bookSourceUrl)
notifyItemChanged(holder.layoutPosition) notifyItemChanged(holder.layoutPosition)
} }
} }

@ -776,7 +776,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
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(ctx.cacheDir, cacheName) else File(ctx.filesDir, cacheName)
return get(f, maxSize, maxCount) return get(f, maxSize, maxCount)
} }
@ -786,17 +786,15 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
cacheDir: File, cacheDir: File,
maxSize: Long = MAX_SIZE.toLong(), maxSize: Long = MAX_SIZE.toLong(),
maxCount: Int = MAX_COUNT maxCount: Int = MAX_COUNT
): ACache? { ): ACache {
try { synchronized(this) {
var manager = mInstanceMap[cacheDir.absoluteFile.toString() + myPid()] var manager = mInstanceMap[cacheDir.absoluteFile.toString() + myPid()]
if (manager == null) { if (manager == null) {
manager = ACache(cacheDir, maxSize, maxCount) manager = ACache(cacheDir, maxSize, maxCount)
mInstanceMap[cacheDir.absolutePath + myPid()] = manager mInstanceMap[cacheDir.absolutePath + myPid()] = manager
} }
return manager return manager
} catch (ignored: Exception) {
} }
return null
} }
private fun myPid(): String { private fun myPid(): String {

Loading…
Cancel
Save