Fix pages thumbnails loading
parent
5b53f8c27d
commit
97524d66f2
@ -1,16 +0,0 @@
|
||||
package org.koitharu.kotatsu.history.domain.model
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import org.koitharu.kotatsu.R
|
||||
|
||||
enum class HistoryOrder(
|
||||
@StringRes val titleResId: Int,
|
||||
) {
|
||||
|
||||
UPDATED(R.string.updated),
|
||||
CREATED(R.string.order_added),
|
||||
PROGRESS(R.string.progress),
|
||||
ALPHABETIC(R.string.by_name);
|
||||
|
||||
fun isGroupingSupported() = this == UPDATED || this == CREATED || this == PROGRESS
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package org.koitharu.kotatsu.list.domain
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.parsers.util.find
|
||||
import java.util.EnumSet
|
||||
|
||||
enum class ListSortOrder(
|
||||
@StringRes val titleResId: Int,
|
||||
) {
|
||||
|
||||
UPDATED(R.string.updated),
|
||||
NEWEST(R.string.order_added),
|
||||
PROGRESS(R.string.progress),
|
||||
ALPHABETIC(R.string.by_name),
|
||||
RATING(R.string.by_rating),
|
||||
RELEVANCE(R.string.by_relevance),
|
||||
;
|
||||
|
||||
fun isGroupingSupported() = this == UPDATED || this == NEWEST || this == PROGRESS
|
||||
|
||||
companion object {
|
||||
|
||||
val HISTORY = EnumSet.of(UPDATED, NEWEST, PROGRESS, ALPHABETIC)
|
||||
val FAVORITES = EnumSet.of(ALPHABETIC, NEWEST, RATING)
|
||||
val SUGGESTIONS = EnumSet.of(RELEVANCE)
|
||||
|
||||
operator fun invoke(value: String, fallback: ListSortOrder) = entries.find(value) ?: fallback
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package org.koitharu.kotatsu.list.ui.config
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
sealed interface ListConfigSection : Parcelable {
|
||||
|
||||
@Parcelize
|
||||
data object History : ListConfigSection
|
||||
|
||||
@Parcelize
|
||||
data object General : ListConfigSection
|
||||
|
||||
@Parcelize
|
||||
data class Favorites(
|
||||
val categoryId: Long,
|
||||
) : ListConfigSection
|
||||
|
||||
@Parcelize
|
||||
data object Suggestions : ListConfigSection
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package org.koitharu.kotatsu.list.ui.config
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||
import org.koitharu.kotatsu.core.ui.BaseViewModel
|
||||
import org.koitharu.kotatsu.core.util.ext.require
|
||||
import org.koitharu.kotatsu.core.util.ext.sortedByOrdinal
|
||||
import org.koitharu.kotatsu.favourites.domain.FavouritesRepository
|
||||
import org.koitharu.kotatsu.list.domain.ListSortOrder
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class ListConfigViewModel @Inject constructor(
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val settings: AppSettings,
|
||||
private val favouritesRepository: FavouritesRepository,
|
||||
) : BaseViewModel() {
|
||||
|
||||
val section = savedStateHandle.require<ListConfigSection>(ListConfigBottomSheet.ARG_SECTION)
|
||||
|
||||
var listMode: ListMode
|
||||
get() = when (section) {
|
||||
is ListConfigSection.Favorites -> settings.favoritesListMode
|
||||
ListConfigSection.General -> settings.listMode
|
||||
ListConfigSection.History -> settings.historyListMode
|
||||
ListConfigSection.Suggestions -> settings.suggestionsListMode
|
||||
}
|
||||
set(value) {
|
||||
when (section) {
|
||||
is ListConfigSection.Favorites -> settings.favoritesListMode = value
|
||||
ListConfigSection.General -> settings.listMode = value
|
||||
ListConfigSection.History -> settings.historyListMode = value
|
||||
ListConfigSection.Suggestions -> settings.suggestionsListMode = value
|
||||
}
|
||||
}
|
||||
|
||||
var gridSize: Int
|
||||
get() = settings.gridSize
|
||||
set(value) {
|
||||
settings.gridSize = value
|
||||
}
|
||||
|
||||
val isGroupingAvailable: Boolean
|
||||
get() = section == ListConfigSection.History
|
||||
|
||||
fun getSortOrders(): List<ListSortOrder>? = when (section) {
|
||||
is ListConfigSection.Favorites -> ListSortOrder.FAVORITES
|
||||
ListConfigSection.General -> null
|
||||
ListConfigSection.History -> ListSortOrder.HISTORY
|
||||
ListConfigSection.Suggestions -> ListSortOrder.SUGGESTIONS
|
||||
}?.sortedByOrdinal()
|
||||
|
||||
fun getSelectedSortOrder(): ListSortOrder? = when (section) {
|
||||
is ListConfigSection.Favorites -> runBlocking { favouritesRepository.getCategory(section.categoryId).order }
|
||||
ListConfigSection.General -> null
|
||||
ListConfigSection.History -> settings.historySortOrder
|
||||
ListConfigSection.Suggestions -> ListSortOrder.RELEVANCE // TODO
|
||||
}
|
||||
|
||||
fun setSortOrder(position: Int) {
|
||||
val value = getSortOrders()?.getOrNull(position) ?: return
|
||||
when (section) {
|
||||
is ListConfigSection.Favorites -> launchJob {
|
||||
favouritesRepository.setCategoryOrder(section.categoryId, value)
|
||||
}
|
||||
|
||||
ListConfigSection.General -> Unit
|
||||
ListConfigSection.History -> settings.historySortOrder = value
|
||||
|
||||
ListConfigSection.Suggestions -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue