From 14f2988d139a14cf98a764f1d8ee843827a116b6 Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 26 Dec 2021 22:11:37 +0100 Subject: [PATCH] Hide notification vibration settings when there's no vibrator hardware --- .../k9/ui/settings/account/AccountSettingsFragment.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/settings/account/AccountSettingsFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/settings/account/AccountSettingsFragment.kt index 62e786af3..8c7de2175 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/settings/account/AccountSettingsFragment.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/settings/account/AccountSettingsFragment.kt @@ -4,10 +4,12 @@ import android.annotation.SuppressLint import android.content.Intent import android.os.Build import android.os.Bundle +import android.os.Vibrator import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.widget.Toast +import androidx.core.content.getSystemService import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceCategory @@ -49,6 +51,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr private val messagingController: MessagingController by inject() private val accountRemover: BackgroundAccountRemover by inject() private val notificationChannelManager: NotificationChannelManager by inject() + private val vibrator by lazy { requireContext().getSystemService() } private lateinit var dataStore: AccountSettingsDataStore private var notificationLightColorPreference: ColorPickerPreference? = null private var notificationVibrationPatternPreference: VibrationPatternPreference? = null @@ -187,6 +190,11 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr } private fun initializeNotifications(account: Account) { + if (vibrator?.hasVibrator() != true) { + findPreference(PREFERENCE_NOTIFICATION_VIBRATION_PATTERN)?.remove() + findPreference(PREFERENCE_NOTIFICATION_ENABLE_VIBRATION)?.remove() + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { findPreference(PREFERENCE_NOTIFICATION_LIGHT_COLOR)?.let { preference -> notificationLightColorPreference = preference @@ -433,6 +441,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr private const val PREFERENCE_SPAM_FOLDER = "spam_folder" private const val PREFERENCE_TRASH_FOLDER = "trash_folder" private const val PREFERENCE_NOTIFICATION_LIGHT_COLOR = "led_color" + private const val PREFERENCE_NOTIFICATION_ENABLE_VIBRATION = "account_vibrate" private const val PREFERENCE_NOTIFICATION_VIBRATION_PATTERN = "account_combined_vibration_pattern" private const val PREFERENCE_NOTIFICATION_CHANNELS = "notification_channels" private const val PREFERENCE_NOTIFICATION_SETTINGS_MESSAGES = "open_notification_settings_messages" @@ -441,7 +450,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr private val PRE_SDK26_NOTIFICATION_PREFERENCES = arrayOf( "account_ringtone", - "account_vibrate", + PREFERENCE_NOTIFICATION_ENABLE_VIBRATION, "account_led", )