diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt b/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt index c88327109..8fb7063e0 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt @@ -38,9 +38,11 @@ class ATEAutoCompleteTextView : AppCompatAutoCompleteTextView { showDropDown() } - fun setFilterValues(values: List, delCallBack: ((value: String) -> Unit)? = null) { + fun setFilterValues(values: List?, delCallBack: ((value: String) -> Unit)? = null) { this.delCallBack = delCallBack - setAdapter(MyAdapter(context, values)) + values?.let { + setAdapter(MyAdapter(context, values)) + } } fun setFilterValues(vararg value: String, delCallBack: ((value: String) -> Unit)? = null) { 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 95fa8f635..c00d4167f 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 @@ -165,13 +165,17 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity @SuppressLint("InflateParams") private fun showImportDialog() { - val cacheUrls = ACache.get(this, "cacheUrls") + val cacheUrls: List? = ACache + .get(this, "cacheUrls", cacheDir = false) + ?.getAsString("sourceUrl") + ?.splitNotBlank(";") + ?.toMutableList() alert(titleResource = R.string.import_book_source_on_line) { var editText: ATEAutoCompleteTextView? = null customView { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view - edit_view.setFilterValues("") { + edit_view.setFilterValues(cacheUrls) { } } 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 f40fac7f2..049b623da 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -769,31 +769,27 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) private val mInstanceMap = HashMap() @JvmOverloads - operator fun get(ctx: Context, cacheName: String = "ACache"): ACache? { - val f = File(ctx.cacheDir, cacheName) - return get(f, MAX_SIZE.toLong(), MAX_COUNT) - } - - operator fun get(ctx: Context, max_zise: Long, max_count: Int): ACache? { - try { - val f = File(ctx.cacheDir, "ACache") - return get(f, max_zise, max_count) - } catch (ignored: Exception) { - } - - return null + 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) + return get(f, maxSize, maxCount) } @JvmOverloads - operator fun get( + fun get( cacheDir: File, - max_zise: Long = MAX_SIZE.toLong(), - max_count: Int = MAX_COUNT + maxSize: Long = MAX_SIZE.toLong(), + maxCount: Int = MAX_COUNT ): ACache? { try { var manager = mInstanceMap[cacheDir.absoluteFile.toString() + myPid()] if (manager == null) { - manager = ACache(cacheDir, max_zise, max_count) + manager = ACache(cacheDir, maxSize, maxCount) mInstanceMap[cacheDir.absolutePath + myPid()] = manager } return manager