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 0182c1c..2fb205d 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/DnsTestFragment.java @@ -175,11 +175,10 @@ public class DnsTestFragment extends ToolbarFragment { private static void stopThread() { try { if (mThread != null) { - mThread.join(1); + mThread.interrupt(); mThread = null; } - } catch (Exception e) { - Log.e(TAG, e.toString()); + } catch (Exception ignored) { } } diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/RuleConfigFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/RuleConfigFragment.java index 5b797f9..34d0aa2 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/RuleConfigFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/RuleConfigFragment.java @@ -213,7 +213,7 @@ public class RuleConfigFragment extends ConfigFragment { String ruleDownloadUrl = ((EditTextPreference) findPreference("ruleDownloadUrl")).getText(); if (ruleName.equals("") | ruleType.equals("") | ruleFilename.equals("") | ruleDownloadUrl.equals("")) { - Snackbar.make(view, R.string.notice_fill_in_all, Snackbar.LENGTH_LONG) + Snackbar.make(view, R.string.notice_fill_in_all, Snackbar.LENGTH_SHORT) .setAction("Action", null).show(); return false; } @@ -318,7 +318,7 @@ public class RuleConfigFragment extends ConfigFragment { e.printStackTrace(); } - Snackbar.make(view, R.string.notice_downloaded, Snackbar.LENGTH_LONG) + Snackbar.make(view, R.string.notice_downloaded, Snackbar.LENGTH_SHORT) .setAction("Action", null).show(); break; } diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/RulesFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/RulesFragment.java index 751d141..c2b2f5c 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/RulesFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/RulesFragment.java @@ -50,7 +50,7 @@ public class RulesFragment extends ToolbarFragment implements Toolbar.OnMenuItem @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_rules, container, false); - currentType = Rule.TYPE_HOSTS; + currentType = Daedalus.configurations.getUsingRuleType(); RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView_rules); LinearLayoutManager manager = new LinearLayoutManager(getActivity()); @@ -107,6 +107,7 @@ public class RulesFragment extends ToolbarFragment implements Toolbar.OnMenuItem toolbar.inflateMenu(R.menu.rules); toolbar.setTitle(R.string.action_rules); toolbar.setOnMenuItemClickListener(this); + toolbar.getMenu().findItem(R.id.action_change_type).setTitle(Rule.getTypeById(currentType)); } @Override @@ -116,11 +117,10 @@ public class RulesFragment extends ToolbarFragment implements Toolbar.OnMenuItem if (id == R.id.action_change_type) { if (currentType == Rule.TYPE_HOSTS) { currentType = Rule.TYPE_DNAMASQ; - item.setTitle("DNSMasq"); } else if (currentType == Rule.TYPE_DNAMASQ) { currentType = Rule.TYPE_HOSTS; - item.setTitle("Hosts"); } + toolbar.getMenu().findItem(R.id.action_change_type).setTitle(Rule.getTypeById(currentType)); adapter.notifyDataSetChanged(); } return true; diff --git a/app/src/main/java/org/itxtech/daedalus/util/Configurations.java b/app/src/main/java/org/itxtech/daedalus/util/Configurations.java index c3da8e2..14d1d1e 100644 --- a/app/src/main/java/org/itxtech/daedalus/util/Configurations.java +++ b/app/src/main/java/org/itxtech/daedalus/util/Configurations.java @@ -97,6 +97,24 @@ public class Configurations { return hostsRules; } + public int getUsingRuleType() { + if (hostsRules != null && hostsRules.size() > 0) { + for (Rule rule : hostsRules) { + if (rule.isUsing()) { + return Rule.TYPE_HOSTS; + } + } + } + if (dnsmasqRules != null && dnsmasqRules.size() > 0) { + for (Rule rule : dnsmasqRules) { + if (rule.isUsing()) { + return Rule.TYPE_DNAMASQ; + } + } + } + return Rule.TYPE_HOSTS; + } + public static Configurations load(File file) { Configurations.file = file; Configurations config = null;