ReadingModeSelectDialog.kt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package eu.kanade.presentation.reader
  2. import androidx.compose.foundation.layout.Box
  3. import androidx.compose.foundation.layout.fillMaxWidth
  4. import androidx.compose.foundation.layout.padding
  5. import androidx.compose.foundation.lazy.grid.items
  6. import androidx.compose.material3.MaterialTheme
  7. import androidx.compose.runtime.Composable
  8. import androidx.compose.runtime.collectAsState
  9. import androidx.compose.runtime.getValue
  10. import androidx.compose.runtime.remember
  11. import androidx.compose.ui.Modifier
  12. import androidx.compose.ui.graphics.vector.ImageVector
  13. import androidx.compose.ui.res.stringResource
  14. import androidx.compose.ui.res.vectorResource
  15. import eu.kanade.domain.manga.model.readingModeType
  16. import eu.kanade.presentation.components.AdaptiveSheet
  17. import eu.kanade.tachiyomi.R
  18. import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel
  19. import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
  20. import tachiyomi.presentation.core.components.SettingsIconGrid
  21. import tachiyomi.presentation.core.components.material.IconToggleButton
  22. import tachiyomi.presentation.core.components.material.padding
  23. private val readingModeOptions = ReadingModeType.entries.map { it.stringRes to it }
  24. @Composable
  25. fun ReadingModeSelectDialog(
  26. onDismissRequest: () -> Unit,
  27. screenModel: ReaderSettingsScreenModel,
  28. onChange: (Int) -> Unit,
  29. ) {
  30. val manga by screenModel.mangaFlow.collectAsState()
  31. val readingMode = remember(manga) { ReadingModeType.fromPreference(manga?.readingModeType?.toInt()) }
  32. AdaptiveSheet(onDismissRequest = onDismissRequest) {
  33. Box(modifier = Modifier.padding(vertical = MaterialTheme.padding.medium)) {
  34. SettingsIconGrid(R.string.pref_category_reading_mode) {
  35. items(readingModeOptions) { (stringRes, mode) ->
  36. IconToggleButton(
  37. checked = mode == readingMode,
  38. onCheckedChange = {
  39. screenModel.onChangeReadingMode(mode)
  40. onChange(stringRes)
  41. onDismissRequest()
  42. },
  43. modifier = Modifier.fillMaxWidth(),
  44. imageVector = ImageVector.vectorResource(mode.iconRes),
  45. title = stringResource(stringRes),
  46. )
  47. }
  48. }
  49. }
  50. }
  51. }