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()
}
fun setFilterValues(values: List<String>, delCallBack: ((value: String) -> Unit)? = null) {
fun setFilterValues(values: List<String>?, 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) {

@ -165,13 +165,17 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
@SuppressLint("InflateParams")
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) {
var editText: ATEAutoCompleteTextView? = null
customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
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>()
@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

Loading…
Cancel
Save