diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java index e471fd8..03b7f45 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java @@ -55,7 +55,7 @@ public class DnsTestFragment extends Fragment { final Spinner spinnerServerChoice = (Spinner) view.findViewById(R.id.spinner_server_choice); ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, DnsServerHelper.getNames(Daedalus.getInstance())); spinnerServerChoice.setAdapter(spinnerArrayAdapter); - spinnerServerChoice.setSelection(Integer.parseInt(DnsServerHelper.getPrimary())); + spinnerServerChoice.setSelection(DnsServerHelper.getPosition(DnsServerHelper.getPrimary())); final AutoCompleteTextView textViewTestUrl = (AutoCompleteTextView) view.findViewById(R.id.autoCompleteTextView_test_url); ArrayAdapter autoCompleteArrayAdapter = new ArrayAdapter<>(Daedalus.getInstance(), android.R.layout.simple_list_item_1, Daedalus.DEFAULT_TEST_DOMAINS); diff --git a/app/src/main/java/org/itxtech/daedalus/util/DnsServerHelper.java b/app/src/main/java/org/itxtech/daedalus/util/DnsServerHelper.java index 61eee35..c805ac4 100644 --- a/app/src/main/java/org/itxtech/daedalus/util/DnsServerHelper.java +++ b/app/src/main/java/org/itxtech/daedalus/util/DnsServerHelper.java @@ -46,6 +46,20 @@ public class DnsServerHelper { return defaultPort; } + public static int getPosition(String id) { + int intId = Integer.parseInt(id); + if (intId < Daedalus.DNS_SERVERS.size()) { + return intId; + } + + for (int i = 0; i < Daedalus.configurations.getCustomDnsServers().size(); i++) { + if (Daedalus.configurations.getCustomDnsServers().get(i).getId().equals(id)) { + return i + Daedalus.DNS_SERVERS.size(); + } + } + return 0; + } + public static String getPrimary() { return String.valueOf(DnsServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("primary_server", "0")))); }