优化
This commit is contained in:
@@ -45,7 +45,9 @@ import kotlinx.coroutines.*
|
|||||||
import kotlinx.coroutines.flow.catch
|
import kotlinx.coroutines.flow.catch
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import kotlinx.coroutines.flow.mapLatest
|
||||||
|
|
||||||
|
@ExperimentalCoroutinesApi
|
||||||
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
|
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
|
||||||
PopupMenu.OnMenuItemClickListener,
|
PopupMenu.OnMenuItemClickListener,
|
||||||
BookSourceAdapter.CallBack,
|
BookSourceAdapter.CallBack,
|
||||||
@@ -207,6 +209,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|||||||
searchView.setOnQueryTextListener(this)
|
searchView.setOnQueryTextListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun upBookSource(searchKey: String? = null) {
|
private fun upBookSource(searchKey: String? = null) {
|
||||||
sourceFlowJob?.cancel()
|
sourceFlowJob?.cancel()
|
||||||
sourceFlowJob = launch {
|
sourceFlowJob = launch {
|
||||||
@@ -232,8 +235,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|||||||
}
|
}
|
||||||
}.catch {
|
}.catch {
|
||||||
AppLog.put("书源界面更新书源出错", it)
|
AppLog.put("书源界面更新书源出错", it)
|
||||||
}.collectLatest { data ->
|
}.mapLatest { data ->
|
||||||
val sourceList =
|
|
||||||
if (sortAscending) when (sort) {
|
if (sortAscending) when (sort) {
|
||||||
Sort.Weight -> data.sortedBy { it.weight }
|
Sort.Weight -> data.sortedBy { it.weight }
|
||||||
Sort.Name -> data.sortedWith { o1, o2 ->
|
Sort.Name -> data.sortedWith { o1, o2 ->
|
||||||
@@ -268,7 +270,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
|||||||
}
|
}
|
||||||
else -> data.reversed()
|
else -> data.reversed()
|
||||||
}
|
}
|
||||||
adapter.setItems(sourceList, adapter.diffItemCallback)
|
}.collectLatest { data ->
|
||||||
|
adapter.setItems(data, adapter.diffItemCallback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user