Add option to reset to default DNS servers

This commit is contained in:
Arne 2024-11-13 10:47:18 +01:00
parent 4c12749ebe
commit 278ac508ef
4 changed files with 53 additions and 0 deletions

View file

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

View file

@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?colorControlNormal" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M520,630L520,570L680,570L680,630L520,630ZM580,840L580,790L520,790L520,730L580,730L580,680L640,680L640,840L580,840ZM680,790L680,730L840,730L840,790L680,790ZM720,680L720,520L780,520L780,570L840,570L840,630L780,630L780,680L720,680ZM831,400L748,400Q722,312 649,256Q576,200 480,200Q363,200 281.5,281.5Q200,363 200,480Q200,552 232.5,612Q265,672 320,710L320,600L400,600L400,840L160,840L160,760L254,760Q192,710 156,637.5Q120,565 120,480Q120,405 148.5,339.5Q177,274 225.5,225.5Q274,177 339.5,148.5Q405,120 480,120Q609,120 706.5,199.5Q804,279 831,400Z"/>
</vector>

View file

@ -1317,4 +1317,7 @@
<string name="direct_messages">Direct messages</string>
<string name="channels">Channels</string>
<string name="manage_account">Manage account</string>
<string name="pref_reset_dns_server_summary">Reset to the default DNS servers. A phone restart is needed.</string>
<string name="pref_reset_dns_server_title">Reset DNS</string>
<string name="dns_server_reset">DNS reset</string>
</resources>

View file

@ -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" />
<Preference
android:key="reset_dns_server"
android:icon="@drawable/outline_reset_settings_24"
android:summary="@string/pref_reset_dns_server_summary"
android:title="@string/pref_reset_dns_server_title" />
</PreferenceCategory>
<PreferenceCategory