fix crash when toggling setting after rotation
This commit is contained in:
parent
67e01af5ef
commit
03ee84bf35
|
@ -26,11 +26,15 @@ public class ConnectionSettingsFragment extends XmppPreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
|
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
|
||||||
setPreferencesFromResource(R.xml.preferences_connection, 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 channelDiscovery = findPreference(AppSettings.CHANNEL_DISCOVERY_METHOD);
|
||||||
final var groupsAndConferences = findPreference(GROUPS_AND_CONFERENCES);
|
final var groupsAndConferences = findPreference(GROUPS_AND_CONFERENCES);
|
||||||
if (channelDiscovery == null || groupsAndConferences == null) {
|
if (connectionOptions == null || channelDiscovery == null || groupsAndConferences == null) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
if (QuickConversationsService.isQuicksy()) {
|
||||||
|
connectionOptions.setVisible(false);
|
||||||
|
}
|
||||||
if (hideChannelDiscovery()) {
|
if (hideChannelDiscovery()) {
|
||||||
groupsAndConferences.setVisible(false);
|
groupsAndConferences.setVisible(false);
|
||||||
channelDiscovery.setVisible(false);
|
channelDiscovery.setVisible(false);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package eu.siacs.conversations.ui.fragment.settings;
|
package eu.siacs.conversations.ui.fragment.settings;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.ui.XmppActivity;
|
import eu.siacs.conversations.ui.XmppActivity;
|
||||||
|
@ -17,10 +19,14 @@ public abstract class XmppPreferenceFragment extends PreferenceFragmentCompat {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (isAdded()) {
|
||||||
onSharedPreferenceChanged(key);
|
onSharedPreferenceChanged(key);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected void onSharedPreferenceChanged(@NonNull String key) {}
|
protected void onSharedPreferenceChanged(@NonNull String key) {
|
||||||
|
Log.d(Config.LOGTAG,"onSharedPreferenceChanged("+key+")");
|
||||||
|
}
|
||||||
|
|
||||||
public void onBackendConnected() {}
|
public void onBackendConnected() {}
|
||||||
|
|
||||||
|
@ -43,7 +49,7 @@ public abstract class XmppPreferenceFragment extends PreferenceFragmentCompat {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
final var sharedPreferences = getPreferenceManager().getSharedPreferences();
|
final var sharedPreferences = getPreferenceManager().getSharedPreferences();
|
||||||
if (sharedPreferences != null) {
|
if (sharedPreferences != null) {
|
||||||
sharedPreferences.registerOnSharedPreferenceChangeListener(
|
sharedPreferences.unregisterOnSharedPreferenceChangeListener(
|
||||||
this.sharedPreferenceChangeListener);
|
this.sharedPreferenceChangeListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/pref_category_server_connection">
|
<PreferenceCategory android:title="@string/pref_category_server_connection">
|
||||||
<CheckBoxPreference
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="@bool/show_connection_options"
|
android:defaultValue="@bool/show_connection_options"
|
||||||
android:icon="@drawable/ic_settings_24dp"
|
android:icon="@drawable/ic_settings_24dp"
|
||||||
android:key="show_connection_options"
|
android:key="show_connection_options"
|
||||||
android:summary="@string/pref_show_connection_options_summary"
|
android:summary="@string/pref_show_connection_options_summary"
|
||||||
android:title="@string/pref_show_connection_options" />
|
android:title="@string/pref_show_connection_options" />
|
||||||
<CheckBoxPreference
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="@bool/use_tor"
|
android:defaultValue="@bool/use_tor"
|
||||||
android:icon="@drawable/ic_network_node_24dp"
|
android:icon="@drawable/ic_network_node_24dp"
|
||||||
android:key="use_tor"
|
android:key="use_tor"
|
||||||
|
|
Loading…
Reference in a new issue