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
This commit is contained in:
pandasoft0 2019-05-09 20:21:22 +03:00 committed by Konrad Pozniak
parent bd7f0dfe62
commit c75b046483
7 changed files with 88 additions and 79 deletions

View File

@ -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<Account>{
.enqueue(object : Callback<Account> {
override fun onResponse(call: Call<Account>, response: Response<Account>) {
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()
}
}

View File

@ -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()

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="@string/preferences_file_key">
<Preference
@ -18,8 +18,9 @@
android:key="blockedUsersPreference"
android:title="@string/action_view_blocks" />
<PreferenceCategory android:title="@string/pref_publishing">
<PreferenceCategory
android:shouldDisableView="true"
android:title="@string/pref_publishing">
<ListPreference
android:defaultValue="public"
android:entries="@array/post_privacy_names"
@ -28,40 +29,42 @@
android:summary="%s"
android:title="@string/pref_default_post_privacy" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_eye_24dp"
android:key="defaultMediaSensitivity"
android:title="@string/pref_default_media_sensitivity" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_title_timelines">
<SwitchPreference
<PreferenceCategory
android:shouldDisableView="true"
android:title="@string/pref_title_timelines">
<SwitchPreferenceCompat
android:key="mediaPreviewEnabled"
android:title="@string/pref_title_show_media_preview" />
<SwitchPreference
<SwitchPreferenceCompat
android:key="alwaysShowSensitiveMedia"
android:title="@string/pref_title_alway_show_sensitive_media" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_title_timeline_filters">
<PreferenceCategory
android:shouldDisableView="true"
android:title="@string/pref_title_timeline_filters">
<Preference
android:key="publicFilters"
android:title="@string/pref_title_public_filter_keywords"
/>
android:title="@string/pref_title_public_filter_keywords" />
<Preference
android:key="notificationFilters"
android:title="@string/title_notifications"
/>
android:title="@string/title_notifications" />
<Preference
android:key="homeFilters"
android:title="@string/title_home"
/>
android:title="@string/title_home" />
<Preference
android:key="threadFilters"
android:title="@string/pref_title_thread_filter_keywords"
/>
android:title="@string/pref_title_thread_filter_keywords" />
</PreferenceCategory>
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

View File

@ -1,22 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/pref_title_http_proxy_settings">
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="httpProxyEnabled"
android:title="@string/pref_title_http_proxy_enable"
app:iconSpaceReserved="false" />
<EditTextPreference
android:key="httpProxyServer"
android:summary="%s"
android:title="@string/pref_title_http_proxy_server"
app:iconSpaceReserved="false" />
<EditTextPreference
android:key="httpProxyPort"
android:summary="%s"
android:title="@string/pref_title_http_proxy_port"
app:iconSpaceReserved="false" />
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:key="notificationSettings"
android:title="@string/pref_title_edit_notification_settings">
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationsEnabled"
android:title="@string/pref_title_notifications_enabled"
@ -12,64 +12,63 @@
<PreferenceCategory
android:dependency="notificationsEnabled"
android:shouldDisableView="true"
android:title="@string/pref_title_notification_filters"
app:iconSpaceReserved="false">
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationFilterMentions"
android:title="@string/pref_title_notification_filter_mentions"
app:iconSpaceReserved="false" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationFilterFollows"
android:title="@string/pref_title_notification_filter_follows"
app:iconSpaceReserved="false" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationFilterReblogs"
android:title="@string/pref_title_notification_filter_reblogs"
app:iconSpaceReserved="false" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationFilterFavourites"
android:title="@string/pref_title_notification_filter_favourites"
app:iconSpaceReserved="false" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationFilterPolls"
android:title="@string/pref_title_notification_filter_poll"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:dependency="notificationsEnabled"
android:shouldDisableView="true"
android:title="@string/pref_title_notification_alerts"
app:iconSpaceReserved="false">
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationAlertSound"
android:title="@string/pref_title_notification_alert_sound"
app:iconSpaceReserved="false" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationAlertVibrate"
android:title="@string/pref_title_notification_alert_vibrate"
app:iconSpaceReserved="false" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="notificationAlertLight"
android:title="@string/pref_title_notification_alert_light"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="@string/preferences_file_key">
<PreferenceCategory
android:shouldDisableView="true"
android:title="@string/pref_title_appearance_settings">
<ListPreference
@ -15,9 +16,9 @@
<com.keylesspalace.tusky.EmojiPreference
android:defaultValue="@string/system_default"
android:icon="@drawable/ic_emoji_24dp"
android:key="emojiCompat"
android:summary="@string/system_default"
android:icon="@drawable/ic_emoji_24dp"
android:title="@string/emoji_style" />
<ListPreference
@ -36,45 +37,48 @@
android:summary="%s"
android:title="@string/pref_status_text_size" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="fabHide"
android:title="@string/pref_title_hide_follow_button" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="absoluteTimeView"
android:title="@string/pref_title_absolute_time" />
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="showBotOverlay"
android:title="@string/pref_title_bot_overlay" />
</PreferenceCategory>
<PreferenceCategory
android:shouldDisableView="true"
android:title="@string/pref_title_browser_settings">
<SwitchPreference
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="customTabs"
android:title="@string/pref_title_custom_tabs" />
</PreferenceCategory>
<PreferenceCategory
android:shouldDisableView="true"
android:title="@string/pref_title_status_filter">
<Preference
android:key="timelineFilterPreferences"
android:title="@string/pref_title_status_tabs" />
</PreferenceCategory>
<PreferenceCategory
android:shouldDisableView="true"
android:title="@string/pref_title_proxy_settings">
<Preference
android:key="httpProxyPreferences"
android:summary="%s"
android:title="@string/pref_title_http_proxy_settings" />
</PreferenceCategory>
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

View File

@ -1,20 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/pref_title_status_tabs">
<PreferenceCategory
android:shouldDisableView="true"
android:title="@string/title_home"
app:iconSpaceReserved="false">
<CheckBoxPreference
android:defaultValue="true"
android:key="tabFilterHomeBoosts"
android:title="@string/pref_title_show_boosts"
app:iconSpaceReserved="false" />
<CheckBoxPreference
android:defaultValue="true"
android:key="tabFilterHomeReplies"
android:title="@string/pref_title_show_replies"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>
</androidx.preference.PreferenceScreen>