Skip to content

Commit 31824fe

Browse files
authored
Merge pull request #207 from Hepolise/dev
feat: split long press settings into separate components and update UI
2 parents c0881b3 + c0e8dae commit 31824fe

7 files changed

Lines changed: 190 additions & 147 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies {
5454
implementation("androidx.compose.ui:ui-tooling-preview")
5555
implementation("androidx.compose.material3:material3:1.4.0")
5656
implementation("androidx.compose.material:material-icons-core:1.7.8")
57+
implementation("androidx.compose.material:material-icons-extended:1.7.8")
5758
implementation("androidx.core:core-splashscreen:1.2.0")
5859

5960
// Compose navigation

app/src/main/java/ru/hepolise/volumekeytrackcontrol/repository/BootRepository.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ru.hepolise.volumekeytrackcontrol.util.LSPosedLogger
1212
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.LAST_BOOT_COMPLETED_TIME
1313
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.getStatusSharedPreferences
1414
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.isBootCompleted
15+
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.isHooked
1516
import ru.hepolise.volumekeytrackcontrol.util.StatusSysPropsHelper
1617

1718
class BootRepository private constructor(private val sharedPreferences: SharedPreferences) {
@@ -31,6 +32,10 @@ class BootRepository private constructor(private val sharedPreferences: SharedPr
3132
return sharedPreferences.isBootCompleted()
3233
}
3334

35+
fun isHooked(): Boolean {
36+
return StatusSysPropsHelper.isHooked || sharedPreferences.isHooked()
37+
}
38+
3439
fun setBootCompleted() {
3540
sharedPreferences.edit {
3641
putLong(LAST_BOOT_COMPLETED_TIME, System.currentTimeMillis())
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package ru.hepolise.volumekeytrackcontrol.ui.component
2+
3+
import 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
9+
import androidx.compose.foundation.clickable
10+
import androidx.compose.foundation.layout.Box
11+
import androidx.compose.foundation.layout.Column
12+
import androidx.compose.foundation.layout.Row
13+
import androidx.compose.foundation.layout.defaultMinSize
14+
import androidx.compose.foundation.layout.fillMaxWidth
15+
import androidx.compose.material.icons.Icons
16+
import androidx.compose.material.icons.filled.Edit
17+
import androidx.compose.material3.Icon
18+
import androidx.compose.material3.IconButton
19+
import androidx.compose.material3.SegmentedButton
20+
import androidx.compose.material3.SegmentedButtonDefaults
21+
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
22+
import androidx.compose.material3.Text
23+
import androidx.compose.runtime.Composable
24+
import androidx.compose.runtime.getValue
25+
import androidx.compose.runtime.mutableStateOf
26+
import androidx.compose.runtime.remember
27+
import androidx.compose.runtime.setValue
28+
import androidx.compose.ui.Alignment
29+
import androidx.compose.ui.Modifier
30+
import androidx.compose.ui.res.stringResource
31+
import androidx.compose.ui.text.style.TextOverflow
32+
import androidx.compose.ui.unit.dp
33+
import androidx.core.content.edit
34+
import ru.hepolise.volumekeytrackcontrol.util.RewindActionType
35+
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.REWIND_ACTION_TYPE
36+
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.REWIND_DURATION
37+
import ru.hepolise.volumekeytrackcontrolmodule.R
38+
39+
data class RewindSettingData(
40+
val rewindActionType: RewindActionType,
41+
val rewindDuration: Int
42+
)
43+
44+
@Composable
45+
fun LongPressActionSetting(
46+
data: RewindSettingData,
47+
sharedPreferences: SharedPreferences,
48+
onValueChange: (RewindSettingData) -> Unit
49+
) {
50+
val rewindActionType = data.rewindActionType
51+
val rewindDuration = data.rewindDuration
52+
53+
var showRewindDurationDialog by remember { mutableStateOf(false) }
54+
55+
Row(verticalAlignment = Alignment.CenterVertically) {
56+
SingleChoiceSegmentedButtonRow {
57+
RewindActionType.entries.forEachIndexed { index, actionType ->
58+
SegmentedButton(
59+
selected = rewindActionType == actionType,
60+
onClick = {
61+
onValueChange(data.copy(rewindActionType = actionType))
62+
sharedPreferences.edit {
63+
putString(REWIND_ACTION_TYPE, actionType.name)
64+
}
65+
},
66+
shape = SegmentedButtonDefaults.itemShape(
67+
index = index,
68+
count = RewindActionType.entries.size
69+
),
70+
modifier = Modifier
71+
.defaultMinSize(minWidth = 140.dp)
72+
.weight(1f)
73+
) {
74+
Text(
75+
text = when (actionType) {
76+
RewindActionType.TRACK_CHANGE -> stringResource(R.string.track_change)
77+
RewindActionType.REWIND -> stringResource(R.string.rewind)
78+
},
79+
maxLines = 1,
80+
overflow = TextOverflow.Visible,
81+
softWrap = false
82+
)
83+
}
84+
}
85+
}
86+
}
87+
88+
Box {
89+
AnimatedVisibility(
90+
visible = rewindActionType == RewindActionType.REWIND,
91+
enter = fadeIn() + expandVertically(expandFrom = Alignment.Top),
92+
exit = fadeOut() + shrinkVertically(shrinkTowards = Alignment.Top),
93+
modifier = Modifier.fillMaxWidth()
94+
) {
95+
Column(
96+
horizontalAlignment = Alignment.CenterHorizontally,
97+
) {
98+
PrefsSlider(
99+
value = rewindDuration,
100+
onValueChange = {
101+
onValueChange(data.copy(rewindDuration = it))
102+
},
103+
valueRange = 1f..60f,
104+
prefKey = REWIND_DURATION,
105+
sharedPreferences = sharedPreferences
106+
)
107+
108+
Row(verticalAlignment = Alignment.CenterVertically) {
109+
Text(
110+
text = stringResource(R.string.rewind_duration, rewindDuration),
111+
modifier = Modifier.clickable { showRewindDurationDialog = true }
112+
)
113+
IconButton(
114+
onClick = {
115+
showRewindDurationDialog = true
116+
}
117+
) {
118+
Icon(
119+
imageVector = Icons.Default.Edit,
120+
contentDescription = stringResource(R.string.edit_rewind_duration)
121+
)
122+
}
123+
}
124+
}
125+
}
126+
}
127+
128+
if (showRewindDurationDialog) {
129+
NumberAlertDialog(
130+
title = stringResource(R.string.rewind_duration_dialog_title),
131+
defaultValue = rewindDuration,
132+
minValue = 1,
133+
maxValue = 60,
134+
onDismissRequest = { showRewindDurationDialog = false },
135+
onConfirm = {
136+
onValueChange(data.copy(rewindDuration = it))
137+
sharedPreferences.edit { putInt(REWIND_DURATION, it) }
138+
showRewindDurationDialog = false
139+
}
140+
)
141+
}
142+
}
Lines changed: 4 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
package ru.hepolise.volumekeytrackcontrol.ui.component
22

33
import 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
94
import androidx.compose.foundation.clickable
10-
import androidx.compose.foundation.layout.Box
11-
import androidx.compose.foundation.layout.Column
125
import androidx.compose.foundation.layout.Row
13-
import androidx.compose.foundation.layout.defaultMinSize
14-
import androidx.compose.foundation.layout.fillMaxWidth
156
import androidx.compose.material.icons.Icons
167
import androidx.compose.material.icons.filled.Edit
178
import androidx.compose.material3.Icon
189
import androidx.compose.material3.IconButton
19-
import androidx.compose.material3.SegmentedButton
20-
import androidx.compose.material3.SegmentedButtonDefaults
21-
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
2210
import androidx.compose.material3.Text
2311
import androidx.compose.runtime.Composable
2412
import androidx.compose.runtime.getValue
@@ -28,37 +16,21 @@ import androidx.compose.runtime.setValue
2816
import androidx.compose.ui.Alignment
2917
import androidx.compose.ui.Modifier
3018
import androidx.compose.ui.res.stringResource
31-
import androidx.compose.ui.text.style.TextOverflow
32-
import androidx.compose.ui.unit.dp
3319
import androidx.core.content.edit
34-
import ru.hepolise.volumekeytrackcontrol.util.RewindActionType
3520
import 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
3821
import 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
4724
fun 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

Comments
 (0)