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
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
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.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Button
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -14,20 +22,21 @@ 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.unit.sp
import androidx.core.content.edit
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.APP_FILTER_TYPE
import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.AppFilterType
import ru.hepolise.volumekeytrackcontrolmodule.R

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppFilterSetting(
value: SharedPreferencesUtil.AppFilterType,
value: AppFilterType,
sharedPreferences: SharedPreferences,
onValueChange: (SharedPreferencesUtil.AppFilterType) -> Unit,
onValueChange: (AppFilterType) -> Unit,
onNavigateToAppFilter: () -> Unit
) {
Text(text = stringResource(R.string.app_filter), fontSize = 20.sp)
Expand All @@ -51,7 +60,7 @@ fun AppFilterSetting(
ExposedDropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false }) {
SharedPreferencesUtil.AppFilterType.values.forEach { type ->
AppFilterType.values.forEach { type ->
DropdownMenuItem(
text = { Text(stringResource(type.resourceId)) },
onClick = {
Expand All @@ -66,11 +75,27 @@ fun AppFilterSetting(
}
}

if (value == SharedPreferencesUtil.AppFilterType.WhiteList || value == SharedPreferencesUtil.AppFilterType.BlackList) {
Button(
onClick = onNavigateToAppFilter,
Box {
AnimatedVisibility(
visible = value == AppFilterType.WhiteList || value == AppFilterType.BlackList,
enter = fadeIn() + expandVertically(expandFrom = Alignment.Top),
exit = fadeOut() + shrinkVertically(shrinkTowards = Alignment.Top),
modifier = Modifier.fillMaxWidth()
) {
Text(text = stringResource(R.string.manage_apps, stringResource(value.resourceId)))
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Button(
onClick = onNavigateToAppFilter,
) {
Text(
text = stringResource(
R.string.manage_apps,
stringResource(value.resourceId)
)
)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ package ru.hepolise.volumekeytrackcontrol.ui.component
import android.content.SharedPreferences
import android.os.Build
import android.os.Vibrator
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.fillMaxWidth
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Edit
Expand Down Expand Up @@ -107,110 +115,124 @@ fun VibrationEffectSetting(
}
}

if (vibrationType == VibrationType.Manual) {
Slider(
value = vibrationLength.toFloat(),
onValueChange = {
onValueChange(value.copy(vibrationLength = it.toInt()))
},
valueRange = 10f..500f,
onValueChangeFinished = {
sharedPreferences.edit {
putInt(VIBRATION_LENGTH, vibrationLength)
}
},
modifier = Modifier.widthIn(max = 300.dp)
)

var showManualVibrationLengthDialog by remember { mutableStateOf(false) }
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.vibration_length, vibrationLength),
modifier = Modifier.clickable { showManualVibrationLengthDialog = true }
)
IconButton(
onClick = {
showManualVibrationLengthDialog = true
}
Box {
AnimatedVisibility(
visible = vibrationType != VibrationType.Disabled,
enter = fadeIn() + expandVertically(expandFrom = Alignment.Top),
exit = fadeOut() + shrinkVertically(shrinkTowards = Alignment.Top),
modifier = Modifier.fillMaxWidth()
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(R.string.edit)
)
}
}
AnimatedVisibility(
visible = vibrationType == VibrationType.Manual,
enter = fadeIn() + expandVertically(expandFrom = Alignment.Top),
exit = fadeOut() + shrinkVertically(shrinkTowards = Alignment.Top)
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Slider(
value = vibrationLength.toFloat(),
onValueChange = {
onValueChange(value.copy(vibrationLength = it.toInt()))
},
valueRange = 10f..500f,
onValueChangeFinished = {
sharedPreferences.edit {
putInt(VIBRATION_LENGTH, vibrationLength)
}
},
modifier = Modifier.widthIn(max = 300.dp)
)

if (showManualVibrationLengthDialog) {
NumberAlertDialog(
title = stringResource(R.string.vibration_length_dialog_title),
defaultValue = vibrationLength,
minValue = 10,
maxValue = 500,
onDismissRequest = { showManualVibrationLengthDialog = false },
onConfirm = {
onValueChange(value.copy(vibrationLength = it))
sharedPreferences.edit { putInt(VIBRATION_LENGTH, it) }
showManualVibrationLengthDialog = false
}
)
}
var showManualVibrationLengthDialog by remember { mutableStateOf(false) }
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.vibration_length, vibrationLength),
modifier = Modifier.clickable {
showManualVibrationLengthDialog = true
}
)
IconButton(onClick = { showManualVibrationLengthDialog = true }) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(R.string.edit)
)
}
}

Slider(
value = vibrationAmplitude.toFloat(),
onValueChange = {
onValueChange(value.copy(vibrationAmplitude = it.toInt()))
},
valueRange = 1f..255f,
onValueChangeFinished = {
sharedPreferences.edit {
putInt(VIBRATION_AMPLITUDE, vibrationAmplitude)
}
},
modifier = Modifier.widthIn(max = 300.dp)
)
if (showManualVibrationLengthDialog) {
NumberAlertDialog(
title = stringResource(R.string.vibration_length_dialog_title),
defaultValue = vibrationLength,
minValue = 10,
maxValue = 500,
onDismissRequest = { showManualVibrationLengthDialog = false },
onConfirm = {
onValueChange(value.copy(vibrationLength = it))
sharedPreferences.edit { putInt(VIBRATION_LENGTH, it) }
showManualVibrationLengthDialog = false
}
)
}

var showVibrationAmplitudeDialog by remember { mutableStateOf(false) }
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(R.string.vibration_amplitude, vibrationAmplitude),
modifier = Modifier.clickable { showVibrationAmplitudeDialog = true }
)
IconButton(
onClick = {
showVibrationAmplitudeDialog = true
}
) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(R.string.edit)
)
}
}
Slider(
value = vibrationAmplitude.toFloat(),
onValueChange = {
onValueChange(value.copy(vibrationAmplitude = it.toInt()))
},
valueRange = 1f..255f,
onValueChangeFinished = {
sharedPreferences.edit {
putInt(VIBRATION_AMPLITUDE, vibrationAmplitude)
}
},
modifier = Modifier.widthIn(max = 300.dp)
)

var showVibrationAmplitudeDialog by remember { mutableStateOf(false) }
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = stringResource(
R.string.vibration_amplitude,
vibrationAmplitude
),
modifier = Modifier.clickable {
showVibrationAmplitudeDialog = true
}
)
IconButton(onClick = { showVibrationAmplitudeDialog = true }) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(R.string.edit)
)
}
}

if (showVibrationAmplitudeDialog) {
NumberAlertDialog(
title = stringResource(R.string.vibration_amplitude_dialog_title),
defaultValue = vibrationAmplitude,
minValue = 1,
maxValue = 255,
onDismissRequest = { showVibrationAmplitudeDialog = false },
onConfirm = {
onValueChange(value.copy(vibrationAmplitude = it))
sharedPreferences.edit {
putInt(VIBRATION_AMPLITUDE, it)
if (showVibrationAmplitudeDialog) {
NumberAlertDialog(
title = stringResource(R.string.vibration_amplitude_dialog_title),
defaultValue = vibrationAmplitude,
minValue = 1,
maxValue = 255,
onDismissRequest = { showVibrationAmplitudeDialog = false },
onConfirm = {
onValueChange(value.copy(vibrationAmplitude = it))
sharedPreferences.edit {
putInt(VIBRATION_AMPLITUDE, it)
}
showVibrationAmplitudeDialog = false
}
)
}
}
showVibrationAmplitudeDialog = false
}
)
}

}

if (vibrationType != VibrationType.Disabled) {
Button(onClick = {
vibrator?.triggerVibration(sharedPreferences)
}) {
Text(stringResource(R.string.test_vibration))
Button(onClick = { vibrator?.triggerVibration(sharedPreferences) }) {
Text(stringResource(R.string.test_vibration))
}
}
}
}

}