MangaDialogs.kt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package eu.kanade.presentation.manga.components
  2. import androidx.compose.foundation.layout.BoxWithConstraints
  3. import androidx.compose.foundation.layout.fillMaxWidth
  4. import androidx.compose.material3.AlertDialog
  5. import androidx.compose.material3.Text
  6. import androidx.compose.material3.TextButton
  7. import androidx.compose.runtime.Composable
  8. import androidx.compose.runtime.getValue
  9. import androidx.compose.runtime.mutableIntStateOf
  10. import androidx.compose.runtime.saveable.rememberSaveable
  11. import androidx.compose.runtime.setValue
  12. import androidx.compose.ui.Alignment
  13. import androidx.compose.ui.Modifier
  14. import androidx.compose.ui.res.stringResource
  15. import androidx.compose.ui.unit.DpSize
  16. import androidx.compose.ui.unit.dp
  17. import eu.kanade.tachiyomi.R
  18. import tachiyomi.domain.manga.interactor.MAX_GRACE_PERIOD
  19. import tachiyomi.presentation.core.components.WheelTextPicker
  20. @Composable
  21. fun DeleteChaptersDialog(
  22. onDismissRequest: () -> Unit,
  23. onConfirm: () -> Unit,
  24. ) {
  25. AlertDialog(
  26. onDismissRequest = onDismissRequest,
  27. dismissButton = {
  28. TextButton(onClick = onDismissRequest) {
  29. Text(text = stringResource(R.string.action_cancel))
  30. }
  31. },
  32. confirmButton = {
  33. TextButton(
  34. onClick = {
  35. onDismissRequest()
  36. onConfirm()
  37. },
  38. ) {
  39. Text(text = stringResource(R.string.action_ok))
  40. }
  41. },
  42. title = {
  43. Text(text = stringResource(R.string.are_you_sure))
  44. },
  45. text = {
  46. Text(text = stringResource(R.string.confirm_delete_chapters))
  47. },
  48. )
  49. }
  50. @Composable
  51. fun SetIntervalDialog(
  52. interval: Int,
  53. onDismissRequest: () -> Unit,
  54. onValueChanged: (Int) -> Unit,
  55. ) {
  56. var intervalValue by rememberSaveable { mutableIntStateOf(interval) }
  57. AlertDialog(
  58. onDismissRequest = onDismissRequest,
  59. title = { Text(text = stringResource(R.string.manga_modify_calculated_interval_title)) },
  60. text = {
  61. BoxWithConstraints(
  62. modifier = Modifier.fillMaxWidth(),
  63. contentAlignment = Alignment.Center,
  64. ) {
  65. val size = DpSize(width = maxWidth / 2, height = 128.dp)
  66. val items = (0..MAX_GRACE_PERIOD).map {
  67. if (it == 0) {
  68. stringResource(R.string.label_default)
  69. } else {
  70. it.toString()
  71. }
  72. }
  73. WheelTextPicker(
  74. size = size,
  75. items = items,
  76. startIndex = intervalValue,
  77. onSelectionChanged = { intervalValue = it },
  78. )
  79. }
  80. },
  81. dismissButton = {
  82. TextButton(onClick = onDismissRequest) {
  83. Text(text = stringResource(R.string.action_cancel))
  84. }
  85. },
  86. confirmButton = {
  87. TextButton(onClick = {
  88. onValueChanged(intervalValue)
  89. onDismissRequest()
  90. },) {
  91. Text(text = stringResource(R.string.action_ok))
  92. }
  93. },
  94. )
  95. }