Fix list mode changing

pull/293/head
Koitharu 3 years ago
parent 8a2706d70b
commit 7f530d0476
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -55,7 +55,7 @@ class FavouritesListViewModel @AssistedInject constructor(
} else {
repository.observeAll(categoryId)
},
createListModeFlow(),
listModeFlow,
) { list, mode ->
when {
list.isEmpty() -> listOf(

@ -48,7 +48,7 @@ class HistoryListViewModel @Inject constructor(
override val content = combine(
repository.observeAllWithHistory(),
historyGrouping,
createListModeFlow(),
listModeFlow,
) { list, grouped, mode ->
when {
list.isEmpty() -> listOf(

@ -49,6 +49,9 @@ class ListModeBottomSheet :
}
override fun onButtonChecked(group: MaterialButtonToggleGroup?, checkedId: Int, isChecked: Boolean) {
if (!isChecked) {
return
}
val mode = when (checkedId) {
R.id.button_list -> ListMode.LIST
R.id.button_list_detailed -> ListMode.DETAILED_LIST

@ -1,26 +1,29 @@
package org.koitharu.kotatsu.list.ui
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.plus
import org.koitharu.kotatsu.base.ui.BaseViewModel
import org.koitharu.kotatsu.base.ui.util.ReversibleAction
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.prefs.ListMode
import org.koitharu.kotatsu.core.prefs.observeAsFlow
import org.koitharu.kotatsu.core.prefs.observeAsLiveData
import org.koitharu.kotatsu.list.ui.model.ListModel
import org.koitharu.kotatsu.parsers.model.MangaTag
import org.koitharu.kotatsu.utils.SingleLiveEvent
import org.koitharu.kotatsu.utils.asFlowLiveData
abstract class MangaListViewModel(
private val settings: AppSettings,
) : BaseViewModel() {
abstract val content: LiveData<List<ListModel>>
val listMode = MutableLiveData<ListMode>()
protected val listModeFlow = settings.observeAsFlow(AppSettings.KEY_LIST_MODE) { listMode }
.stateIn(viewModelScope + Dispatchers.Default, SharingStarted.Lazily, settings.listMode)
val listMode = listModeFlow.asFlowLiveData(viewModelScope.coroutineContext)
val onActionDone = SingleLiveEvent<ReversibleAction>()
val gridScale = settings.observeAsLiveData(
context = viewModelScope.coroutineContext + Dispatchers.Default,
@ -30,13 +33,6 @@ abstract class MangaListViewModel(
open fun onUpdateFilter(tags: Set<MangaTag>) = Unit
protected fun createListModeFlow() = settings.observeAsFlow(AppSettings.KEY_LIST_MODE) { listMode }
.onEach {
if (listMode.value != it) {
listMode.postValue(it)
}
}
abstract fun onRefresh()
abstract fun onRetry()

@ -57,7 +57,7 @@ class LocalListViewModel @Inject constructor(
override val content = combine(
mangaList,
createListModeFlow(),
listModeFlow,
sortOrder.asFlow(),
selectedTags,
listError,

@ -63,7 +63,7 @@ class RemoteListViewModel @AssistedInject constructor(
override val content = combine(
mangaList,
createListModeFlow(),
listModeFlow,
createHeaderFlow(),
listError,
hasNextPage,

@ -39,7 +39,7 @@ class SearchViewModel @AssistedInject constructor(
override val content = combine(
mangaList,
createListModeFlow(),
listModeFlow,
listError,
hasNextPage,
) { list, mode, error, hasNext ->

@ -2,7 +2,6 @@ package org.koitharu.kotatsu.suggestions.ui
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine
@ -17,6 +16,7 @@ import org.koitharu.kotatsu.list.ui.model.toUi
import org.koitharu.kotatsu.suggestions.domain.SuggestionRepository
import org.koitharu.kotatsu.utils.asFlowLiveData
import org.koitharu.kotatsu.utils.ext.onFirst
import javax.inject.Inject
@HiltViewModel
class SuggestionsViewModel @Inject constructor(
@ -26,7 +26,7 @@ class SuggestionsViewModel @Inject constructor(
override val content = combine(
repository.observeAll(),
createListModeFlow(),
listModeFlow,
) { list, mode ->
when {
list.isEmpty() -> listOf(
@ -37,6 +37,7 @@ class SuggestionsViewModel @Inject constructor(
actionStringRes = 0,
),
)
else -> list.toUi(mode)
}
}.onStart {

@ -34,7 +34,7 @@ class UpdatesViewModel @Inject constructor(
override val content = combine(
repository.observeUpdatedManga(),
createListModeFlow(),
listModeFlow,
) { mangaMap, mode ->
when {
mangaMap.isEmpty() -> listOf(

Loading…
Cancel
Save