pull/35/head
kunfei 5 years ago
parent c0ee91f8f4
commit cab4193ea1
  1. 6
      app/src/main/java/io/legado/app/lib/theme/view/ATEAutoCompleteTextView.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  3. 30
      app/src/main/java/io/legado/app/utils/ACache.kt

@ -38,9 +38,11 @@ class ATEAutoCompleteTextView : AppCompatAutoCompleteTextView {
showDropDown() showDropDown()
} }
fun setFilterValues(values: List<String>, delCallBack: ((value: String) -> Unit)? = null) { fun setFilterValues(values: List<String>?, delCallBack: ((value: String) -> Unit)? = null) {
this.delCallBack = delCallBack this.delCallBack = delCallBack
setAdapter(MyAdapter(context, values)) values?.let {
setAdapter(MyAdapter(context, values))
}
} }
fun setFilterValues(vararg value: String, delCallBack: ((value: String) -> Unit)? = null) { fun setFilterValues(vararg value: String, delCallBack: ((value: String) -> Unit)? = null) {

@ -165,13 +165,17 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
private fun showImportDialog() { private fun showImportDialog() {
val cacheUrls = ACache.get(this, "cacheUrls") val cacheUrls: List<String>? = ACache
.get(this, "cacheUrls", cacheDir = false)
?.getAsString("sourceUrl")
?.splitNotBlank(";")
?.toMutableList()
alert(titleResource = R.string.import_book_source_on_line) { alert(titleResource = R.string.import_book_source_on_line) {
var editText: ATEAutoCompleteTextView? = null var editText: ATEAutoCompleteTextView? = null
customView { customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
editText = edit_view editText = edit_view
edit_view.setFilterValues("") { edit_view.setFilterValues(cacheUrls) {
} }
} }

@ -769,31 +769,27 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
private val mInstanceMap = HashMap<String, ACache>() private val mInstanceMap = HashMap<String, ACache>()
@JvmOverloads @JvmOverloads
operator fun get(ctx: Context, cacheName: String = "ACache"): ACache? { fun get(
val f = File(ctx.cacheDir, cacheName) ctx: Context,
return get(f, MAX_SIZE.toLong(), MAX_COUNT) cacheName: String = "ACache",
} maxSize: Long = MAX_SIZE.toLong(),
maxCount: Int = MAX_COUNT,
operator fun get(ctx: Context, max_zise: Long, max_count: Int): ACache? { cacheDir: Boolean = true
try { ): ACache? {
val f = File(ctx.cacheDir, "ACache") val f = if (cacheDir) File(ctx.cacheDir, cacheName) else File(ctx.filesDir, cacheName)
return get(f, max_zise, max_count) return get(f, maxSize, maxCount)
} catch (ignored: Exception) {
}
return null
} }
@JvmOverloads @JvmOverloads
operator fun get( fun get(
cacheDir: File, cacheDir: File,
max_zise: Long = MAX_SIZE.toLong(), maxSize: Long = MAX_SIZE.toLong(),
max_count: Int = MAX_COUNT maxCount: Int = MAX_COUNT
): ACache? { ): ACache? {
try { try {
var manager = mInstanceMap[cacheDir.absoluteFile.toString() + myPid()] var manager = mInstanceMap[cacheDir.absoluteFile.toString() + myPid()]
if (manager == null) { if (manager == null) {
manager = ACache(cacheDir, max_zise, max_count) manager = ACache(cacheDir, maxSize, maxCount)
mInstanceMap[cacheDir.absolutePath + myPid()] = manager mInstanceMap[cacheDir.absolutePath + myPid()] = manager
} }
return manager return manager

Loading…
Cancel
Save