Added back-end support for Custom DNS server
This commit is contained in:
parent
5bdfeb9a60
commit
abdee64724
@ -49,6 +49,7 @@ dependencies {
|
||||
compile 'com.android.support:design:25.3.1'
|
||||
compile 'com.android.support:support-v4:25.3.1'
|
||||
compile 'com.android.support:percent:25.3.1'
|
||||
compile 'com.android.support:cardview-v7:25.3.1'
|
||||
|
||||
compile 'org.pcap4j:pcap4j-core:1.7.0'
|
||||
compile 'org.pcap4j:pcap4j-packetfactory-propertiesbased:1.7.0'
|
||||
|
@ -33,11 +33,11 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
ListPreference primaryServer = (ListPreference) findPreference("primary_server");
|
||||
primaryServer.setEntries(DnsServer.getDnsServerNames(Daedalus.getInstance()));
|
||||
primaryServer.setEntryValues(DnsServer.getDnsServerIds());
|
||||
primaryServer.setSummary(DnsServer.getDnsServerById(primaryServer.getValue()).getStringDescription(Daedalus.getInstance()));
|
||||
primaryServer.setSummary(DnsServer.getDnsServerDescription(primaryServer.getValue(), Daedalus.getInstance()));
|
||||
primaryServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
preference.setSummary(DnsServer.getDnsServerById((String) newValue).getStringDescription(Daedalus.getInstance()));
|
||||
preference.setSummary(DnsServer.getDnsServerDescription((String) newValue, Daedalus.getInstance()));
|
||||
Snackbar.make(view, R.string.notice_need_restart, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
return true;
|
||||
@ -47,11 +47,11 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
ListPreference secondaryServer = (ListPreference) findPreference("secondary_server");
|
||||
secondaryServer.setEntries(DnsServer.getDnsServerNames(Daedalus.getInstance()));
|
||||
secondaryServer.setEntryValues(DnsServer.getDnsServerIds());
|
||||
secondaryServer.setSummary(DnsServer.getDnsServerById(secondaryServer.getValue()).getStringDescription(Daedalus.getInstance()));
|
||||
secondaryServer.setSummary(DnsServer.getDnsServerDescription(secondaryServer.getValue(), Daedalus.getInstance()));
|
||||
secondaryServer.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
preference.setSummary(DnsServer.getDnsServerById((String) newValue).getStringDescription(Daedalus.getInstance()));
|
||||
preference.setSummary(DnsServer.getDnsServerDescription((String) newValue, Daedalus.getInstance()));
|
||||
Snackbar.make(view, R.string.notice_need_restart, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
return true;
|
||||
|
@ -11,7 +11,14 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author PeratX
|
||||
* Daedalus Project
|
||||
*
|
||||
* @author iTXTech
|
||||
* @link https://itxtech.org
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*/
|
||||
public class Configurations {
|
||||
private static File file;
|
||||
|
@ -50,6 +50,11 @@ public class DnsServer {
|
||||
return server.getAddress();
|
||||
}
|
||||
}
|
||||
for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
|
||||
if (customDnsServer.getName().equals(id)) {
|
||||
return customDnsServer.getAddress();
|
||||
}
|
||||
}
|
||||
return Daedalus.DNS_SERVERS.get(0).getAddress();
|
||||
}
|
||||
|
||||
@ -59,6 +64,11 @@ public class DnsServer {
|
||||
return server.getAddress();
|
||||
}
|
||||
}
|
||||
for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
|
||||
if (customDnsServer.getName().equals(description)) {
|
||||
return customDnsServer.getAddress();
|
||||
}
|
||||
}
|
||||
return Daedalus.DNS_SERVERS.get(0).getAddress();
|
||||
}
|
||||
|
||||
@ -67,6 +77,9 @@ public class DnsServer {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
servers.add(server.getId());
|
||||
}
|
||||
for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
|
||||
servers.add(customDnsServer.getName());
|
||||
}
|
||||
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
|
||||
return servers.toArray(stringServers);
|
||||
}
|
||||
@ -76,17 +89,24 @@ public class DnsServer {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
servers.add(server.getStringDescription(context));
|
||||
}
|
||||
for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
|
||||
servers.add(customDnsServer.getName());
|
||||
}
|
||||
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
|
||||
return servers.toArray(stringServers);
|
||||
}
|
||||
|
||||
public static DnsServer getDnsServerById(String id) {
|
||||
public static String getDnsServerDescription(String id, Context context) {
|
||||
for (DnsServer server : Daedalus.DNS_SERVERS) {
|
||||
if (server.getId().equals(id)) {
|
||||
return server;
|
||||
return server.getStringDescription(context);
|
||||
}
|
||||
}
|
||||
return Daedalus.DNS_SERVERS.get(0);
|
||||
|
||||
for (CustomDnsServer customDnsServer : Daedalus.configurations.getCustomDnsServers()) {
|
||||
if (customDnsServer.getName().equals(id)) {
|
||||
return customDnsServer.getName();
|
||||
}
|
||||
}
|
||||
return Daedalus.DNS_SERVERS.get(0).getStringDescription(context);
|
||||
}
|
||||
}
|
||||
|
9
app/src/main/res/drawable/ic_note_add_black_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_note_add_black_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M14,2L6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6zM16,16h-3v3h-2v-3L8,16v-2h3v-3h2v3h3v2zM13,9L13,3.5L18.5,9L13,9z"/>
|
||||
</vector>
|
@ -11,13 +11,16 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_device_hub_black_24dp"/>
|
||||
android:src="@drawable/ic_note_add_black_24dp"
|
||||
android:tint="#FFFFFF"/>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/recyclerView_dns_servers"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="horizontal" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
|
||||
android:scrollbars="horizontal"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
@ -1,28 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
<android.support.v7.widget.CardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
<TextView
|
||||
app:cardCornerRadius="10dp"
|
||||
app:cardPreventCornerOverlap="true"
|
||||
app:cardUseCompatPadding="true">
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/textView_custom_dns_name"
|
||||
android:layout_marginTop="30dp"
|
||||
android:id="@+id/textView_custom_dns_address"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/textView_custom_dns_name"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"/>
|
||||
</RelativeLayout>
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/textView_custom_dns_name"
|
||||
android:layout_marginTop="30dp"
|
||||
android:id="@+id/textView_custom_dns_address"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/textView_custom_dns_name"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</android.support.v7.widget.CardView>
|
Loading…
Reference in New Issue
Block a user