Skip to content

Commit 918e6ed

Browse files
committed
refactor settings sliders and buttons
1 parent aecf60c commit 918e6ed

File tree

11 files changed

+145
-144
lines changed

11 files changed

+145
-144
lines changed

app/src/main/java/com/uravgcode/chooser/settings/presentation/SettingsScreen.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
3232
import androidx.compose.ui.unit.dp
3333
import androidx.datastore.core.DataStore
3434
import com.uravgcode.chooser.settings.data.SettingsData
35-
import com.uravgcode.chooser.settings.presentation.button.SettingsButtonExport
36-
import com.uravgcode.chooser.settings.presentation.button.SettingsButtonImport
37-
import com.uravgcode.chooser.settings.presentation.button.SettingsButtonReset
35+
import com.uravgcode.chooser.settings.presentation.button.ExportButton
36+
import com.uravgcode.chooser.settings.presentation.button.ImportButton
37+
import com.uravgcode.chooser.settings.presentation.button.ResetButton
3838
import com.uravgcode.chooser.settings.presentation.component.SettingsSeparator
39+
import com.uravgcode.chooser.settings.presentation.component.SettingsSwitch
3940
import com.uravgcode.chooser.settings.presentation.component.SettingsTopAppBar
40-
import com.uravgcode.chooser.settings.presentation.row.SettingsRowPaddingSlider
41-
import com.uravgcode.chooser.settings.presentation.row.SettingsRowPercentSlider
42-
import com.uravgcode.chooser.settings.presentation.row.SettingsRowSwitch
43-
import com.uravgcode.chooser.settings.presentation.row.SettingsRowTimeSlider
41+
import com.uravgcode.chooser.settings.presentation.slider.PaddingSlider
42+
import com.uravgcode.chooser.settings.presentation.slider.PercentSlider
43+
import com.uravgcode.chooser.settings.presentation.slider.TimeSlider
4444
import kotlinx.coroutines.launch
4545

4646
@Composable
@@ -76,7 +76,7 @@ fun SettingsScreen(
7676
heading = "General Settings",
7777
showDivider = false,
7878
)
79-
SettingsRowSwitch(
79+
SettingsSwitch(
8080
title = "Enable Sound",
8181
isChecked = settings.soundEnabled,
8282
onCheckedChange = { isChecked ->
@@ -85,7 +85,7 @@ fun SettingsScreen(
8585
}
8686
}
8787
)
88-
SettingsRowSwitch(
88+
SettingsSwitch(
8989
title = "Enable Vibration",
9090
isChecked = settings.vibrationEnabled,
9191
onCheckedChange = { isChecked ->
@@ -98,7 +98,7 @@ fun SettingsScreen(
9898

9999
item {
100100
SettingsSeparator("Display Settings")
101-
SettingsRowSwitch(
101+
SettingsSwitch(
102102
title = "Full Screen Mode",
103103
isChecked = settings.fullScreen,
104104
onCheckedChange = { isChecked ->
@@ -107,7 +107,7 @@ fun SettingsScreen(
107107
}
108108
}
109109
)
110-
SettingsRowPaddingSlider(
110+
PaddingSlider(
111111
title = "Additional Button Padding",
112112
value = settings.additionalButtonPadding,
113113
onValueChange = { sliderValue ->
@@ -118,7 +118,7 @@ fun SettingsScreen(
118118
valueRange = 0f..50f,
119119
steps = 9
120120
)
121-
SettingsRowPercentSlider(
121+
PercentSlider(
122122
title = "Circle Size",
123123
value = settings.circleSizeFactor,
124124
onValueChange = { sliderValue ->
@@ -133,7 +133,7 @@ fun SettingsScreen(
133133

134134
item {
135135
SettingsSeparator("Circle Lifetimes")
136-
SettingsRowTimeSlider(
136+
TimeSlider(
137137
title = "Circle Lifetime",
138138
value = settings.circleLifetime,
139139
onValueChange = { sliderValue ->
@@ -144,7 +144,7 @@ fun SettingsScreen(
144144
valueRange = 0L..3000L,
145145
steps = 5,
146146
)
147-
SettingsRowTimeSlider(
147+
TimeSlider(
148148
title = "Group Circle Lifetime",
149149
value = settings.groupCircleLifetime,
150150
onValueChange = { sliderValue ->
@@ -155,7 +155,7 @@ fun SettingsScreen(
155155
valueRange = 0L..3000L,
156156
steps = 5,
157157
)
158-
SettingsRowTimeSlider(
158+
TimeSlider(
159159
title = "Order Circle Lifetime",
160160
value = settings.orderCircleLifetime,
161161
onValueChange = { sliderValue ->
@@ -170,9 +170,9 @@ fun SettingsScreen(
170170

171171
item {
172172
SettingsSeparator()
173-
SettingsButtonImport(dataStore)
174-
SettingsButtonExport(dataStore)
175-
SettingsButtonReset(dataStore)
173+
ImportButton(dataStore)
174+
ExportButton(dataStore)
175+
ResetButton(dataStore)
176176
}
177177
}
178178
}

app/src/main/java/com/uravgcode/chooser/settings/presentation/button/SettingsButtonExport.kt renamed to app/src/main/java/com/uravgcode/chooser/settings/presentation/button/ExportButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1111
*
1212
* @author UrAvgCode
13-
* @description SettingsButtonExport provides functionality to export settings to a file.
13+
* @description ExportButton provides functionality to export settings to a file.
1414
*/
1515

1616
package com.uravgcode.chooser.settings.presentation.button
@@ -28,7 +28,7 @@ import kotlinx.coroutines.flow.first
2828
import kotlinx.coroutines.launch
2929

3030
@Composable
31-
fun SettingsButtonExport(dataStore: DataStore<SettingsData>) {
31+
fun ExportButton(dataStore: DataStore<SettingsData>) {
3232
val scope = rememberCoroutineScope()
3333
val context = LocalContext.current
3434

app/src/main/java/com/uravgcode/chooser/settings/presentation/button/SettingsButtonImport.kt renamed to app/src/main/java/com/uravgcode/chooser/settings/presentation/button/ImportButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1111
*
1212
* @author UrAvgCode
13-
* @description SettingsButtonImport provides functionality to import settings from a previously exported file.
13+
* @description ImportButton provides functionality to import settings from a previously exported file.
1414
*/
1515

1616
package com.uravgcode.chooser.settings.presentation.button
@@ -27,7 +27,7 @@ import com.uravgcode.chooser.settings.data.SettingsSerializer
2727
import kotlinx.coroutines.launch
2828

2929
@Composable
30-
fun SettingsButtonImport(dataStore: DataStore<SettingsData>) {
30+
fun ImportButton(dataStore: DataStore<SettingsData>) {
3131
val scope = rememberCoroutineScope()
3232
val context = LocalContext.current
3333

app/src/main/java/com/uravgcode/chooser/settings/presentation/button/SettingsButtonReset.kt renamed to app/src/main/java/com/uravgcode/chooser/settings/presentation/button/ResetButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1111
*
1212
* @author UrAvgCode
13-
* @description SettingsButtonReset allows users to restore all settings to their default values.
13+
* @description ResetButton allows users to restore all settings to their default values.
1414
*/
1515

1616
package com.uravgcode.chooser.settings.presentation.button
@@ -29,7 +29,7 @@ import com.uravgcode.chooser.settings.data.SettingsData
2929
import kotlinx.coroutines.launch
3030

3131
@Composable
32-
fun SettingsButtonReset(dataStore: DataStore<SettingsData>) {
32+
fun ResetButton(dataStore: DataStore<SettingsData>) {
3333
val coroutineScope = rememberCoroutineScope()
3434
var showResetDialog by remember { mutableStateOf(false) }
3535

app/src/main/java/com/uravgcode/chooser/settings/presentation/row/SettingsRowSwitch.kt renamed to app/src/main/java/com/uravgcode/chooser/settings/presentation/component/SettingsSwitch.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1111
*
1212
* @author UrAvgCode
13-
* @description SettingsRowSwitch is a component that provides a toggle switch for settings.
13+
* @description SettingsSwitch is a component that provides a toggle switch for settings.
1414
*/
1515

16-
package com.uravgcode.chooser.settings.presentation.row
16+
package com.uravgcode.chooser.settings.presentation.component
1717

1818
import androidx.compose.foundation.layout.Row
1919
import androidx.compose.foundation.layout.fillMaxWidth
@@ -28,7 +28,7 @@ import androidx.compose.ui.Modifier
2828
import androidx.compose.ui.unit.dp
2929

3030
@Composable
31-
fun SettingsRowSwitch(
31+
fun SettingsSwitch(
3232
title: String,
3333
isChecked: Boolean,
3434
onCheckedChange: (Boolean) -> Unit

app/src/main/java/com/uravgcode/chooser/settings/presentation/row/SettingsRowPercentSlider.kt

Lines changed: 0 additions & 54 deletions
This file was deleted.

app/src/main/java/com/uravgcode/chooser/settings/presentation/row/SettingsRowTimeSlider.kt

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2025 UrAvgCode
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* You should have received a copy of the GNU General Public License
10+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
11+
*
12+
* @author UrAvgCode
13+
* @description PaddingSlider is a component that provides a settings slider for padding values.
14+
*/
15+
16+
package com.uravgcode.chooser.settings.presentation.slider
17+
18+
import androidx.compose.runtime.Composable
19+
import kotlin.math.roundToInt
20+
21+
@Composable
22+
fun PaddingSlider(
23+
title: String,
24+
value: Float,
25+
onValueChange: (Float) -> Unit,
26+
valueRange: ClosedFloatingPointRange<Float> = 0f..50f,
27+
steps: Int = 0
28+
) {
29+
SettingsSlider(
30+
title = title,
31+
value = value,
32+
onValueChange = onValueChange,
33+
valueRange = valueRange,
34+
steps = steps,
35+
valueFormatter = { "${it.roundToInt()} dp" }
36+
)
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2025 UrAvgCode
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* You should have received a copy of the GNU General Public License
10+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
11+
*
12+
* @author UrAvgCode
13+
* @description PercentSlider is a component that provides a settings slider for percent values.
14+
*/
15+
16+
package com.uravgcode.chooser.settings.presentation.slider
17+
18+
import androidx.compose.runtime.Composable
19+
import kotlin.math.roundToInt
20+
21+
@Composable
22+
fun PercentSlider(
23+
title: String,
24+
value: Float,
25+
onValueChange: (Float) -> Unit,
26+
valueRange: ClosedFloatingPointRange<Float> = 0f..1f,
27+
steps: Int = 0
28+
) {
29+
SettingsSlider(
30+
title = title,
31+
value = value,
32+
onValueChange = onValueChange,
33+
valueRange = valueRange,
34+
steps = steps,
35+
valueFormatter = { "${(it * 100).roundToInt()}%" }
36+
)
37+
}

0 commit comments

Comments
 (0)