perf: 优化触感反馈的开启方式
This commit is contained in:
parent
b5f327cacc
commit
5bd2383b50
2 changed files with 9 additions and 2 deletions
|
|
@ -32,6 +32,7 @@ import cn.super12138.todo.ui.pages.settings.components.SettingsRadioDialog
|
|||
import cn.super12138.todo.ui.pages.settings.components.SettingsRadioOptions
|
||||
import cn.super12138.todo.ui.pages.settings.components.SwitchSettingsItem
|
||||
import cn.super12138.todo.ui.viewmodels.MainViewModel
|
||||
import cn.super12138.todo.utils.VibrationUtils
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -80,7 +81,7 @@ fun SettingsInterface(
|
|||
leadingIcon = Icons.Outlined.Vibration,
|
||||
title = stringResource(R.string.pref_haptic_feedback),
|
||||
description = stringResource(R.string.pref_haptic_feedback_desc),
|
||||
onCheckedChange = {}
|
||||
onCheckedChange = { VibrationUtils.setEnabled(it) }
|
||||
)
|
||||
SettingsPlainBox(stringResource(R.string.pref_haptic_feedback_more_info))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,17 @@ import android.view.View
|
|||
import cn.super12138.todo.constants.GlobalValues
|
||||
|
||||
object VibrationUtils {
|
||||
private var isEnabled: Boolean = GlobalValues.hapticFeedback
|
||||
|
||||
fun setEnabled(enabled: Boolean) {
|
||||
isEnabled = enabled
|
||||
}
|
||||
|
||||
fun performHapticFeedback(
|
||||
view: View,
|
||||
feedbackConstants: Int = HapticFeedbackConstants.CONTEXT_CLICK
|
||||
) {
|
||||
if (GlobalValues.hapticFeedback) {
|
||||
if (isEnabled) {
|
||||
view.performHapticFeedback(feedbackConstants)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue