Cleanup Slider usage
(cherry picked from commit df9fff60da3a38acd8fcd540b5fdd275be93f2d5) # Conflicts: # app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt # app/src/main/java/eu/kanade/presentation/reader/components/ChapterNavigator.kt
This commit is contained in:
parent
b49ca3ce4c
commit
a8a290d03d
@ -84,7 +84,7 @@ fun ReaderAppBars(
|
|||||||
enabledPrevious: Boolean,
|
enabledPrevious: Boolean,
|
||||||
currentPage: Int,
|
currentPage: Int,
|
||||||
totalPages: Int,
|
totalPages: Int,
|
||||||
onSliderValueChange: (Int) -> Unit,
|
onPageIndexChange: (Int) -> Unit,
|
||||||
|
|
||||||
readingMode: ReadingMode,
|
readingMode: ReadingMode,
|
||||||
onClickReadingMode: () -> Unit,
|
onClickReadingMode: () -> Unit,
|
||||||
@ -154,7 +154,7 @@ fun ReaderAppBars(
|
|||||||
enabledPrevious = enabledPrevious,
|
enabledPrevious = enabledPrevious,
|
||||||
currentPage = currentPage,
|
currentPage = currentPage,
|
||||||
totalPages = totalPages,
|
totalPages = totalPages,
|
||||||
onSliderValueChange = onSliderValueChange,
|
onPageIndexChange = onPageIndexChange,
|
||||||
isVerticalSlider = true,
|
isVerticalSlider = true,
|
||||||
currentPageText = currentPageText,
|
currentPageText = currentPageText,
|
||||||
)
|
)
|
||||||
@ -182,7 +182,7 @@ fun ReaderAppBars(
|
|||||||
enabledPrevious = enabledPrevious,
|
enabledPrevious = enabledPrevious,
|
||||||
currentPage = currentPage,
|
currentPage = currentPage,
|
||||||
totalPages = totalPages,
|
totalPages = totalPages,
|
||||||
onSliderValueChange = onSliderValueChange,
|
onPageIndexChange = onPageIndexChange,
|
||||||
isVerticalSlider = true,
|
isVerticalSlider = true,
|
||||||
currentPageText = currentPageText,
|
currentPageText = currentPageText,
|
||||||
)
|
)
|
||||||
@ -285,7 +285,7 @@ fun ReaderAppBars(
|
|||||||
enabledPrevious = enabledPrevious,
|
enabledPrevious = enabledPrevious,
|
||||||
currentPage = currentPage,
|
currentPage = currentPage,
|
||||||
totalPages = totalPages,
|
totalPages = totalPages,
|
||||||
onSliderValueChange = onSliderValueChange,
|
onPageIndexChange = onPageIndexChange,
|
||||||
isVerticalSlider = false,
|
isVerticalSlider = false,
|
||||||
currentPageText = currentPageText,
|
currentPageText = currentPageText,
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,6 @@ import androidx.compose.material3.FilledIconButton
|
|||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButtonDefaults
|
import androidx.compose.material3.IconButtonDefaults
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Slider
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.surfaceColorAtElevation
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@ -45,8 +44,8 @@ import androidx.compose.ui.unit.dp
|
|||||||
import eu.kanade.presentation.theme.TachiyomiPreviewTheme
|
import eu.kanade.presentation.theme.TachiyomiPreviewTheme
|
||||||
import eu.kanade.presentation.util.isTabletUi
|
import eu.kanade.presentation.util.isTabletUi
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
|
import tachiyomi.presentation.core.components.material.Slider
|
||||||
import tachiyomi.presentation.core.i18n.stringResource
|
import tachiyomi.presentation.core.i18n.stringResource
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChapterNavigator(
|
fun ChapterNavigator(
|
||||||
@ -61,7 +60,7 @@ fun ChapterNavigator(
|
|||||||
currentPageText: String,
|
currentPageText: String,
|
||||||
// SY <--
|
// SY <--
|
||||||
totalPages: Int,
|
totalPages: Int,
|
||||||
onSliderValueChange: (Int) -> Unit,
|
onPageIndexChange: (Int) -> Unit,
|
||||||
) {
|
) {
|
||||||
// SY -->
|
// SY -->
|
||||||
if (isVerticalSlider) {
|
if (isVerticalSlider) {
|
||||||
@ -73,7 +72,7 @@ fun ChapterNavigator(
|
|||||||
currentPage = currentPage,
|
currentPage = currentPage,
|
||||||
currentPageText = currentPageText,
|
currentPageText = currentPageText,
|
||||||
totalPages = totalPages,
|
totalPages = totalPages,
|
||||||
onSliderValueChange = onSliderValueChange,
|
onPageIndexChange = onPageIndexChange,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -138,14 +137,11 @@ fun ChapterNavigator(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(horizontal = 8.dp),
|
.padding(horizontal = 8.dp),
|
||||||
value = currentPage.toFloat(),
|
value = currentPage,
|
||||||
valueRange = 1f..totalPages.toFloat(),
|
valueRange = 1..totalPages,
|
||||||
steps = totalPages - 2,
|
onValueChange = f@{
|
||||||
onValueChange = {
|
if (it == currentPage) return@f
|
||||||
val new = it.roundToInt() - 1
|
onPageIndexChange(it - 1)
|
||||||
if (new != currentPage) {
|
|
||||||
onSliderValueChange(new)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
)
|
)
|
||||||
@ -184,7 +180,7 @@ fun ChapterNavigatorVert(
|
|||||||
currentPageText: String,
|
currentPageText: String,
|
||||||
// SY <--
|
// SY <--
|
||||||
totalPages: Int,
|
totalPages: Int,
|
||||||
onSliderValueChange: (Int) -> Unit,
|
onPageIndexChange: (Int) -> Unit,
|
||||||
) {
|
) {
|
||||||
val isTabletUi = isTabletUi()
|
val isTabletUi = isTabletUi()
|
||||||
val verticalPadding = if (isTabletUi) 24.dp else 8.dp
|
val verticalPadding = if (isTabletUi) 24.dp else 8.dp
|
||||||
@ -259,11 +255,11 @@ fun ChapterNavigatorVert(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.weight(1f),
|
.weight(1f),
|
||||||
value = currentPage.toFloat(),
|
value = currentPage,
|
||||||
valueRange = 1f..totalPages.toFloat(),
|
valueRange = 1..totalPages,
|
||||||
steps = totalPages,
|
onValueChange = f@{
|
||||||
onValueChange = {
|
if (it == currentPage) return@f
|
||||||
onSliderValueChange(it.roundToInt() - 1)
|
onPageIndexChange(it - 1)
|
||||||
},
|
},
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
)
|
)
|
||||||
@ -301,7 +297,7 @@ private fun ChapterNavigatorPreview() {
|
|||||||
enabledPrevious = true,
|
enabledPrevious = true,
|
||||||
currentPage = currentPage,
|
currentPage = currentPage,
|
||||||
totalPages = 10,
|
totalPages = 10,
|
||||||
onSliderValueChange = { currentPage = it },
|
onPageIndexChange = { currentPage = (it + 1) },
|
||||||
// SY -->
|
// SY -->
|
||||||
currentPageText = "1",
|
currentPageText = "1",
|
||||||
isVerticalSlider = false,
|
isVerticalSlider = false,
|
||||||
|
@ -478,7 +478,7 @@ class ReaderActivity : BaseActivity() {
|
|||||||
enabledPrevious = state.viewerChapters?.prevChapter != null,
|
enabledPrevious = state.viewerChapters?.prevChapter != null,
|
||||||
currentPage = state.currentPage,
|
currentPage = state.currentPage,
|
||||||
totalPages = state.totalPages,
|
totalPages = state.totalPages,
|
||||||
onSliderValueChange = {
|
onPageIndexChange = {
|
||||||
isScrollingThroughPages = true
|
isScrollingThroughPages = true
|
||||||
moveToPageIndex(it)
|
moveToPageIndex(it)
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,6 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
import androidx.compose.material3.RadioButton
|
import androidx.compose.material3.RadioButton
|
||||||
import androidx.compose.material3.Slider
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
@ -47,6 +46,7 @@ import tachiyomi.core.common.preference.Preference
|
|||||||
import tachiyomi.core.common.preference.TriState
|
import tachiyomi.core.common.preference.TriState
|
||||||
import tachiyomi.core.common.preference.toggle
|
import tachiyomi.core.common.preference.toggle
|
||||||
import tachiyomi.presentation.core.components.material.DISABLED_ALPHA
|
import tachiyomi.presentation.core.components.material.DISABLED_ALPHA
|
||||||
|
import tachiyomi.presentation.core.components.material.Slider
|
||||||
import tachiyomi.presentation.core.components.material.padding
|
import tachiyomi.presentation.core.components.material.padding
|
||||||
import tachiyomi.presentation.core.i18n.stringResource
|
import tachiyomi.presentation.core.i18n.stringResource
|
||||||
import tachiyomi.presentation.core.theme.header
|
import tachiyomi.presentation.core.theme.header
|
||||||
@ -193,17 +193,14 @@ fun SliderItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Slider(
|
Slider(
|
||||||
value = value.toFloat(),
|
|
||||||
onValueChange = {
|
|
||||||
val newValue = it.toInt()
|
|
||||||
if (newValue != value) {
|
|
||||||
onChange(newValue)
|
|
||||||
haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.weight(1.5f),
|
modifier = Modifier.weight(1.5f),
|
||||||
valueRange = min.toFloat()..max.toFloat(),
|
value = value,
|
||||||
steps = max - min - 1,
|
onValueChange = f@{
|
||||||
|
if (it == value) return@f
|
||||||
|
onChange(it)
|
||||||
|
haptic.performHapticFeedback(HapticFeedbackType.TextHandleMove)
|
||||||
|
},
|
||||||
|
valueRange = min..max,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
package tachiyomi.presentation.core.components.material
|
||||||
|
|
||||||
|
import androidx.annotation.IntRange
|
||||||
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
|
import androidx.compose.material3.Slider
|
||||||
|
import androidx.compose.material3.SliderColors
|
||||||
|
import androidx.compose.material3.SliderDefaults
|
||||||
|
import androidx.compose.material3.SliderState
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun Slider(
|
||||||
|
value: Int,
|
||||||
|
onValueChange: (Int) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
enabled: Boolean = true,
|
||||||
|
valueRange: ClosedRange<Int> = 0..1,
|
||||||
|
@IntRange(from = 0) steps: Int = with(valueRange) { (endInclusive - start) - 1 },
|
||||||
|
onValueChangeFinished: (() -> Unit)? = null,
|
||||||
|
colors: SliderColors = SliderDefaults.colors(),
|
||||||
|
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||||
|
thumb: @Composable (SliderState) -> Unit = {
|
||||||
|
SliderDefaults.Thumb(
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
colors = colors,
|
||||||
|
enabled = enabled,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
track: @Composable (SliderState) -> Unit = { sliderState ->
|
||||||
|
SliderDefaults.Track(colors = colors, enabled = enabled, sliderState = sliderState)
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Slider(
|
||||||
|
value = value.toFloat(),
|
||||||
|
onValueChange = { onValueChange(it.toInt()) },
|
||||||
|
modifier = modifier,
|
||||||
|
enabled = enabled,
|
||||||
|
valueRange = with(valueRange) { start.toFloat()..endInclusive.toFloat() },
|
||||||
|
steps = steps,
|
||||||
|
onValueChangeFinished = onValueChangeFinished,
|
||||||
|
colors = colors,
|
||||||
|
interactionSource = interactionSource,
|
||||||
|
thumb = thumb,
|
||||||
|
track = track,
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user