1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2024-12-22 07:43:15 +00:00

Show default rule state

This commit is contained in:
M66B 2015-10-25 23:40:40 +01:00
parent 13c86fc253
commit b71eefc2b6
2 changed files with 13 additions and 1 deletions

View file

@ -19,8 +19,10 @@ public class Rule implements Comparable<Rule> {
public boolean disabled;
public boolean wifi_blocked;
public boolean other_blocked;
public boolean wifi_default;
public boolean other_default;
private Rule(PackageInfo info, boolean wifi_blocked, boolean other_blocked, Context context) {
private Rule(PackageInfo info, boolean wifi_blocked, boolean other_blocked, boolean wifi_default, boolean other_default, Context context) {
PackageManager pm = context.getPackageManager();
this.info = info;
this.name = info.applicationInfo.loadLabel(pm).toString();
@ -34,6 +36,8 @@ public class Rule implements Comparable<Rule> {
this.wifi_blocked = wifi_blocked;
this.other_blocked = other_blocked;
this.wifi_default = wifi_default;
this.other_default = other_default;
}
public static List<Rule> getRules(Context context) {
@ -47,6 +51,8 @@ public class Rule implements Comparable<Rule> {
info,
wifi.getBoolean(info.packageName, prefs.getBoolean("whitelist_wifi", true)),
other.getBoolean(info.packageName, prefs.getBoolean("whitelist_other", true)),
!wifi.contains(info.packageName),
!other.contains(info.packageName),
context
));

View file

@ -76,15 +76,19 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
if (buttonView == holder.cbWifi) {
name = "wifi";
rule.wifi_blocked = isChecked;
rule.wifi_default = false;
} else {
name = "other";
rule.other_blocked = isChecked;
rule.other_default = false;
}
Log.i(TAG, rule.info.packageName + ": " + name + "=" + isChecked);
SharedPreferences prefs = context.getSharedPreferences(name, Context.MODE_PRIVATE);
prefs.edit().putBoolean(rule.info.packageName, isChecked).apply();
notifyDataSetChanged();
BlackHoleService.reload(name, context);
}
};
@ -102,10 +106,12 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
holder.cbWifi.setOnCheckedChangeListener(null);
holder.cbWifi.setChecked(rule.wifi_blocked);
holder.cbWifi.setOnCheckedChangeListener(cbListener);
holder.cbWifi.setAlpha(rule.wifi_default ? 0.4f : 1);
holder.cbOther.setOnCheckedChangeListener(null);
holder.cbOther.setChecked(rule.other_blocked);
holder.cbOther.setOnCheckedChangeListener(cbListener);
holder.cbOther.setAlpha(rule.other_default ? 0.4f : 1);
}
@Override