11package ru.hepolise.volumekeytrackcontrol.ui.component
22
33import android.content.SharedPreferences
4- import androidx.compose.animation.AnimatedVisibility
5- import androidx.compose.animation.expandVertically
6- import androidx.compose.animation.fadeIn
7- import androidx.compose.animation.fadeOut
8- import androidx.compose.animation.shrinkVertically
94import androidx.compose.foundation.clickable
10- import androidx.compose.foundation.layout.Box
11- import androidx.compose.foundation.layout.Column
125import androidx.compose.foundation.layout.Row
13- import androidx.compose.foundation.layout.defaultMinSize
14- import androidx.compose.foundation.layout.fillMaxWidth
156import androidx.compose.material.icons.Icons
167import androidx.compose.material.icons.filled.Edit
178import androidx.compose.material3.Icon
189import androidx.compose.material3.IconButton
19- import androidx.compose.material3.SegmentedButton
20- import androidx.compose.material3.SegmentedButtonDefaults
21- import androidx.compose.material3.SingleChoiceSegmentedButtonRow
2210import androidx.compose.material3.Text
2311import androidx.compose.runtime.Composable
2412import androidx.compose.runtime.getValue
@@ -28,37 +16,21 @@ import androidx.compose.runtime.setValue
2816import androidx.compose.ui.Alignment
2917import androidx.compose.ui.Modifier
3018import androidx.compose.ui.res.stringResource
31- import androidx.compose.ui.text.style.TextOverflow
32- import androidx.compose.ui.unit.dp
3319import androidx.core.content.edit
34- import ru.hepolise.volumekeytrackcontrol.util.RewindActionType
3520import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.LONG_PRESS_DURATION
36- import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.REWIND_ACTION_TYPE
37- import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.REWIND_DURATION
3821import ru.hepolise.volumekeytrackcontrolmodule.R
3922
40- data class LongPressSettingData (
41- val longPressDuration : Int ,
42- val rewindActionType : RewindActionType ,
43- val rewindDuration : Int
44- )
45-
4623@Composable
4724fun LongPressSetting (
48- data : LongPressSettingData ,
25+ longPressDuration : Int ,
4926 sharedPreferences : SharedPreferences ,
50- onValueChange : (LongPressSettingData ) -> Unit
27+ onValueChange : (Int ) -> Unit
5128) {
52- val longPressDuration = data.longPressDuration
53- val rewindActionType = data.rewindActionType
54- val rewindDuration = data.rewindDuration
55-
5629 var showLongPressTimeoutDialog by remember { mutableStateOf(false ) }
57- var showRewindDurationDialog by remember { mutableStateOf(false ) }
5830
5931 PrefsSlider (
6032 value = longPressDuration,
61- onValueChange = { onValueChange(data.copy(longPressDuration = it) ) },
33+ onValueChange = { onValueChange(it ) },
6234 valueRange = 100f .. 1000f ,
6335 prefKey = LONG_PRESS_DURATION ,
6436 sharedPreferences = sharedPreferences
@@ -81,85 +53,6 @@ fun LongPressSetting(
8153 }
8254 }
8355
84- Row (verticalAlignment = Alignment .CenterVertically ) {
85- Text (
86- text = stringResource(R .string.long_press_action),
87- )
88- }
89-
90- Row (verticalAlignment = Alignment .CenterVertically ) {
91- SingleChoiceSegmentedButtonRow {
92- RewindActionType .entries.forEachIndexed { index, actionType ->
93- SegmentedButton (
94- selected = rewindActionType == actionType,
95- onClick = {
96- onValueChange(data.copy(rewindActionType = actionType))
97- sharedPreferences.edit {
98- putString(REWIND_ACTION_TYPE , actionType.name)
99- }
100- },
101- shape = SegmentedButtonDefaults .itemShape(
102- index = index,
103- count = RewindActionType .entries.size
104- ),
105- modifier = Modifier
106- .defaultMinSize(minWidth = 140 .dp)
107- .weight(1f )
108- ) {
109- Text (
110- text = when (actionType) {
111- RewindActionType .TRACK_CHANGE -> stringResource(R .string.track_change)
112- RewindActionType .REWIND -> stringResource(R .string.rewind)
113- },
114- maxLines = 1 ,
115- overflow = TextOverflow .Visible ,
116- softWrap = false
117- )
118- }
119- }
120- }
121- }
122-
123- Box {
124- AnimatedVisibility (
125- visible = rewindActionType == RewindActionType .REWIND ,
126- enter = fadeIn() + expandVertically(expandFrom = Alignment .Top ),
127- exit = fadeOut() + shrinkVertically(shrinkTowards = Alignment .Top ),
128- modifier = Modifier .fillMaxWidth()
129- ) {
130- Column (
131- horizontalAlignment = Alignment .CenterHorizontally ,
132- ) {
133- PrefsSlider (
134- value = rewindDuration,
135- onValueChange = {
136- onValueChange(data.copy(rewindDuration = it))
137- },
138- valueRange = 1f .. 60f ,
139- prefKey = REWIND_DURATION ,
140- sharedPreferences = sharedPreferences
141- )
142-
143- Row (verticalAlignment = Alignment .CenterVertically ) {
144- Text (
145- text = stringResource(R .string.rewind_duration, rewindDuration),
146- modifier = Modifier .clickable { showRewindDurationDialog = true }
147- )
148- IconButton (
149- onClick = {
150- showRewindDurationDialog = true
151- }
152- ) {
153- Icon (
154- imageVector = Icons .Default .Edit ,
155- contentDescription = stringResource(R .string.edit_rewind_duration)
156- )
157- }
158- }
159- }
160- }
161- }
162-
16356 if (showLongPressTimeoutDialog) {
16457 NumberAlertDialog (
16558 title = stringResource(R .string.long_press_duration_dialog_title),
@@ -168,25 +61,10 @@ fun LongPressSetting(
16861 maxValue = 1000 ,
16962 onDismissRequest = { showLongPressTimeoutDialog = false },
17063 onConfirm = {
171- onValueChange(data.copy(longPressDuration = it) )
64+ onValueChange(it )
17265 sharedPreferences.edit { putInt(LONG_PRESS_DURATION , it) }
17366 showLongPressTimeoutDialog = false
17467 }
17568 )
17669 }
177-
178- if (showRewindDurationDialog) {
179- NumberAlertDialog (
180- title = stringResource(R .string.rewind_duration_dialog_title),
181- defaultValue = rewindDuration,
182- minValue = 1 ,
183- maxValue = 60 ,
184- onDismissRequest = { showRewindDurationDialog = false },
185- onConfirm = {
186- onValueChange(data.copy(rewindDuration = it))
187- sharedPreferences.edit { putInt(REWIND_DURATION , it) }
188- showRewindDurationDialog = false
189- }
190- )
191- }
19270}
0 commit comments