Refactor grid size slider composable for reuse
(cherry picked from commit b354e37cc34e1b713a0d19818fd030294985f109) # Conflicts: # app/src/main/java/eu/kanade/presentation/library/LibrarySettingsDialog.kt
This commit is contained in:
parent
f3d47eaaa3
commit
832e765a22
@ -1,27 +1,19 @@
|
|||||||
package eu.kanade.presentation.library
|
package eu.kanade.presentation.library
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.ColumnScope
|
import androidx.compose.foundation.layout.ColumnScope
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Slider
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
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.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.util.fastForEach
|
import androidx.compose.ui.util.fastForEach
|
||||||
import eu.kanade.presentation.components.TabbedDialog
|
import eu.kanade.presentation.components.TabbedDialog
|
||||||
import eu.kanade.presentation.components.TabbedDialogPaddings
|
import eu.kanade.presentation.components.TabbedDialogPaddings
|
||||||
@ -41,7 +33,7 @@ import tachiyomi.presentation.core.components.CheckboxItem
|
|||||||
import tachiyomi.presentation.core.components.HeadingItem
|
import tachiyomi.presentation.core.components.HeadingItem
|
||||||
import tachiyomi.presentation.core.components.IconItem
|
import tachiyomi.presentation.core.components.IconItem
|
||||||
import tachiyomi.presentation.core.components.RadioItem
|
import tachiyomi.presentation.core.components.RadioItem
|
||||||
import tachiyomi.presentation.core.components.SettingsItemsPaddings
|
import tachiyomi.presentation.core.components.SliderItem
|
||||||
import tachiyomi.presentation.core.components.SortItem
|
import tachiyomi.presentation.core.components.SortItem
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -225,10 +217,6 @@ private fun ColumnScope.SortPage(
|
|||||||
private fun ColumnScope.DisplayPage(
|
private fun ColumnScope.DisplayPage(
|
||||||
screenModel: LibrarySettingsScreenModel,
|
screenModel: LibrarySettingsScreenModel,
|
||||||
) {
|
) {
|
||||||
// SY -->
|
|
||||||
val globalDisplayMode by screenModel.libraryPreferences.libraryDisplayMode().collectAsState()
|
|
||||||
// SY <--
|
|
||||||
|
|
||||||
HeadingItem(R.string.action_display_mode)
|
HeadingItem(R.string.action_display_mode)
|
||||||
val displayMode by screenModel.libraryPreferences.libraryDisplayMode().collectAsState()
|
val displayMode by screenModel.libraryPreferences.libraryDisplayMode().collectAsState()
|
||||||
listOf(
|
listOf(
|
||||||
@ -245,48 +233,28 @@ private fun ColumnScope.DisplayPage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (displayMode != LibraryDisplayMode.List) {
|
if (displayMode != LibraryDisplayMode.List) {
|
||||||
Row(
|
val configuration = LocalConfiguration.current
|
||||||
modifier = Modifier
|
val columnPreference = remember {
|
||||||
.fillMaxWidth()
|
if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
.padding(
|
screenModel.libraryPreferences.landscapeColumns()
|
||||||
horizontal = SettingsItemsPaddings.Horizontal,
|
} else {
|
||||||
vertical = SettingsItemsPaddings.Vertical,
|
screenModel.libraryPreferences.portraitColumns()
|
||||||
),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(24.dp),
|
|
||||||
) {
|
|
||||||
val configuration = LocalConfiguration.current
|
|
||||||
val columnPreference = remember {
|
|
||||||
if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
||||||
screenModel.libraryPreferences.landscapeColumns()
|
|
||||||
} else {
|
|
||||||
screenModel.libraryPreferences.portraitColumns()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val columns by columnPreference.collectAsState()
|
|
||||||
Column(modifier = Modifier.weight(0.5f)) {
|
|
||||||
Text(
|
|
||||||
stringResource(id = R.string.pref_library_columns),
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
if (columns > 0) {
|
|
||||||
stringResource(id = R.string.pref_library_columns_per_row, columns)
|
|
||||||
} else {
|
|
||||||
stringResource(id = R.string.label_default)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Slider(
|
|
||||||
value = columns.toFloat(),
|
|
||||||
onValueChange = { columnPreference.set(it.toInt()) },
|
|
||||||
modifier = Modifier.weight(1.5f),
|
|
||||||
valueRange = 0f..10f,
|
|
||||||
steps = 10,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val columns by columnPreference.collectAsState()
|
||||||
|
SliderItem(
|
||||||
|
label = stringResource(R.string.pref_library_columns),
|
||||||
|
min = 0,
|
||||||
|
max = 10,
|
||||||
|
value = columns,
|
||||||
|
valueText = if (columns > 0) {
|
||||||
|
stringResource(R.string.pref_library_columns_per_row, columns)
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.label_default)
|
||||||
|
},
|
||||||
|
onChange = { columnPreference.set(it) },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
HeadingItem(R.string.overlay_header)
|
HeadingItem(R.string.overlay_header)
|
||||||
|
@ -3,6 +3,7 @@ package tachiyomi.presentation.core.components
|
|||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.RowScope
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
@ -17,6 +18,7 @@ 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.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@ -136,6 +138,43 @@ fun RadioItem(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SliderItem(
|
||||||
|
label: String,
|
||||||
|
min: Int,
|
||||||
|
max: Int,
|
||||||
|
value: Int,
|
||||||
|
valueText: String,
|
||||||
|
onChange: (Int) -> Unit,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(
|
||||||
|
horizontal = SettingsItemsPaddings.Horizontal,
|
||||||
|
vertical = SettingsItemsPaddings.Vertical,
|
||||||
|
),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(24.dp),
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.weight(0.5f)) {
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
)
|
||||||
|
Text(valueText)
|
||||||
|
}
|
||||||
|
|
||||||
|
Slider(
|
||||||
|
value = value.toFloat(),
|
||||||
|
onValueChange = { onChange(it.toInt()) },
|
||||||
|
modifier = Modifier.weight(1.5f),
|
||||||
|
valueRange = min.toFloat()..max.toFloat(),
|
||||||
|
steps = max - min,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun BaseSettingsItem(
|
private fun BaseSettingsItem(
|
||||||
label: String,
|
label: String,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user