Implement showing selected per-series reader settings

This commit is contained in:
arkon 2023-07-15 12:39:36 -04:00
parent 28131ac135
commit fb99577836
4 changed files with 14 additions and 9 deletions

View File

@ -6,6 +6,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import eu.kanade.domain.manga.model.orientationType
import eu.kanade.domain.manga.model.readingModeType
import eu.kanade.presentation.util.collectAsState import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.setting.OrientationType import eu.kanade.tachiyomi.ui.reader.setting.OrientationType
@ -26,12 +28,15 @@ internal fun ColumnScope.ReadingModePage(screenModel: ReaderSettingsScreenModel)
HeadingItem(R.string.pref_category_for_this_series) HeadingItem(R.string.pref_category_for_this_series)
val manga by screenModel.mangaFlow.collectAsState()
val readingMode = remember(manga) { ReadingModeType.fromPreference(manga?.readingModeType?.toInt()) }
val orientation = remember(manga) { OrientationType.fromPreference(manga?.orientationType?.toInt()) }
HeadingItem(R.string.pref_category_reading_mode) HeadingItem(R.string.pref_category_reading_mode)
ReadingModeType.values().map { ReadingModeType.values().map {
RadioItem( RadioItem(
label = stringResource(it.stringRes), label = stringResource(it.stringRes),
// TODO: Reading mode selected = readingMode == it,
selected = false,
onClick = { screenModel.onChangeReadingMode(it) }, onClick = { screenModel.onChangeReadingMode(it) },
) )
} }
@ -40,8 +45,7 @@ internal fun ColumnScope.ReadingModePage(screenModel: ReaderSettingsScreenModel)
OrientationType.values().map { OrientationType.values().map {
RadioItem( RadioItem(
label = stringResource(it.stringRes), label = stringResource(it.stringRes),
// TODO: Rotation type selected = orientation == it,
selected = false,
onClick = { screenModel.onChangeOrientation(it) }, onClick = { screenModel.onChangeOrientation(it) },
) )
} }

View File

@ -18,8 +18,6 @@ enum class OrientationType(val prefValue: Int, val flag: Int, @StringRes val str
companion object { companion object {
const val MASK = 0x00000038 const val MASK = 0x00000038
fun fromPreference(preference: Int?): OrientationType = values().find { it.flagValue == preference } ?: FREE fun fromPreference(preference: Int?): OrientationType = values().find { it.flagValue == preference } ?: DEFAULT
fun fromSpinner(position: Int?) = values().find { value -> value.prefValue == position } ?: DEFAULT
} }
} }

View File

@ -25,6 +25,11 @@ class ReaderSettingsScreenModel(
.distinctUntilChanged() .distinctUntilChanged()
.stateIn(ioCoroutineScope, SharingStarted.Lazily, null) .stateIn(ioCoroutineScope, SharingStarted.Lazily, null)
val mangaFlow = readerState
.map { it.manga }
.distinctUntilChanged()
.stateIn(ioCoroutineScope, SharingStarted.Lazily, null)
fun togglePreference(preference: (ReaderPreferences) -> Preference<Boolean>) { fun togglePreference(preference: (ReaderPreferences) -> Preference<Boolean>) {
preference(preferences).toggle() preference(preferences).toggle()
} }

View File

@ -29,8 +29,6 @@ enum class ReadingModeType(val prefValue: Int, @StringRes val stringRes: Int, @D
return mode == LEFT_TO_RIGHT || mode == RIGHT_TO_LEFT || mode == VERTICAL return mode == LEFT_TO_RIGHT || mode == RIGHT_TO_LEFT || mode == VERTICAL
} }
fun fromSpinner(position: Int?) = values().find { value -> value.prefValue == position } ?: DEFAULT
fun toViewer(preference: Int?, activity: ReaderActivity): Viewer { fun toViewer(preference: Int?, activity: ReaderActivity): Viewer {
return when (fromPreference(preference)) { return when (fromPreference(preference)) {
LEFT_TO_RIGHT -> L2RPagerViewer(activity) LEFT_TO_RIGHT -> L2RPagerViewer(activity)