Improved rules activate
This commit is contained in:
parent
9f54c54205
commit
9ea61b0b95
@ -206,7 +206,7 @@ public class RuleConfigFragment extends ConfigFragment {
|
||||
return view;
|
||||
}
|
||||
|
||||
private void save() {
|
||||
private boolean save() {
|
||||
String ruleName = ((EditTextPreference) findPreference("ruleName")).getText();
|
||||
String ruleType = ((ListPreference) findPreference("ruleType")).getValue();
|
||||
String ruleFilename = ((EditTextPreference) findPreference("ruleFilename")).getText();
|
||||
@ -215,7 +215,7 @@ public class RuleConfigFragment extends ConfigFragment {
|
||||
if (ruleName.equals("") | ruleType.equals("") | ruleFilename.equals("") | ruleDownloadUrl.equals("")) {
|
||||
Snackbar.make(view, R.string.notice_fill_in_all, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id == ConfigActivity.ID_NONE) {
|
||||
@ -231,6 +231,7 @@ public class RuleConfigFragment extends ConfigFragment {
|
||||
rule.setDownloadUrl(ruleDownloadUrl);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -239,8 +240,9 @@ public class RuleConfigFragment extends ConfigFragment {
|
||||
|
||||
switch (id) {
|
||||
case R.id.action_apply:
|
||||
save();
|
||||
getActivity().finish();
|
||||
if (save()) {
|
||||
getActivity().finish();
|
||||
}
|
||||
break;
|
||||
case R.id.action_delete:
|
||||
if (this.id != ConfigActivity.ID_NONE) {
|
||||
|
@ -19,6 +19,7 @@ import org.itxtech.daedalus.util.Rule;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* Daedalus Project
|
||||
@ -119,6 +120,8 @@ public class RulesFragment extends Fragment {
|
||||
}
|
||||
|
||||
private class RuleAdapter extends RecyclerView.Adapter<ViewHolder> {
|
||||
private CopyOnWriteArrayList<ViewHolder> selectedItems = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
Rule rule = Daedalus.configurations.getRules().get(position);
|
||||
@ -147,13 +150,17 @@ public class RulesFragment extends Fragment {
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
void checkType(Rule rule) {
|
||||
for (Rule check : Daedalus.configurations.getRules()) {
|
||||
if (check.getType() != rule.getType()) {
|
||||
void checkType(Rule rule, ViewHolder holder) {
|
||||
for (ViewHolder viewHolder : selectedItems) {
|
||||
Rule check = Rule.getRuleById(viewHolder.getId());
|
||||
if (check != null && check.getType() != rule.getType()) {
|
||||
viewHolder.view.setSelected(false);
|
||||
check.setUsing(false);
|
||||
selectedItems.remove(viewHolder);
|
||||
notifyItemChanged(viewHolder.getLayoutPosition());
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
selectedItems.add(holder);
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,6 +187,9 @@ public class RulesFragment extends Fragment {
|
||||
Rule rule = Rule.getRuleById(id);
|
||||
if (rule != null) {
|
||||
view.setSelected(rule.isUsing());
|
||||
if (view.isSelected()) {
|
||||
adapter.selectedItems.add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,11 +199,18 @@ public class RulesFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Rule rule = Rule.getRuleById(id);
|
||||
if (rule != null) {
|
||||
rule.setUsing(!v.isSelected());
|
||||
v.setSelected(!v.isSelected());
|
||||
//adapter.checkType(rule);
|
||||
if (!Daedalus.getInstance().isServiceActivated()) {
|
||||
Rule rule = Rule.getRuleById(id);
|
||||
if (rule != null && !rule.isUsing()) {
|
||||
rule.setUsing(!v.isSelected());
|
||||
v.setSelected(!v.isSelected());
|
||||
if (v.isSelected()) {
|
||||
adapter.checkType(rule, this);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Snackbar.make(view, R.string.notice_after_stop, Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,4 +80,5 @@
|
||||
<string name="settings_rule_filename">规则文件名</string>
|
||||
<string name="settings_rule_import">导入</string>
|
||||
<string name="settings_rule_import_build_in">从内置规则导入</string>
|
||||
<string name="notice_after_stop">请在服务停止后更改启用的规则。</string>
|
||||
</resources>
|
@ -80,4 +80,5 @@
|
||||
<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>
|
||||
<string name="notice_after_stop">Please modify activated rules after stopping service.</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user