Improved initial type

This commit is contained in:
PeratX 2017-05-21 21:08:21 +08:00
parent bb5c195283
commit 0a0be5815d
4 changed files with 25 additions and 8 deletions

View File

@ -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) {
}
}

View File

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

View File

@ -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;

View File

@ -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;