From 03ee84bf357542a26ab4737627ac4ea12eadb837 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 8 Apr 2024 10:05:07 +0200 Subject: [PATCH] fix crash when toggling setting after rotation --- .../settings/ConnectionSettingsFragment.java | 6 +++++- .../ui/fragment/settings/XmppPreferenceFragment.java | 12 +++++++++--- src/main/res/xml/preferences_connection.xml | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/fragment/settings/ConnectionSettingsFragment.java b/src/main/java/eu/siacs/conversations/ui/fragment/settings/ConnectionSettingsFragment.java index 26bb27dc9..61843bd93 100644 --- a/src/main/java/eu/siacs/conversations/ui/fragment/settings/ConnectionSettingsFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/fragment/settings/ConnectionSettingsFragment.java @@ -26,11 +26,15 @@ public class ConnectionSettingsFragment extends XmppPreferenceFragment { @Override public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { setPreferencesFromResource(R.xml.preferences_connection, rootKey); + final var connectionOptions = findPreference(AppSettings.SHOW_CONNECTION_OPTIONS); final var channelDiscovery = findPreference(AppSettings.CHANNEL_DISCOVERY_METHOD); final var groupsAndConferences = findPreference(GROUPS_AND_CONFERENCES); - if (channelDiscovery == null || groupsAndConferences == null) { + if (connectionOptions == null || channelDiscovery == null || groupsAndConferences == null) { throw new IllegalStateException(); } + if (QuickConversationsService.isQuicksy()) { + connectionOptions.setVisible(false); + } if (hideChannelDiscovery()) { groupsAndConferences.setVisible(false); channelDiscovery.setVisible(false); diff --git a/src/main/java/eu/siacs/conversations/ui/fragment/settings/XmppPreferenceFragment.java b/src/main/java/eu/siacs/conversations/ui/fragment/settings/XmppPreferenceFragment.java index 631ecb6c4..f3b1dabca 100644 --- a/src/main/java/eu/siacs/conversations/ui/fragment/settings/XmppPreferenceFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/fragment/settings/XmppPreferenceFragment.java @@ -1,10 +1,12 @@ package eu.siacs.conversations.ui.fragment.settings; import android.content.SharedPreferences; +import android.util.Log; import androidx.annotation.NonNull; import androidx.preference.PreferenceFragmentCompat; +import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.XmppActivity; @@ -17,10 +19,14 @@ public abstract class XmppPreferenceFragment extends PreferenceFragmentCompat { if (key == null) { return; } - onSharedPreferenceChanged(key); + if (isAdded()) { + onSharedPreferenceChanged(key); + } }; - protected void onSharedPreferenceChanged(@NonNull String key) {} + protected void onSharedPreferenceChanged(@NonNull String key) { + Log.d(Config.LOGTAG,"onSharedPreferenceChanged("+key+")"); + } public void onBackendConnected() {} @@ -43,7 +49,7 @@ public abstract class XmppPreferenceFragment extends PreferenceFragmentCompat { super.onPause(); final var sharedPreferences = getPreferenceManager().getSharedPreferences(); if (sharedPreferences != null) { - sharedPreferences.registerOnSharedPreferenceChangeListener( + sharedPreferences.unregisterOnSharedPreferenceChangeListener( this.sharedPreferenceChangeListener); } } diff --git a/src/main/res/xml/preferences_connection.xml b/src/main/res/xml/preferences_connection.xml index 3ac78e4be..bd69258c7 100644 --- a/src/main/res/xml/preferences_connection.xml +++ b/src/main/res/xml/preferences_connection.xml @@ -2,13 +2,13 @@ - -