feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 62f5e6ce4d
commit 76cecb4c1a
  1. 4
      app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt
  2. 4
      app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt
  3. 8
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -9,6 +9,10 @@ import android.content.Context
*/
abstract class ItemViewDelegate<ITEM>(protected val context: Context, val layoutId: Int) {
/**
* 如果使用了事件回调,回调里不要直接使用item,会出现不更新的问题,
* 使用getItem(holder.layoutPosition)来获取item
*/
abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>)
}

@ -18,5 +18,9 @@ abstract class SimpleRecyclerAdapter<ITEM>(context: Context, private val layoutI
})
}
/**
* 如果使用了事件回调,回调里不要直接使用item,会出现不更新的问题,
* 使用getItem(holder.layoutPosition)来获取item
*/
abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>)
}

@ -27,7 +27,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
var author: String = ""
private var task: Coroutine<*>? = null
private var screenKey: String = ""
private val searchBooks = linkedSetOf<SearchBook>()
private val searchBooks = hashSetOf<SearchBook>()
fun initData(arguments: Bundle?) {
arguments?.let { bundle ->
@ -50,10 +50,8 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
}
private fun upAdapter() {
execute {
val books = searchBooks.toList()
searchBooksLiveData.postValue(books.sortedBy { it.originOrder })
}
val books = searchBooks.toList()
searchBooksLiveData.postValue(books.sortedBy { it.originOrder })
}
private fun searchFinish(searchBook: SearchBook) {

Loading…
Cancel
Save