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