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
Expand Up @@ -231,7 +231,7 @@ object VolumeKeyControlModuleHandlers {
val handler = instance.getHandler()
handler.postDelayed(
getRunnable(instance, VOLUME_BOTH_LONG_PRESS),
SharedPreferencesUtil.prefs().getLongPressDuration()
SharedPreferencesUtil.prefs().getLongPressDuration().toLong()
)
}

Expand All @@ -243,7 +243,7 @@ object VolumeKeyControlModuleHandlers {
KeyEvent.KEYCODE_VOLUME_DOWN -> getRunnable(instance, VOLUME_DOWN_LONG_PRESS)
else -> return
},
SharedPreferencesUtil.prefs().getLongPressDuration()
SharedPreferencesUtil.prefs().getLongPressDuration().toLong()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -137,9 +136,9 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) {
exitProcess(0)
}

var longPressDuration by remember { mutableLongStateOf(sharedPreferences.getLongPressDuration()) }
var longPressDuration by remember { mutableIntStateOf(sharedPreferences.getLongPressDuration()) }
var selectedEffect by remember { mutableIntStateOf(sharedPreferences.getSelectedEffect()) }
var vibrationLength by remember { mutableLongStateOf(sharedPreferences.getVibrationLength()) }
var vibrationLength by remember { mutableIntStateOf(sharedPreferences.getVibrationLength()) }
var vibrationAmplitude by remember { mutableIntStateOf(sharedPreferences.getVibrationAmplitude()) }

Scaffold(
Expand Down Expand Up @@ -167,11 +166,11 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) {
Slider(
value = longPressDuration.toFloat(),
onValueChange = {
longPressDuration = it.toLong()
longPressDuration = it.toInt()
},
valueRange = 100f..1000f,
onValueChangeFinished = {
sharedPreferences.edit().putLong(LONG_PRESS_DURATION, longPressDuration)
sharedPreferences.edit().putInt(LONG_PRESS_DURATION, longPressDuration)
.apply()
},
modifier = Modifier.widthIn(max = 300.dp)
Expand Down Expand Up @@ -201,7 +200,7 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) {
onDismissRequest = { showLongPressTimeoutDialog = false },
onConfirm = {
longPressDuration = it
sharedPreferences.edit().putLong(LONG_PRESS_DURATION, it).apply()
sharedPreferences.edit().putInt(LONG_PRESS_DURATION, it).apply()
showLongPressTimeoutDialog = false
}
)
Expand Down Expand Up @@ -247,11 +246,11 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) {
Slider(
value = vibrationLength.toFloat(),
onValueChange = {
vibrationLength = it.toLong()
vibrationLength = it.toInt()
},
valueRange = 10f..500f,
onValueChangeFinished = {
sharedPreferences.edit().putLong(VIBRATION_LENGTH, vibrationLength)
sharedPreferences.edit().putInt(VIBRATION_LENGTH, vibrationLength)
.apply()
},
modifier = Modifier.widthIn(max = 300.dp)
Expand Down Expand Up @@ -281,7 +280,7 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) {
onDismissRequest = { showManualVibrationLengthDialog = false },
onConfirm = {
vibrationLength = it
sharedPreferences.edit().putLong(VIBRATION_LENGTH, it).apply()
sharedPreferences.edit().putInt(VIBRATION_LENGTH, it).apply()
showManualVibrationLengthDialog = false
}
)
Expand Down Expand Up @@ -318,13 +317,13 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) {
if (showVibrationAmplitudeDialog) {
NumberAlertDialog(
title = stringResource(R.string.vibration_amplitude_dialog_title),
defaultValue = vibrationAmplitude.toLong(),
defaultValue = vibrationAmplitude,
minValue = 1,
maxValue = 255,
onDismissRequest = { showVibrationAmplitudeDialog = false },
onConfirm = {
vibrationAmplitude = it.toInt()
sharedPreferences.edit().putInt(VIBRATION_AMPLITUDE, it.toInt())
vibrationAmplitude = it
sharedPreferences.edit().putInt(VIBRATION_AMPLITUDE, it)
.apply()
showVibrationAmplitudeDialog = false
}
Expand Down Expand Up @@ -395,13 +394,13 @@ fun dynamicColorScheme(context: Context): ColorScheme {
@Composable
fun NumberAlertDialog(
title: String,
defaultValue: Long,
defaultValue: Int,
onDismissRequest: () -> Unit,
onConfirm: (Long) -> Unit,
minValue: Long = 0,
maxValue: Long = Long.MAX_VALUE,
validate: (Long) -> Boolean = { it in minValue..maxValue }
onConfirm: (Int) -> Unit,
minValue: Int,
maxValue: Int
) {
fun validate(value: Int) = value in minValue..maxValue
var value by remember { mutableStateOf(defaultValue.toString()) }
val focusRequester = remember { FocusRequester() }
AlertDialog(
Expand All @@ -414,17 +413,17 @@ fun NumberAlertDialog(
onValueChange = { value = it },
label = { Text(stringResource(R.string.value_in_range, minValue, maxValue)) },
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number),
isError = value.toLongOrNull() == null || !validate(value.toLong()),
isError = value.toIntOrNull() == null || !validate(value.toInt()),
modifier = Modifier.focusRequester(focusRequester)
)
}
},
confirmButton = {
TextButton(
onClick = {
onConfirm(value.toLong())
onConfirm(value.toInt())
},
enabled = value.toLongOrNull() != null && validate(value.toLong())
enabled = value.toLongOrNull() != null && validate(value.toInt())
) {
Text(text = stringResource(R.string.ok))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ object SharedPreferencesUtil {
const val LONG_PRESS_DURATION = "longPressDuration"

const val SELECTED_EFFECT_DEFAULT_VALUE = 0
const val VIBRATION_LENGTH_DEFAULT_VALUE = 50L
const val VIBRATION_LENGTH_DEFAULT_VALUE = 50
const val VIBRATION_AMPLITUDE_DEFAULT_VALUE = 128
val LONG_PRESS_DURATION_DEFAULT_VALUE = ViewConfiguration.getLongPressTimeout().toLong()
val LONG_PRESS_DURATION_DEFAULT_VALUE = ViewConfiguration.getLongPressTimeout()

fun SharedPreferences?.getSelectedEffect(): Int {
val defaultValue = SELECTED_EFFECT_DEFAULT_VALUE
Expand All @@ -27,19 +27,19 @@ object SharedPreferencesUtil {
return VibrationType.values[getSelectedEffect()]
}

fun SharedPreferences?.getVibrationLength(): Long {
fun SharedPreferences?.getVibrationLength(): Int {
val defaultValue = VIBRATION_LENGTH_DEFAULT_VALUE
return this?.getLong(VIBRATION_LENGTH, defaultValue) ?: defaultValue
return this?.getInt(VIBRATION_LENGTH, defaultValue) ?: defaultValue
}

fun SharedPreferences?.getVibrationAmplitude(): Int {
val defaultValue = VIBRATION_AMPLITUDE_DEFAULT_VALUE
return this?.getInt(VIBRATION_AMPLITUDE, defaultValue) ?: defaultValue
}

fun SharedPreferences?.getLongPressDuration(): Long {
fun SharedPreferences?.getLongPressDuration(): Int {
val defaultValue = LONG_PRESS_DURATION_DEFAULT_VALUE
return this?.getLong(LONG_PRESS_DURATION, defaultValue) ?: defaultValue
return this?.getInt(LONG_PRESS_DURATION, defaultValue) ?: defaultValue
}

fun prefs(): SharedPreferences? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object VibratorUtil {
} else {
this.vibrate(
VibrationEffect.createOneShot(
prefs.getVibrationLength(),
prefs.getVibrationLength().toLong(),
prefs.getVibrationAmplitude()
)
)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
<string name="cancel">Cancel</string>
<string name="edit">Edit</string>

<string name="value_in_range">Value in range %d..%d</string>
<string name="value_in_range">Value in range %1$d..%2$d</string>
</resources>
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {
id("org.jetbrains.kotlin.plugin.compose") version "2.1.0" apply false
}

val versionName = "1.15.2"
val versionCode = 9
val versionName = "1.15.3"
val versionCode = 10

rootProject.ext.set("appVersionName", versionName)
rootProject.ext.set("appVersionCode", versionCode)
Expand Down
Loading