Added import for rules
This commit is contained in:
parent
0830b34edb
commit
3ab62768fe
@ -21,7 +21,10 @@ import com.google.gson.JsonParseException;
|
|||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import org.itxtech.daedalus.activity.MainActivity;
|
import org.itxtech.daedalus.activity.MainActivity;
|
||||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||||
import org.itxtech.daedalus.util.*;
|
import org.itxtech.daedalus.util.Configurations;
|
||||||
|
import org.itxtech.daedalus.util.DnsServer;
|
||||||
|
import org.itxtech.daedalus.util.Rule;
|
||||||
|
import org.itxtech.daedalus.util.RulesResolver;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -54,15 +57,20 @@ public class Daedalus extends Application {
|
|||||||
add(new DnsServer("123.206.21.48", R.string.server_aixyz_south_china));
|
add(new DnsServer("123.206.21.48", R.string.server_aixyz_south_china));
|
||||||
}};
|
}};
|
||||||
|
|
||||||
public static final List<RulesProvider> HOSTS_PROVIDERS = new ArrayList<RulesProvider>() {{
|
public static final List<Rule> RULES = new ArrayList<Rule>() {{
|
||||||
add(new RulesProvider("racaljk/hosts", "https://coding.net/u/scaffrey/p/hosts/git/raw/master/hosts"));
|
//Build-in Hosts rule providers
|
||||||
add(new RulesProvider("fengixng/google-hosts", "https://raw.githubusercontent.com/fengixng/google-hosts/master/hosts"));
|
add(new Rule("racaljk/hosts", "racaljk.hosts", Rule.TYPE_HOSTS,
|
||||||
add(new RulesProvider("sy618/hosts", "https://raw.githubusercontent.com/sy618/hosts/master/ADFQ"));
|
"https://coding.net/u/scaffrey/p/hosts/git/raw/master/hosts", false));
|
||||||
}};
|
add(new Rule("fengixng/google-hosts", "fengixng.hosts", Rule.TYPE_HOSTS,
|
||||||
|
"https://raw.githubusercontent.com/fengixng/google-hosts/master/hosts", false));
|
||||||
|
add(new Rule("sy618/hosts", "sy618.hosts", Rule.TYPE_HOSTS,
|
||||||
|
"https://raw.githubusercontent.com/sy618/hosts/master/ADFQ", false));
|
||||||
|
//Build-in DNSMasq rule providers
|
||||||
|
add(new Rule("sy618/hosts/dnsad", "dnsad.dnsmasq", Rule.TYPE_DNAMASQ,
|
||||||
|
"https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsad", false));
|
||||||
|
add(new Rule("sy618/hosts/dnsfq", "dnsfq.dnsmasq", Rule.TYPE_DNAMASQ,
|
||||||
|
"https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsfq", false));
|
||||||
|
|
||||||
public static final List<RulesProvider> DNSMASQ_PROVIDERS = new ArrayList<RulesProvider>() {{
|
|
||||||
add(new RulesProvider("sy618/hosts/dnsad", "https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsad", "dnsad"));
|
|
||||||
add(new RulesProvider("sy618/hosts/dnsfq", "https://raw.githubusercontent.com/sy618/hosts/master/dnsmasq/dnsfq", "dnsfq"));
|
|
||||||
}};
|
}};
|
||||||
|
|
||||||
public static final String[] DEFAULT_TEST_DOMAINS = new String[]{
|
public static final String[] DEFAULT_TEST_DOMAINS = new String[]{
|
||||||
|
@ -40,7 +40,7 @@ public class RuleConfigFragment extends ConfigFragment {
|
|||||||
private Thread mThread = null;
|
private Thread mThread = null;
|
||||||
private RuleConfigHandler mHandler = null;
|
private RuleConfigHandler mHandler = null;
|
||||||
private View view;
|
private View view;
|
||||||
private int index;
|
private int id;
|
||||||
|
|
||||||
public void setIntent(Intent intent) {
|
public void setIntent(Intent intent) {
|
||||||
this.intent = intent;
|
this.intent = intent;
|
||||||
@ -77,7 +77,7 @@ public class RuleConfigFragment extends ConfigFragment {
|
|||||||
|
|
||||||
mHandler = new RuleConfigHandler().setView(view);
|
mHandler = new RuleConfigHandler().setView(view);
|
||||||
|
|
||||||
EditTextPreference ruleName = (EditTextPreference) findPreference("ruleName");
|
final EditTextPreference ruleName = (EditTextPreference) findPreference("ruleName");
|
||||||
ruleName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
ruleName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
@ -86,7 +86,7 @@ public class RuleConfigFragment extends ConfigFragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ListPreference ruleType = (ListPreference) findPreference("ruleType");
|
final ListPreference ruleType = (ListPreference) findPreference("ruleType");
|
||||||
final String[] entries = {"hosts", "DNSMasq"};
|
final String[] entries = {"hosts", "DNSMasq"};
|
||||||
String[] values = {"0", "1"};
|
String[] values = {"0", "1"};
|
||||||
ruleType.setEntries(entries);
|
ruleType.setEntries(entries);
|
||||||
@ -158,9 +158,31 @@ public class RuleConfigFragment extends ConfigFragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
index = intent.getIntExtra(ConfigActivity.LAUNCH_ACTION_ID, ConfigActivity.ID_NONE);
|
ListPreference ruleImportBuildIn = (ListPreference) findPreference("ruleImportBuildIn");
|
||||||
if (index != ConfigActivity.ID_NONE) {
|
ruleImportBuildIn.setEntries(Rule.getBuildInRuleNames());
|
||||||
Rule rule = Daedalus.configurations.getRules().get(index);
|
ruleImportBuildIn.setEntryValues(Rule.getBuildInRuleEntries());
|
||||||
|
ruleImportBuildIn.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
Rule rule = Daedalus.RULES.get(Integer.parseInt((String) newValue));
|
||||||
|
ruleName.setText(rule.getName());
|
||||||
|
ruleName.setSummary(rule.getName());
|
||||||
|
ruleType.setValue(String.valueOf(rule.getType()));
|
||||||
|
ruleType.setSummary(Rule.getTypeById(rule.getType()));
|
||||||
|
ruleFilename.setText(rule.getFileName());
|
||||||
|
ruleFilename.setSummary(rule.getFileName());
|
||||||
|
ruleDownloadUrl.setText(rule.getDownloadUrl());
|
||||||
|
ruleDownloadUrl.setSummary(rule.getDownloadUrl());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ruleImportBuildIn.setValue("0");
|
||||||
|
id = intent.getIntExtra(ConfigActivity.LAUNCH_ACTION_ID, ConfigActivity.ID_NONE);
|
||||||
|
Rule rule;
|
||||||
|
if (id != ConfigActivity.ID_NONE && (rule = Rule.getRuleById(String.valueOf(id))) != null) {
|
||||||
|
Rule.getRuleById(String.valueOf(id));
|
||||||
ruleName.setText(rule.getName());
|
ruleName.setText(rule.getName());
|
||||||
ruleName.setSummary(rule.getName());
|
ruleName.setSummary(rule.getName());
|
||||||
int type = rule.getType();
|
int type = rule.getType();
|
||||||
@ -180,6 +202,7 @@ public class RuleConfigFragment extends ConfigFragment {
|
|||||||
ruleDownloadUrl.setText("");
|
ruleDownloadUrl.setText("");
|
||||||
ruleDownloadUrl.setSummary("");
|
ruleDownloadUrl.setSummary("");
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,14 +218,18 @@ public class RuleConfigFragment extends ConfigFragment {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == ConfigActivity.ID_NONE) {
|
if (id == ConfigActivity.ID_NONE) {
|
||||||
Daedalus.configurations.getRules().add(new Rule(ruleName, ruleFilename, Integer.parseInt(ruleType), ruleDownloadUrl));
|
Rule rule = new Rule(ruleName, ruleFilename, Integer.parseInt(ruleType), ruleDownloadUrl);
|
||||||
|
Daedalus.configurations.getRules().add(rule);
|
||||||
|
id = Integer.parseInt(rule.getId());
|
||||||
} else {
|
} else {
|
||||||
Rule rule = Daedalus.configurations.getRules().get(index);
|
Rule rule = Rule.getRuleById(String.valueOf(id));
|
||||||
rule.setName(ruleName);
|
if (rule != null) {
|
||||||
rule.setType(Integer.parseInt(ruleType));
|
rule.setName(ruleName);
|
||||||
rule.setFileName(ruleFilename);
|
rule.setType(Integer.parseInt(ruleType));
|
||||||
rule.setDownloadUrl(ruleDownloadUrl);
|
rule.setFileName(ruleFilename);
|
||||||
|
rule.setDownloadUrl(ruleDownloadUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,13 +243,13 @@ public class RuleConfigFragment extends ConfigFragment {
|
|||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
break;
|
break;
|
||||||
case R.id.action_delete:
|
case R.id.action_delete:
|
||||||
if (index != ConfigActivity.ID_NONE) {
|
if (this.id != ConfigActivity.ID_NONE) {
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(getActivity())
|
||||||
.setTitle(R.string.notice_delete_confirm_prompt)
|
.setTitle(R.string.notice_delete_confirm_prompt)
|
||||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Daedalus.configurations.getRules().remove(index);
|
Daedalus.configurations.getRules().remove(RuleConfigFragment.this.id);
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -50,7 +50,8 @@ public class RulesFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||||
if (viewHolder instanceof RulesFragment.ViewHolder) {
|
if (viewHolder instanceof RulesFragment.ViewHolder) {
|
||||||
if (Daedalus.configurations.getRules().get(((ViewHolder) viewHolder).getIndex()).isUsing()) {
|
Rule rule = Rule.getRuleById(((ViewHolder) viewHolder).getId());
|
||||||
|
if (rule != null && rule.isServiceAndUsing()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,7 +122,7 @@ public class RulesFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
Rule rule = Daedalus.configurations.getRules().get(position);
|
Rule rule = Daedalus.configurations.getRules().get(position);
|
||||||
holder.setIndex(position);
|
holder.setId(rule.getId());
|
||||||
holder.textViewName.setText(rule.getName());
|
holder.textViewName.setText(rule.getName());
|
||||||
holder.textViewAddress.setText(rule.getFileName());
|
holder.textViewAddress.setText(rule.getFileName());
|
||||||
|
|
||||||
@ -145,14 +146,23 @@ public class RulesFragment extends Fragment {
|
|||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_rule, parent, false);
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_rule, parent, false);
|
||||||
return new ViewHolder(view);
|
return new ViewHolder(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkType(Rule rule) {
|
||||||
|
for (Rule check : Daedalus.configurations.getRules()) {
|
||||||
|
if (check.getType() != rule.getType()) {
|
||||||
|
check.setUsing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
private class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
||||||
private final TextView textViewName;
|
private final TextView textViewName;
|
||||||
private final TextView textViewAddress;
|
private final TextView textViewAddress;
|
||||||
private final TextView textViewSize;
|
private final TextView textViewSize;
|
||||||
private final View view;
|
private final View view;
|
||||||
private int index;
|
private String id;
|
||||||
|
|
||||||
ViewHolder(View view) {
|
ViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
@ -162,29 +172,37 @@ public class RulesFragment extends Fragment {
|
|||||||
textViewSize = (TextView) view.findViewById(R.id.textView_rule_size);
|
textViewSize = (TextView) view.findViewById(R.id.textView_rule_size);
|
||||||
view.setOnClickListener(this);
|
view.setOnClickListener(this);
|
||||||
view.setOnLongClickListener(this);
|
view.setOnLongClickListener(this);
|
||||||
view.setBackgroundResource(R.drawable.background_selectable);
|
view.findViewById(R.id.cardView_indicator).setBackgroundResource(R.drawable.background_selectable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIndex(int index) {
|
void setId(String id) {
|
||||||
this.index = index;
|
this.id = id;
|
||||||
view.setSelected(Daedalus.configurations.getRules().get(index).isUsing());
|
Rule rule = Rule.getRuleById(id);
|
||||||
|
if (rule != null) {
|
||||||
|
view.setSelected(rule.isUsing());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getIndex() {
|
String getId() {
|
||||||
return index;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Daedalus.configurations.getRules().get(index).setUsing(!v.isSelected());
|
Rule rule = Rule.getRuleById(id);
|
||||||
v.setSelected(!v.isSelected());
|
if (rule != null) {
|
||||||
|
rule.setUsing(!v.isSelected());
|
||||||
|
v.setSelected(!v.isSelected());
|
||||||
|
adapter.checkType(rule);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
if (!Daedalus.configurations.getRules().get(index).isUsing()) {
|
Rule rule = Rule.getRuleById(id);
|
||||||
|
if (rule != null && rule.isServiceAndUsing()) {
|
||||||
Daedalus.getInstance().startActivity(new Intent(Daedalus.getInstance(), ConfigActivity.class)
|
Daedalus.getInstance().startActivity(new Intent(Daedalus.getInstance(), ConfigActivity.class)
|
||||||
.putExtra(ConfigActivity.LAUNCH_ACTION_ID, index)
|
.putExtra(ConfigActivity.LAUNCH_ACTION_ID, Integer.parseInt(id))
|
||||||
.putExtra(ConfigActivity.LAUNCH_ACTION_FRAGMENT, ConfigActivity.LAUNCH_FRAGMENT_RULE)
|
.putExtra(ConfigActivity.LAUNCH_ACTION_FRAGMENT, ConfigActivity.LAUNCH_FRAGMENT_RULE)
|
||||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import java.util.ArrayList;
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
public class Configurations {
|
public class Configurations {
|
||||||
private static final int CUSTOM_DNS_ID_START = 32;
|
private static final int CUSTOM_ID_START = 32;
|
||||||
|
|
||||||
private static File file;
|
private static File file;
|
||||||
|
|
||||||
@ -30,15 +30,23 @@ public class Configurations {
|
|||||||
|
|
||||||
private ArrayList<Rule> rules;
|
private ArrayList<Rule> rules;
|
||||||
|
|
||||||
private int totalId;
|
private int totalDnsId;
|
||||||
|
private int totalRuleId;
|
||||||
|
|
||||||
private long activateCounter;
|
private long activateCounter;
|
||||||
|
|
||||||
int getNextId() {
|
int getNextDnsId() {
|
||||||
if (totalId < CUSTOM_DNS_ID_START) {
|
if (totalDnsId < CUSTOM_ID_START) {
|
||||||
totalId = CUSTOM_DNS_ID_START;
|
totalDnsId = CUSTOM_ID_START;
|
||||||
}
|
}
|
||||||
return totalId++;
|
return totalDnsId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getNextRuleId() {
|
||||||
|
if (totalRuleId < 0) {
|
||||||
|
totalRuleId = 0;
|
||||||
|
}
|
||||||
|
return totalRuleId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getActivateCounter() {
|
public long getActivateCounter() {
|
||||||
|
@ -23,7 +23,7 @@ public class CustomDnsServer {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.id = String.valueOf(Daedalus.configurations.getNextId());
|
this.id = String.valueOf(Daedalus.configurations.getNextDnsId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package org.itxtech.daedalus.util;
|
package org.itxtech.daedalus.util;
|
||||||
|
|
||||||
|
import org.itxtech.daedalus.Daedalus;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Daedalus Project
|
* Daedalus Project
|
||||||
*
|
*
|
||||||
@ -20,13 +24,29 @@ public class Rule {
|
|||||||
private int type;
|
private int type;
|
||||||
private String downloadUrl;
|
private String downloadUrl;
|
||||||
private boolean using;
|
private boolean using;
|
||||||
|
private String id;
|
||||||
|
|
||||||
public Rule(String name, String fileName, int type, String downloadUrl) {
|
public Rule(String name, String fileName, int type, String downloadUrl, boolean withId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.downloadUrl = downloadUrl;
|
this.downloadUrl = downloadUrl;
|
||||||
this.using = false;
|
this.using = false;
|
||||||
|
if (withId) {
|
||||||
|
this.id = String.valueOf(Daedalus.configurations.getNextRuleId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rule(String name, String fileName, int type, String downloadUrl) {
|
||||||
|
this(name, fileName, type, downloadUrl, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsing(boolean using) {
|
public void setUsing(boolean using) {
|
||||||
@ -68,4 +88,48 @@ public class Rule {
|
|||||||
public void setDownloadUrl(String downloadUrl) {
|
public void setDownloadUrl(String downloadUrl) {
|
||||||
this.downloadUrl = downloadUrl;
|
this.downloadUrl = downloadUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isServiceAndUsing() {
|
||||||
|
return Daedalus.getInstance().isServiceActivated() && isUsing();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//STATIC METHODS
|
||||||
|
public static String[] getBuildInRuleNames() {
|
||||||
|
ArrayList<String> names = new ArrayList<>(Daedalus.RULES.size());
|
||||||
|
for (Rule rule : Daedalus.RULES) {
|
||||||
|
names.add(rule.getName() + " - " + getTypeById(rule.getType()));
|
||||||
|
}
|
||||||
|
String[] strings = new String[names.size()];
|
||||||
|
return names.toArray(strings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getBuildInRuleEntries() {
|
||||||
|
ArrayList<String> entries = new ArrayList<>(Daedalus.RULES.size());
|
||||||
|
for (int i = 0; i < Daedalus.RULES.size(); i++) {
|
||||||
|
entries.add(String.valueOf(i));
|
||||||
|
}
|
||||||
|
String[] strings = new String[entries.size()];
|
||||||
|
return entries.toArray(strings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Rule getRuleById(String id) {
|
||||||
|
for (Rule rule : Daedalus.configurations.getRules()) {
|
||||||
|
if (rule.getId().equals(id)) {
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTypeById(int id) {
|
||||||
|
switch (id) {
|
||||||
|
case TYPE_HOSTS:
|
||||||
|
return "Hosts";
|
||||||
|
case TYPE_DNAMASQ:
|
||||||
|
return "DNSMasq";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
package org.itxtech.daedalus.util;
|
|
||||||
|
|
||||||
import org.itxtech.daedalus.Daedalus;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Daedalus Project
|
|
||||||
*
|
|
||||||
* @author iTX Technologies
|
|
||||||
* @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, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*/
|
|
||||||
public class RulesProvider {
|
|
||||||
private String name;
|
|
||||||
private String downloadURL;
|
|
||||||
private String fileName;
|
|
||||||
private String data;
|
|
||||||
|
|
||||||
public RulesProvider(String name, String downloadURL) {
|
|
||||||
this(name, downloadURL, "Unknown");
|
|
||||||
}
|
|
||||||
|
|
||||||
public RulesProvider(String name, String downloadURL, String fileName) {
|
|
||||||
this.name = name;
|
|
||||||
this.downloadURL = downloadURL;
|
|
||||||
this.fileName = fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDownloadURL() {
|
|
||||||
return downloadURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFileName() {
|
|
||||||
return fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(String data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getData() {
|
|
||||||
String temp = data;
|
|
||||||
data = null;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] getHostsProviderNames() {
|
|
||||||
ArrayList<String> servers = new ArrayList<>(Daedalus.HOSTS_PROVIDERS.size());
|
|
||||||
for (RulesProvider provider : Daedalus.HOSTS_PROVIDERS) {
|
|
||||||
servers.add(provider.getName());
|
|
||||||
}
|
|
||||||
String[] stringServers = new String[Daedalus.HOSTS_PROVIDERS.size()];
|
|
||||||
return servers.toArray(stringServers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String[] getDnsmasqProviderNames() {
|
|
||||||
ArrayList<String> servers = new ArrayList<>(Daedalus.DNSMASQ_PROVIDERS.size());
|
|
||||||
for (RulesProvider provider : Daedalus.DNSMASQ_PROVIDERS) {
|
|
||||||
servers.add(provider.getName());
|
|
||||||
}
|
|
||||||
String[] stringServers = new String[Daedalus.DNSMASQ_PROVIDERS.size()];
|
|
||||||
return servers.toArray(stringServers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getDownloadUrlByName(String name) {
|
|
||||||
for (RulesProvider provider : Daedalus.HOSTS_PROVIDERS) {
|
|
||||||
if (provider.getName().equals(name)) {
|
|
||||||
return provider.getDownloadURL();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RulesProvider getProviderByName(String name) {
|
|
||||||
for (RulesProvider provider : Daedalus.DNSMASQ_PROVIDERS) {
|
|
||||||
if (provider.getName().equals(name)) {
|
|
||||||
return provider;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -138,7 +138,7 @@ public class RulesResolver implements Runnable {
|
|||||||
data[1] = data[1].substring(1, data[1].length());
|
data[1] = data[1].substring(1, data[1].length());
|
||||||
}
|
}
|
||||||
rules.put(data[1], data[2]);
|
rules.put(data[1], data[2]);
|
||||||
Log.d(TAG, "Putting " + data[1] + " " + data[2]);
|
//Log.d(TAG, "Putting " + data[1] + " " + data[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package org.itxtech.daedalus.widget;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.support.v7.widget.CardView;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import org.itxtech.daedalus.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daedalus Project
|
||||||
|
*
|
||||||
|
* @author iTX Technologies & MrFuFuFu
|
||||||
|
* @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, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*/
|
||||||
|
public class BoundedCardView extends CardView {
|
||||||
|
public BoundedCardView(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BoundedCardView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initAttrs(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BoundedCardView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int boundedWidth;
|
||||||
|
private int boundedHeight;
|
||||||
|
|
||||||
|
private void initAttrs(Context context, AttributeSet attrs) {
|
||||||
|
TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.BoundedView);
|
||||||
|
boundedWidth = arr.getDimensionPixelSize(R.styleable.BoundedView_bounded_width, 0);
|
||||||
|
boundedHeight = arr.getDimensionPixelSize(R.styleable.BoundedView_bounded_height, 0);
|
||||||
|
arr.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
if (boundedWidth > 0 && boundedWidth < MeasureSpec.getSize(widthMeasureSpec)) {
|
||||||
|
MeasureSpec.makeMeasureSpec(boundedWidth, MeasureSpec.getMode(widthMeasureSpec));
|
||||||
|
}
|
||||||
|
if (boundedHeight > 0 && boundedHeight < MeasureSpec.getSize(heightMeasureSpec)) {
|
||||||
|
MeasureSpec.makeMeasureSpec(boundedHeight, MeasureSpec.getMode(heightMeasureSpec));
|
||||||
|
}
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,9 @@
|
|||||||
android:enterFadeDuration="@android:integer/config_mediumAnimTime"
|
android:enterFadeDuration="@android:integer/config_mediumAnimTime"
|
||||||
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
|
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
|
||||||
<item android:state_selected="true">
|
<item android:state_selected="true">
|
||||||
<color android:color="@color/colorPrimaryDark"/>
|
<color android:color="#ddff00"/>
|
||||||
|
</item>
|
||||||
|
<item android:state_selected="false">
|
||||||
|
<color android:color="@android:color/white"/>
|
||||||
</item>
|
</item>
|
||||||
</selector>
|
</selector>
|
||||||
|
@ -1,53 +1,64 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.v7.widget.CardView
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:layout_width="match_parent"
|
<android.support.v7.widget.CardView
|
||||||
android:clickable="true"
|
|
||||||
android:foreground="?attr/selectableItemBackgroundBorderless"
|
|
||||||
android:focusable="true"
|
|
||||||
app:cardBackgroundColor="@android:color/white"
|
|
||||||
app:cardCornerRadius="10dp"
|
|
||||||
app:cardPreventCornerOverlap="true"
|
|
||||||
app:cardUseCompatPadding="true">
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
android:layout_width="match_parent"
|
||||||
android:paddingRight="@dimen/activity_horizontal_margin">
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_marginTop="@dimen/margin_small"
|
||||||
|
android:layout_marginStart="@dimen/margin_small"
|
||||||
|
android:layout_marginEnd="@dimen/margin_small"
|
||||||
|
app:cardCornerRadius="10dp"
|
||||||
|
app:cardPreventCornerOverlap="true"
|
||||||
|
android:id="@+id/cardView_indicator">
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="@dimen/margin_small"
|
android:focusable="true"
|
||||||
android:paddingBottom="@dimen/margin_small"
|
android:orientation="vertical"
|
||||||
android:id="@+id/textView_rule_name"
|
android:padding="@dimen/margin_small"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
android:background="?android:attr/selectableItemBackground">
|
||||||
android:layout_alignParentTop="true"
|
<RelativeLayout
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_width="match_parent"
|
||||||
android:layout_alignParentStart="true"/>
|
android:layout_height="wrap_content"
|
||||||
<TextView
|
android:layout_marginStart="@dimen/margin_small">
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
<TextView
|
||||||
android:layout_below="@+id/textView_rule_name"
|
android:layout_width="match_parent"
|
||||||
android:paddingTop="@dimen/margin_small"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="@dimen/margin_small"
|
android:paddingTop="@dimen/margin_small"
|
||||||
android:id="@+id/textView_rule_detail"
|
android:paddingBottom="@dimen/margin_small"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:id="@+id/textView_rule_name"
|
||||||
android:layout_alignParentBottom="true"
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_alignParentStart="true"/>
|
android:layout_alignParentLeft="true"
|
||||||
<TextView android:id="@+id/textView_rule_size"
|
android:layout_alignParentStart="true"/>
|
||||||
android:layout_width="wrap_content"
|
<TextView
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_gravity="bottom"
|
android:layout_height="wrap_content"
|
||||||
android:paddingBottom="@dimen/margin_small"
|
android:layout_below="@+id/textView_rule_name"
|
||||||
android:paddingRight="@dimen/margin_small"
|
android:paddingTop="@dimen/margin_small"
|
||||||
android:paddingEnd="@dimen/margin_small"
|
android:paddingBottom="@dimen/margin_small"
|
||||||
android:layout_alignParentEnd="true"
|
android:id="@+id/textView_rule_detail"
|
||||||
android:layout_alignParentRight="true"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:ellipsize="end"
|
android:layout_alignParentBottom="true"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
android:layout_alignParentLeft="true"
|
||||||
</RelativeLayout>
|
android:layout_alignParentStart="true"/>
|
||||||
</android.support.v7.widget.CardView>
|
<TextView android:id="@+id/textView_rule_size"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:paddingBottom="@dimen/margin_small"
|
||||||
|
android:paddingRight="@dimen/margin_small"
|
||||||
|
android:paddingEnd="@dimen/margin_small"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"/>
|
||||||
|
</RelativeLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</android.support.v7.widget.CardView>
|
||||||
|
</FrameLayout>
|
@ -77,5 +77,7 @@
|
|||||||
<string name="settings_rule">规则设置</string>
|
<string name="settings_rule">规则设置</string>
|
||||||
<string name="settings_rule_download_url">规则下载地址</string>
|
<string name="settings_rule_download_url">规则下载地址</string>
|
||||||
<string name="settings_rule_sync">同步规则</string>
|
<string name="settings_rule_sync">同步规则</string>
|
||||||
<string name="settings_rule_filename" translatable="false">规则文件名</string>
|
<string name="settings_rule_filename">规则文件名</string>
|
||||||
|
<string name="settings_rule_import">导入</string>
|
||||||
|
<string name="settings_rule_import_build_in">从内置规则导入</string>
|
||||||
</resources>
|
</resources>
|
7
app/src/main/res/values/attrs.xml
Normal file
7
app/src/main/res/values/attrs.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<declare-styleable name="BoundedView">
|
||||||
|
<attr name="bounded_width" format="dimension"/>
|
||||||
|
<attr name="bounded_height" format="dimension"/>
|
||||||
|
</declare-styleable>
|
||||||
|
</resources>
|
@ -8,4 +8,6 @@
|
|||||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||||
<dimen name="nav_header_vertical_spacing">16dp</dimen>
|
<dimen name="nav_header_vertical_spacing">16dp</dimen>
|
||||||
<dimen name="nav_header_height">180dp</dimen>
|
<dimen name="nav_header_height">180dp</dimen>
|
||||||
|
|
||||||
|
<dimen name="config_item_max_width">480dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -77,5 +77,7 @@
|
|||||||
<string name="settings_rule">Rule Settings</string>
|
<string name="settings_rule">Rule Settings</string>
|
||||||
<string name="settings_rule_download_url">Rule Download Url</string>
|
<string name="settings_rule_download_url">Rule Download Url</string>
|
||||||
<string name="settings_rule_sync">Sync Rule</string>
|
<string name="settings_rule_sync">Sync Rule</string>
|
||||||
<string name="settings_rule_filename">Rule File Name</string>
|
<string name="settings_rule_filename">Rule Filename</string>
|
||||||
|
<string name="settings_rule_import">Import</string>
|
||||||
|
<string name="settings_rule_import_build_in">Import from build in rules</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:title="@string/settings_rule_name"/>
|
android:title="@string/settings_rule_name"/>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="Rule Settings"
|
android:key="rulSettings"
|
||||||
android:title="@string/settings_rule">
|
android:title="@string/settings_rule">
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="ruleType"
|
android:key="ruleType"
|
||||||
@ -27,4 +27,11 @@
|
|||||||
android:key="ruleSync"
|
android:key="ruleSync"
|
||||||
android:title="@string/settings_rule_sync"/>
|
android:title="@string/settings_rule_sync"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="Import"
|
||||||
|
android:title="@string/settings_rule_import">
|
||||||
|
<ListPreference
|
||||||
|
android:key="ruleImportBuildIn"
|
||||||
|
android:title="@string/settings_rule_import_build_in"/>
|
||||||
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user