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 61843bd93..8b0180d7e 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 @@ -1,17 +1,27 @@ package eu.siacs.conversations.ui.fragment.settings; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.EditTextPreference; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.PreferenceManager; import com.google.common.base.Strings; +import java.io.File; + import eu.siacs.conversations.AppSettings; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.services.QuickConversationsService; +import eu.siacs.conversations.ui.activity.SettingsActivity; +import eu.siacs.conversations.utils.ChatBackgroundHelper; public class ConnectionSettingsFragment extends XmppPreferenceFragment { @@ -39,6 +49,25 @@ public class ConnectionSettingsFragment extends XmppPreferenceFragment { groupsAndConferences.setVisible(false); channelDiscovery.setVisible(false); } + + final var resetDNSServerPreference = findPreference("reset_dns_server"); + if (resetDNSServerPreference != null) { + resetDNSServerPreference.setOnPreferenceClickListener(preference -> { + + final var dnsv4Server = (EditTextPreference) findPreference("dns_server_ipv4"); + if (dnsv4Server != null) { + dnsv4Server.setText("194.242.2.2"); + } + + final var dnsv6Server = (EditTextPreference) findPreference("dns_server_ipv6"); + if (dnsv6Server != null) { + dnsv6Server.setText("[2a07:e340::2]"); + } + + Toast.makeText(requireSettingsActivity(),R.string.dns_server_reset,Toast.LENGTH_LONG).show(); + return true; + }); + } } @Override @@ -70,4 +99,15 @@ public class ConnectionSettingsFragment extends XmppPreferenceFragment { super.onStart(); requireActivity().setTitle(R.string.pref_connection_options); } + + public SettingsActivity requireSettingsActivity() { + final var activity = requireActivity(); + if (activity instanceof SettingsActivity settingsActivity) { + return settingsActivity; + } + throw new IllegalStateException( + String.format( + "%s is not %s", + activity.getClass().getName(), SettingsActivity.class.getName())); + } } diff --git a/src/main/res/drawable/outline_reset_settings_24.xml b/src/main/res/drawable/outline_reset_settings_24.xml new file mode 100644 index 000000000..8c352d76e --- /dev/null +++ b/src/main/res/drawable/outline_reset_settings_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 6c0c5eb22..8e5fef191 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1317,4 +1317,7 @@ Direct messages Channels Manage account + Reset to the default DNS servers. A phone restart is needed. + Reset DNS + DNS reset \ No newline at end of file diff --git a/src/main/res/xml/preferences_connection.xml b/src/main/res/xml/preferences_connection.xml index 909137d9a..37e6d5c90 100644 --- a/src/main/res/xml/preferences_connection.xml +++ b/src/main/res/xml/preferences_connection.xml @@ -26,6 +26,11 @@ android:key="dns_server_ipv6" android:summary="@string/pref_dns_server_ipv6_summary" android:title="@string/pref_dns_server_ipv6_title" /> +