ReaderSettingsDialog.kt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package eu.kanade.presentation.reader.settings
  2. import androidx.compose.foundation.layout.BoxWithConstraints
  3. import androidx.compose.foundation.layout.Column
  4. import androidx.compose.foundation.layout.heightIn
  5. import androidx.compose.foundation.layout.padding
  6. import androidx.compose.foundation.pager.rememberPagerState
  7. import androidx.compose.foundation.rememberScrollState
  8. import androidx.compose.foundation.verticalScroll
  9. import androidx.compose.runtime.Composable
  10. import androidx.compose.runtime.LaunchedEffect
  11. import androidx.compose.ui.Modifier
  12. import androidx.compose.ui.platform.LocalView
  13. import androidx.compose.ui.res.stringResource
  14. import androidx.compose.ui.window.DialogWindowProvider
  15. import eu.kanade.presentation.components.TabbedDialog
  16. import eu.kanade.presentation.components.TabbedDialogPaddings
  17. import eu.kanade.tachiyomi.R
  18. import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel
  19. @Composable
  20. fun ReaderSettingsDialog(
  21. onDismissRequest: () -> Unit,
  22. onShowMenus: () -> Unit,
  23. onHideMenus: () -> Unit,
  24. screenModel: ReaderSettingsScreenModel,
  25. ) {
  26. val tabTitles = listOf(
  27. stringResource(R.string.pref_category_reading_mode),
  28. stringResource(R.string.pref_category_general),
  29. stringResource(R.string.custom_filter),
  30. )
  31. val pagerState = rememberPagerState { tabTitles.size }
  32. BoxWithConstraints {
  33. TabbedDialog(
  34. modifier = Modifier.heightIn(max = maxHeight * 0.75f),
  35. onDismissRequest = {
  36. onDismissRequest()
  37. onShowMenus()
  38. },
  39. tabTitles = tabTitles,
  40. pagerState = pagerState,
  41. ) { page ->
  42. val window = (LocalView.current.parent as? DialogWindowProvider)?.window
  43. LaunchedEffect(pagerState.currentPage) {
  44. if (pagerState.currentPage == 2) {
  45. window?.setDimAmount(0f)
  46. onHideMenus()
  47. } else {
  48. window?.setDimAmount(0.5f)
  49. onShowMenus()
  50. }
  51. }
  52. Column(
  53. modifier = Modifier
  54. .padding(vertical = TabbedDialogPaddings.Vertical)
  55. .verticalScroll(rememberScrollState()),
  56. ) {
  57. when (page) {
  58. 0 -> ReadingModePage(screenModel)
  59. 1 -> GeneralPage(screenModel)
  60. 2 -> ColorFilterPage(screenModel)
  61. }
  62. }
  63. }
  64. }
  65. }