Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies {
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3:1.4.0")
implementation("androidx.compose.material:material-icons-core:1.7.8")
implementation("androidx.compose.material:material-icons-extended:1.7.8")
implementation("androidx.core:core-splashscreen:1.2.0")

// Compose navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ru.hepolise.volumekeytrackcontrol.util.LSPosedLogger
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.LAST_BOOT_COMPLETED_TIME
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.getStatusSharedPreferences
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.isBootCompleted
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.isHooked
import ru.hepolise.volumekeytrackcontrol.util.StatusSysPropsHelper

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

fun isHooked(): Boolean {
return StatusSysPropsHelper.isHooked || sharedPreferences.isHooked()
}

fun setBootCompleted() {
sharedPreferences.edit {
putLong(LAST_BOOT_COMPLETED_TIME, System.currentTimeMillis())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package ru.hepolise.volumekeytrackcontrol.ui.component

import android.content.SharedPreferences
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.core.content.edit
import ru.hepolise.volumekeytrackcontrol.util.RewindActionType
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.REWIND_ACTION_TYPE
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.REWIND_DURATION
import ru.hepolise.volumekeytrackcontrolmodule.R

data class RewindSettingData(
val rewindActionType: RewindActionType,
val rewindDuration: Int
)

@Composable
fun LongPressActionSetting(
data: RewindSettingData,
sharedPreferences: SharedPreferences,
onValueChange: (RewindSettingData) -> Unit
) {
val rewindActionType = data.rewindActionType
val rewindDuration = data.rewindDuration

var showRewindDurationDialog by remember { mutableStateOf(false) }

Row(verticalAlignment = Alignment.CenterVertically) {
SingleChoiceSegmentedButtonRow {
RewindActionType.entries.forEachIndexed { index, actionType ->
SegmentedButton(
selected = rewindActionType == actionType,
onClick = {
onValueChange(data.copy(rewindActionType = actionType))
sharedPreferences.edit {
putString(REWIND_ACTION_TYPE, actionType.name)
}
},
shape = SegmentedButtonDefaults.itemShape(
index = index,
count = RewindActionType.entries.size
),
modifier = Modifier
.defaultMinSize(minWidth = 140.dp)
.weight(1f)
) {
Text(
text = when (actionType) {
RewindActionType.TRACK_CHANGE -> stringResource(R.string.track_change)
RewindActionType.REWIND -> stringResource(R.string.rewind)
},
maxLines = 1,
overflow = TextOverflow.Visible,
softWrap = false
)
}
}
}
}

Box {
AnimatedVisibility(
visible = rewindActionType == RewindActionType.REWIND,
enter = fadeIn() + expandVertically(expandFrom = Alignment.Top),
exit = fadeOut() + shrinkVertically(shrinkTowards = Alignment.Top),
modifier = Modifier.fillMaxWidth()
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
PrefsSlider(
value = rewindDuration,
onValueChange = {
onValueChange(data.copy(rewindDuration = it))
},
valueRange = 1f..60f,
prefKey = REWIND_DURATION,
sharedPreferences = sharedPreferences
)

Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.rewind_duration, rewindDuration),
modifier = Modifier.clickable { showRewindDurationDialog = true }
)
IconButton(
onClick = {
showRewindDurationDialog = true
}
) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(R.string.edit_rewind_duration)
)
}
}
}
}
}

if (showRewindDurationDialog) {
NumberAlertDialog(
title = stringResource(R.string.rewind_duration_dialog_title),
defaultValue = rewindDuration,
minValue = 1,
maxValue = 60,
onDismissRequest = { showRewindDurationDialog = false },
onConfirm = {
onValueChange(data.copy(rewindDuration = it))
sharedPreferences.edit { putInt(REWIND_DURATION, it) }
showRewindDurationDialog = false
}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package ru.hepolise.volumekeytrackcontrol.ui.component

import android.content.SharedPreferences
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -28,37 +16,21 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.core.content.edit
import ru.hepolise.volumekeytrackcontrol.util.RewindActionType
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.LONG_PRESS_DURATION
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.REWIND_ACTION_TYPE
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.REWIND_DURATION
import ru.hepolise.volumekeytrackcontrolmodule.R

data class LongPressSettingData(
val longPressDuration: Int,
val rewindActionType: RewindActionType,
val rewindDuration: Int
)

@Composable
fun LongPressSetting(
data: LongPressSettingData,
longPressDuration: Int,
sharedPreferences: SharedPreferences,
onValueChange: (LongPressSettingData) -> Unit
onValueChange: (Int) -> Unit
) {
val longPressDuration = data.longPressDuration
val rewindActionType = data.rewindActionType
val rewindDuration = data.rewindDuration

var showLongPressTimeoutDialog by remember { mutableStateOf(false) }
var showRewindDurationDialog by remember { mutableStateOf(false) }

PrefsSlider(
value = longPressDuration,
onValueChange = { onValueChange(data.copy(longPressDuration = it)) },
onValueChange = { onValueChange(it) },
valueRange = 100f..1000f,
prefKey = LONG_PRESS_DURATION,
sharedPreferences = sharedPreferences
Expand All @@ -81,85 +53,6 @@ fun LongPressSetting(
}
}

Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.long_press_action),
)
}

Row(verticalAlignment = Alignment.CenterVertically) {
SingleChoiceSegmentedButtonRow {
RewindActionType.entries.forEachIndexed { index, actionType ->
SegmentedButton(
selected = rewindActionType == actionType,
onClick = {
onValueChange(data.copy(rewindActionType = actionType))
sharedPreferences.edit {
putString(REWIND_ACTION_TYPE, actionType.name)
}
},
shape = SegmentedButtonDefaults.itemShape(
index = index,
count = RewindActionType.entries.size
),
modifier = Modifier
.defaultMinSize(minWidth = 140.dp)
.weight(1f)
) {
Text(
text = when (actionType) {
RewindActionType.TRACK_CHANGE -> stringResource(R.string.track_change)
RewindActionType.REWIND -> stringResource(R.string.rewind)
},
maxLines = 1,
overflow = TextOverflow.Visible,
softWrap = false
)
}
}
}
}

Box {
AnimatedVisibility(
visible = rewindActionType == RewindActionType.REWIND,
enter = fadeIn() + expandVertically(expandFrom = Alignment.Top),
exit = fadeOut() + shrinkVertically(shrinkTowards = Alignment.Top),
modifier = Modifier.fillMaxWidth()
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
PrefsSlider(
value = rewindDuration,
onValueChange = {
onValueChange(data.copy(rewindDuration = it))
},
valueRange = 1f..60f,
prefKey = REWIND_DURATION,
sharedPreferences = sharedPreferences
)

Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.rewind_duration, rewindDuration),
modifier = Modifier.clickable { showRewindDurationDialog = true }
)
IconButton(
onClick = {
showRewindDurationDialog = true
}
) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(R.string.edit_rewind_duration)
)
}
}
}
}
}

if (showLongPressTimeoutDialog) {
NumberAlertDialog(
title = stringResource(R.string.long_press_duration_dialog_title),
Expand All @@ -168,25 +61,10 @@ fun LongPressSetting(
maxValue = 1000,
onDismissRequest = { showLongPressTimeoutDialog = false },
onConfirm = {
onValueChange(data.copy(longPressDuration = it))
onValueChange(it)
sharedPreferences.edit { putInt(LONG_PRESS_DURATION, it) }
showLongPressTimeoutDialog = false
}
)
}

if (showRewindDurationDialog) {
NumberAlertDialog(
title = stringResource(R.string.rewind_duration_dialog_title),
defaultValue = rewindDuration,
minValue = 1,
maxValue = 60,
onDismissRequest = { showRewindDurationDialog = false },
onConfirm = {
onValueChange(data.copy(rewindDuration = it))
sharedPreferences.edit { putInt(REWIND_DURATION, it) }
showRewindDurationDialog = false
}
)
}
}
Loading