From b7e1cfb6fd208e20efe730f161d88d4683f7e95f Mon Sep 17 00:00:00 2001 From: Hepolise Date: Fri, 10 Jan 2025 21:43:16 +0300 Subject: [PATCH 1/5] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c06da0..5a0156c 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,5 @@ Works when the screen is off. * OnePlus 10 Pro (Android 13 & 14) -[Open an issue](https://github.com/Hepolise/VolumeKeyMusicManagerModule/issues/new) if you are experiencing some troubles on your device +[Open an issue](https://github.com/Hepolise/VolumeKeyTrackControlModule/issues/new) if you are +experiencing some troubles on your device From 6447dcecddbab9eac9bf709d2833c3627fde7987 Mon Sep 17 00:00:00 2001 From: Hepolise Date: Fri, 10 Jan 2025 21:43:56 +0300 Subject: [PATCH 2/5] Update module settings --- .../ui/SettingsActivity.kt | 75 +++++++++++++++---- .../volumekeytrackcontrol/util/Constants.kt | 6 ++ .../util/SharedPreferencesUtil.kt | 12 ++- .../util/VibratorUtil.kt | 16 ++-- app/src/main/res/values/strings.xml | 3 +- 5 files changed, 82 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/Constants.kt diff --git a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/ui/SettingsActivity.kt b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/ui/SettingsActivity.kt index bfc1cc9..de4c06d 100644 --- a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/ui/SettingsActivity.kt +++ b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/ui/SettingsActivity.kt @@ -1,7 +1,6 @@ package ru.hepolise.volumekeytrackcontrol.ui import android.annotation.SuppressLint -import android.app.Activity import android.content.Context import android.content.Intent import android.net.Uri @@ -64,10 +63,17 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.LinkAnnotation +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.TextLinkStyles +import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.text.withLink import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import ru.hepolise.volumekeytrackcontrol.util.Constants import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.LONG_PRESS_DURATION import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.LONG_PRESS_DURATION_DEFAULT_VALUE import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.SELECTED_EFFECT @@ -78,14 +84,14 @@ import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.VIBRATION_AM import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.VIBRATION_LENGTH import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.VIBRATION_LENGTH_DEFAULT_VALUE import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.getLongPressDuration -import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.getSelectedEffect import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.getVibrationAmplitude import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.getVibrationLength +import ru.hepolise.volumekeytrackcontrol.util.SharedPreferencesUtil.getVibrationType import ru.hepolise.volumekeytrackcontrol.util.VibrationType import ru.hepolise.volumekeytrackcontrol.util.VibratorUtil.getVibrator import ru.hepolise.volumekeytrackcontrol.util.VibratorUtil.triggerVibration import ru.hepolise.volumekeytrackcontrolmodule.R -import kotlin.system.exitProcess + class SettingsActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -130,14 +136,12 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) { val sharedPreferences = try { context.getSharedPreferences(SETTINGS_PREFS_NAME, Context.MODE_WORLD_READABLE) } catch (e: SecurityException) { - Toast.makeText(context, R.string.module_is_not_enabled, Toast.LENGTH_LONG).show() - // Clear the application stack and exit - (context as? Activity)?.finishAffinity() - exitProcess(0) + ModuleIsNotEnabled() + return } var longPressDuration by remember { mutableIntStateOf(sharedPreferences.getLongPressDuration()) } - var selectedEffect by remember { mutableIntStateOf(sharedPreferences.getSelectedEffect()) } + var vibrationType by remember { mutableStateOf(sharedPreferences.getVibrationType()) } var vibrationLength by remember { mutableIntStateOf(sharedPreferences.getVibrationLength()) } var vibrationAmplitude by remember { mutableIntStateOf(sharedPreferences.getVibrationAmplitude()) } @@ -210,7 +214,6 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) { Text(text = stringResource(R.string.vibration_settings), fontSize = 20.sp) - val vibrationType = VibrationType.values[selectedEffect] var effectExpanded by remember { mutableStateOf(false) } ExposedDropdownMenuBox( expanded = effectExpanded, @@ -228,12 +231,12 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) { ExposedDropdownMenu( expanded = effectExpanded, onDismissRequest = { effectExpanded = false }) { - VibrationType.values.forEachIndexed { index, effect -> + VibrationType.values.forEach { effect -> DropdownMenuItem( text = { Text(stringResource(VibrationEffectTitles[effect]!!)) }, onClick = { - selectedEffect = index - sharedPreferences.edit().putInt(SELECTED_EFFECT, index) + vibrationType = effect + sharedPreferences.edit().putString(SELECTED_EFFECT, effect.key) .apply() effectExpanded = false } @@ -350,7 +353,7 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) { Button(onClick = { sharedPreferences.edit().clear().apply() - selectedEffect = SELECTED_EFFECT_DEFAULT_VALUE + vibrationType = VibrationType.fromKey(SELECTED_EFFECT_DEFAULT_VALUE) vibrationLength = VIBRATION_LENGTH_DEFAULT_VALUE vibrationAmplitude = VIBRATION_AMPLITUDE_DEFAULT_VALUE longPressDuration = LONG_PRESS_DURATION_DEFAULT_VALUE @@ -367,8 +370,7 @@ fun VibrationSettingsScreen(vibrator: Vibrator?) { Button(onClick = { val intent = Intent(Intent.ACTION_VIEW) - intent.data = - Uri.parse("https://github.com/Hepolise/VolumeKeyTrackControlModule") + intent.data = Uri.parse(Constants.GITHUB_URL) context.startActivity(intent) }) { Text(stringResource(R.string.about)) @@ -439,6 +441,49 @@ fun NumberAlertDialog( } } +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun ModuleIsNotEnabled() { + Scaffold( + topBar = { + TopAppBar(title = { Text(stringResource(R.string.app_name)) }) + } + ) { padding -> + Box( + modifier = Modifier + .fillMaxSize() + ) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(padding), + verticalArrangement = Arrangement.spacedBy(16.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = buildAnnotatedString { + append(stringResource(id = R.string.module_is_not_enabled)) + append(" ") + withLink( + LinkAnnotation.Url( + url = Constants.GITHUB_NEW_ISSUE, + styles = TextLinkStyles( + style = SpanStyle( + color = MaterialTheme.colorScheme.primary, + textDecoration = TextDecoration.Underline + ) + ) + ) + ) { + append(stringResource(id = R.string.open_issue)) + } + } + ) + } + } + } +} + @Preview(showBackground = true) @Composable fun PreviewVibrationSettingsScreen() { diff --git a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/Constants.kt b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/Constants.kt new file mode 100644 index 0000000..a516ca0 --- /dev/null +++ b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/Constants.kt @@ -0,0 +1,6 @@ +package ru.hepolise.volumekeytrackcontrol.util + +object Constants { + const val GITHUB_URL = "https://github.com/Hepolise/VolumeKeyTrackControlModule" + const val GITHUB_NEW_ISSUE = "$GITHUB_URL/issues/new" +} \ No newline at end of file diff --git a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/SharedPreferencesUtil.kt b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/SharedPreferencesUtil.kt index 9e7cb44..af477a4 100644 --- a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/SharedPreferencesUtil.kt +++ b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/SharedPreferencesUtil.kt @@ -1,6 +1,7 @@ package ru.hepolise.volumekeytrackcontrol.util import android.content.SharedPreferences +import android.os.Build import android.view.ViewConfiguration import de.robv.android.xposed.XSharedPreferences import ru.hepolise.volumekeytrackcontrolmodule.BuildConfig @@ -13,18 +14,15 @@ object SharedPreferencesUtil { const val VIBRATION_AMPLITUDE = "vibrationAmplitude" const val LONG_PRESS_DURATION = "longPressDuration" - const val SELECTED_EFFECT_DEFAULT_VALUE = 0 + val SELECTED_EFFECT_DEFAULT_VALUE = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) VibrationType.Click.key else VibrationType.Manual.key const val VIBRATION_LENGTH_DEFAULT_VALUE = 50 const val VIBRATION_AMPLITUDE_DEFAULT_VALUE = 128 val LONG_PRESS_DURATION_DEFAULT_VALUE = ViewConfiguration.getLongPressTimeout() - fun SharedPreferences?.getSelectedEffect(): Int { - val defaultValue = SELECTED_EFFECT_DEFAULT_VALUE - return this?.getInt(SELECTED_EFFECT, defaultValue) ?: defaultValue - } - fun SharedPreferences?.getVibrationType(): VibrationType { - return VibrationType.values[getSelectedEffect()] + val defaultValue = SELECTED_EFFECT_DEFAULT_VALUE + return VibrationType.fromKey(this?.getString(SELECTED_EFFECT, defaultValue) ?: defaultValue) } fun SharedPreferences?.getVibrationLength(): Int { diff --git a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/VibratorUtil.kt b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/VibratorUtil.kt index 92ccadd..a5d7432 100644 --- a/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/VibratorUtil.kt +++ b/app/src/main/java/ru/hepolise/volumekeytrackcontrol/util/VibratorUtil.kt @@ -41,9 +41,9 @@ object VibratorUtil { } -sealed class VibrationType(val value: Int) { - data object Disabled : VibrationType(-1) - data object Manual : VibrationType(-1) +sealed class VibrationType(val value: Int, val key: String) { + data object Disabled : VibrationType(-1, "disabled") + data object Manual : VibrationType(-1, "manual") companion object { val values: List by lazy { @@ -59,17 +59,19 @@ sealed class VibrationType(val value: Int) { add(Disabled) } } + + fun fromKey(key: String): VibrationType = values.single { it.key == key } } @RequiresApi(Build.VERSION_CODES.Q) - data object Click : VibrationType(VibrationEffect.EFFECT_CLICK) + data object Click : VibrationType(VibrationEffect.EFFECT_CLICK, "click") @RequiresApi(Build.VERSION_CODES.Q) - data object DoubleClick : VibrationType(VibrationEffect.EFFECT_DOUBLE_CLICK) + data object DoubleClick : VibrationType(VibrationEffect.EFFECT_DOUBLE_CLICK, "double_click") @RequiresApi(Build.VERSION_CODES.Q) - data object HeavyClick : VibrationType(VibrationEffect.EFFECT_HEAVY_CLICK) + data object HeavyClick : VibrationType(VibrationEffect.EFFECT_HEAVY_CLICK, "heavy_click") @RequiresApi(Build.VERSION_CODES.Q) - data object Tick : VibrationType(VibrationEffect.EFFECT_TICK) + data object Tick : VibrationType(VibrationEffect.EFFECT_TICK, "tick") } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc139b2..4f354d1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,7 +25,8 @@ Settings are reset to default About - Module is not enabled in LSPosed + Module is not enabled in LSPosed.\nIf you think this is a bug, please + open an issue OK Cancel From fd7c439bbfeb18412db6117618fff359f55c26d1 Mon Sep 17 00:00:00 2001 From: Hepolise Date: Fri, 10 Jan 2025 21:44:04 +0300 Subject: [PATCH 3/5] Fix project name --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 9eef2a5..df7c36c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,5 +15,5 @@ dependencyResolutionManagement { mavenCentral() } } -rootProject.name = "VolumeKeyMusicManagerModule" +rootProject.name = "VolumeKeyTrackControlModule" include ':app' From 04d537b5f419683c8781415ff442b9aecd436f2a Mon Sep 17 00:00:00 2001 From: Hepolise Date: Fri, 10 Jan 2025 21:51:48 +0300 Subject: [PATCH 4/5] Update module is not enabled info --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4f354d1..42aa5b7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,7 +25,7 @@ Settings are reset to default About - Module is not enabled in LSPosed.\nIf you think this is a bug, please + Module is not enabled in LSPosed.\nRestart thea app after enabling the module.\nIf you think this is a bug, please open an issue OK From e47de1fd67c4e74b0181f6e7d18bb0e22e767f91 Mon Sep 17 00:00:00 2001 From: Hepolise Date: Fri, 10 Jan 2025 21:56:01 +0300 Subject: [PATCH 5/5] Fix typo --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42aa5b7..554a0f9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,7 +25,7 @@ Settings are reset to default About - Module is not enabled in LSPosed.\nRestart thea app after enabling the module.\nIf you think this is a bug, please + Module is not enabled in LSPosed.\nRestart the app after enabling the module.\nIf you think this is a bug, please open an issue OK