From c75b04648306a5664f9b4e6b0c7888d4ef7ff8b7 Mon Sep 17 00:00:00 2001 From: pandasoft0 Date: Thu, 9 May 2019 20:21:22 +0300 Subject: [PATCH] Disable click on preference category items (#1239) * Disable click on preference category item. tuskyapp#1221 Changed compat preferences widget to AndroidX according to (https://developer.android.com/guide/topics/ui/settings.html) * Update preference categories clickable --- .../preference/AccountPreferencesFragment.kt | 35 ++++++++-------- .../NotificationPreferencesFragment.kt | 24 +++++------ app/src/main/res/xml/account_preferences.xml | 41 ++++++++++--------- .../main/res/xml/http_proxy_preferences.xml | 9 ++-- .../main/res/xml/notification_preferences.xml | 27 ++++++------ app/src/main/res/xml/preferences.xml | 24 ++++++----- .../res/xml/timeline_filter_preferences.xml | 7 +++- 7 files changed, 88 insertions(+), 79 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt index 03110498..2da07159 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/AccountPreferencesFragment.kt @@ -20,13 +20,11 @@ import android.graphics.drawable.Drawable import android.os.Build import android.os.Bundle import com.google.android.material.snackbar.Snackbar -import androidx.preference.SwitchPreference -import androidx.preference.ListPreference -import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import android.util.Log import android.view.View +import androidx.preference.* import com.keylesspalace.tusky.* +import com.keylesspalace.tusky.R import com.keylesspalace.tusky.appstore.EventHub import com.keylesspalace.tusky.appstore.PreferenceChangedEvent import com.keylesspalace.tusky.db.AccountManager @@ -63,15 +61,15 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), private lateinit var blockedUsersPreference: Preference private lateinit var defaultPostPrivacyPreference: ListPreference - private lateinit var defaultMediaSensitivityPreference: SwitchPreference - private lateinit var alwaysShowSensitiveMediaPreference: SwitchPreference - private lateinit var mediaPreviewEnabledPreference: SwitchPreference + private lateinit var defaultMediaSensitivityPreference: SwitchPreferenceCompat + private lateinit var alwaysShowSensitiveMediaPreference: SwitchPreferenceCompat + private lateinit var mediaPreviewEnabledPreference: SwitchPreferenceCompat private lateinit var homeFiltersPreference: Preference private lateinit var notificationFiltersPreference: Preference private lateinit var publicFiltersPreference: Preference private lateinit var threadFiltersPreference: Preference - private val iconSize by lazy {resources.getDimensionPixelSize(R.dimen.preference_icon_size)} + private val iconSize by lazy { resources.getDimensionPixelSize(R.dimen.preference_icon_size) } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.account_preferences) @@ -81,9 +79,9 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), mutedUsersPreference = requirePreference("mutedUsersPreference") blockedUsersPreference = requirePreference("blockedUsersPreference") defaultPostPrivacyPreference = requirePreference("defaultPostPrivacy") as ListPreference - defaultMediaSensitivityPreference = requirePreference("defaultMediaSensitivity") as SwitchPreference - mediaPreviewEnabledPreference = requirePreference("mediaPreviewEnabled") as SwitchPreference - alwaysShowSensitiveMediaPreference = requirePreference("alwaysShowSensitiveMedia") as SwitchPreference + defaultMediaSensitivityPreference = requirePreference("defaultMediaSensitivity") as SwitchPreferenceCompat + mediaPreviewEnabledPreference = requirePreference("mediaPreviewEnabled") as SwitchPreferenceCompat + alwaysShowSensitiveMediaPreference = requirePreference("alwaysShowSensitiveMedia") as SwitchPreferenceCompat homeFiltersPreference = requirePreference("homeFilters") notificationFiltersPreference = requirePreference("notificationFilters") publicFiltersPreference = requirePreference("publicFilters") @@ -126,7 +124,7 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), } override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { - when(preference) { + when (preference) { defaultPostPrivacyPreference -> { preference.icon = getIconForVisibility(Status.Visibility.byString(newValue as String)) syncWithServer(visibility = newValue) @@ -156,7 +154,7 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), override fun onPreferenceClick(preference: Preference): Boolean { - return when(preference) { + return when (preference) { notificationPreference -> { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val intent = Intent() @@ -213,13 +211,14 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), private fun syncWithServer(visibility: String? = null, sensitive: Boolean? = null) { mastodonApi.accountUpdateSource(visibility, sensitive) - .enqueue(object: Callback{ + .enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { val account = response.body() - if(response.isSuccessful && account != null) { + if (response.isSuccessful && account != null) { accountManager.activeAccount?.let { - it.defaultPostPrivacy = account.source?.privacy ?: Status.Visibility.PUBLIC + it.defaultPostPrivacy = account.source?.privacy + ?: Status.Visibility.PUBLIC it.defaultMediaSensitivity = account.source?.sensitive ?: false accountManager.saveAccount(it) } @@ -238,9 +237,9 @@ class AccountPreferencesFragment : PreferenceFragmentCompat(), } private fun showErrorSnackbar(visibility: String?, sensitive: Boolean?) { - view?.let {view -> + view?.let { view -> Snackbar.make(view, R.string.pref_failed_to_sync, Snackbar.LENGTH_LONG) - .setAction(R.string.action_retry) { syncWithServer( visibility, sensitive)} + .setAction(R.string.action_retry) { syncWithServer(visibility, sensitive) } .show() } } diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/NotificationPreferencesFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/NotificationPreferencesFragment.kt index da175fd0..9103775e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/preference/NotificationPreferencesFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/preference/NotificationPreferencesFragment.kt @@ -16,10 +16,10 @@ package com.keylesspalace.tusky.fragment.preference import android.os.Bundle -import androidx.preference.SwitchPreference +import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import android.view.View +import androidx.preference.SwitchPreferenceCompat import com.keylesspalace.tusky.R import com.keylesspalace.tusky.db.AccountManager import com.keylesspalace.tusky.di.Injectable @@ -42,39 +42,39 @@ class NotificationPreferencesFragment : PreferenceFragmentCompat(), Preference.O if (activeAccount != null) { - val notificationPref = requirePreference("notificationsEnabled") as SwitchPreference + val notificationPref = requirePreference("notificationsEnabled") as SwitchPreferenceCompat notificationPref.isChecked = activeAccount.notificationsEnabled notificationPref.onPreferenceChangeListener = this - val mentionedPref = requirePreference("notificationFilterMentions") as SwitchPreference + val mentionedPref = requirePreference("notificationFilterMentions") as SwitchPreferenceCompat mentionedPref.isChecked = activeAccount.notificationsMentioned mentionedPref.onPreferenceChangeListener = this - val followedPref = requirePreference("notificationFilterFollows") as SwitchPreference + val followedPref = requirePreference("notificationFilterFollows") as SwitchPreferenceCompat followedPref.isChecked = activeAccount.notificationsFollowed followedPref.onPreferenceChangeListener = this - val boostedPref = requirePreference("notificationFilterReblogs") as SwitchPreference + val boostedPref = requirePreference("notificationFilterReblogs") as SwitchPreferenceCompat boostedPref.isChecked = activeAccount.notificationsReblogged boostedPref.onPreferenceChangeListener = this - val favoritedPref = requirePreference("notificationFilterFavourites") as SwitchPreference + val favoritedPref = requirePreference("notificationFilterFavourites") as SwitchPreferenceCompat favoritedPref.isChecked = activeAccount.notificationsFavorited favoritedPref.onPreferenceChangeListener = this - val pollsPref = requirePreference("notificationFilterPolls") as SwitchPreference + val pollsPref = requirePreference("notificationFilterPolls") as SwitchPreferenceCompat pollsPref.isChecked = activeAccount.notificationsPolls pollsPref.onPreferenceChangeListener = this - val soundPref = requirePreference("notificationAlertSound") as SwitchPreference + val soundPref = requirePreference("notificationAlertSound") as SwitchPreferenceCompat soundPref.isChecked = activeAccount.notificationSound soundPref.onPreferenceChangeListener = this - val vibrationPref = requirePreference("notificationAlertVibrate") as SwitchPreference + val vibrationPref = requirePreference("notificationAlertVibrate") as SwitchPreferenceCompat vibrationPref.isChecked = activeAccount.notificationVibration vibrationPref.onPreferenceChangeListener = this - val lightPref = requirePreference("notificationAlertLight") as SwitchPreference + val lightPref = requirePreference("notificationAlertLight") as SwitchPreferenceCompat lightPref.isChecked = activeAccount.notificationLight lightPref.onPreferenceChangeListener = this } @@ -88,7 +88,7 @@ class NotificationPreferencesFragment : PreferenceFragmentCompat(), Preference.O when (preference.key) { "notificationsEnabled" -> { activeAccount.notificationsEnabled = newValue as Boolean - if(NotificationHelper.areNotificationsEnabled(preference.context, accountManager)) { + if (NotificationHelper.areNotificationsEnabled(preference.context, accountManager)) { NotificationHelper.enablePullNotifications() } else { NotificationHelper.disablePullNotifications() diff --git a/app/src/main/res/xml/account_preferences.xml b/app/src/main/res/xml/account_preferences.xml index efec8e14..7898252d 100644 --- a/app/src/main/res/xml/account_preferences.xml +++ b/app/src/main/res/xml/account_preferences.xml @@ -1,5 +1,5 @@ - - - + - - - - - + - - + + + android:title="@string/pref_title_public_filter_keywords" /> + + android:title="@string/title_notifications" /> + + android:title="@string/title_home" /> + + android:title="@string/pref_title_thread_filter_keywords" /> - + diff --git a/app/src/main/res/xml/http_proxy_preferences.xml b/app/src/main/res/xml/http_proxy_preferences.xml index 08a9a99a..fef29426 100644 --- a/app/src/main/res/xml/http_proxy_preferences.xml +++ b/app/src/main/res/xml/http_proxy_preferences.xml @@ -1,22 +1,23 @@ - - + + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/xml/notification_preferences.xml b/app/src/main/res/xml/notification_preferences.xml index e2e53697..044b5b6b 100644 --- a/app/src/main/res/xml/notification_preferences.xml +++ b/app/src/main/res/xml/notification_preferences.xml @@ -1,10 +1,10 @@ - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 265725a7..1c930ca5 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -1,8 +1,9 @@ - - - - - - + - + - - + diff --git a/app/src/main/res/xml/timeline_filter_preferences.xml b/app/src/main/res/xml/timeline_filter_preferences.xml index 03f4fa77..dfd1393f 100644 --- a/app/src/main/res/xml/timeline_filter_preferences.xml +++ b/app/src/main/res/xml/timeline_filter_preferences.xml @@ -1,20 +1,23 @@ - + + - \ No newline at end of file + \ No newline at end of file