diff --git a/app/src/main/java/eu/faircode/netguard/Rule.java b/app/src/main/java/eu/faircode/netguard/Rule.java index 84ecbc9f..8ddf28c9 100644 --- a/app/src/main/java/eu/faircode/netguard/Rule.java +++ b/app/src/main/java/eu/faircode/netguard/Rule.java @@ -154,11 +154,7 @@ public class Rule implements Comparable { if (pre_related.containsKey(info.packageName)) rule.related = pre_related.get(info.packageName); - rule.changed = (rule.wifi_blocked != default_wifi || - rule.other_blocked != default_other || - (rule.wifi_blocked && rule.screen_wifi != rule.screen_wifi_default) || - (rule.other_blocked && rule.screen_other != rule.screen_other_default) || - ((!rule.other_blocked || rule.screen_other) && rule.roaming != default_roaming)); + rule.updateChanged(default_wifi, default_other, default_roaming); listRules.add(rule); } @@ -170,6 +166,22 @@ public class Rule implements Comparable { return listRules; } + private void updateChanged(boolean default_wifi, boolean default_other, boolean default_roaming) { + changed = (wifi_blocked != default_wifi || + other_blocked != default_other || + (wifi_blocked && screen_wifi != screen_wifi_default) || + (other_blocked && screen_other != screen_other_default) || + ((!other_blocked || screen_other) && roaming != default_roaming)); + } + + public void updateChanged(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean default_wifi = prefs.getBoolean("whitelist_wifi", true); + boolean default_other = prefs.getBoolean("whitelist_other", true); + boolean default_roaming = prefs.getBoolean("whitelist_roaming", true); + updateChanged(default_wifi, default_other, default_roaming); + } + @Override public int compareTo(Rule other) { if (changed == other.changed) { diff --git a/app/src/main/java/eu/faircode/netguard/RuleAdapter.java b/app/src/main/java/eu/faircode/netguard/RuleAdapter.java index 5efd1dee..f71eae04 100644 --- a/app/src/main/java/eu/faircode/netguard/RuleAdapter.java +++ b/app/src/main/java/eu/faircode/netguard/RuleAdapter.java @@ -26,6 +26,7 @@ import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.Rect; import android.net.Uri; +import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.util.Log; @@ -53,6 +54,7 @@ public class RuleAdapter extends RecyclerView.Adapter im private Context context; private boolean debuggable; + private boolean dark; private int colorText; private int colorAccent; private List listAll = new ArrayList<>(); @@ -149,6 +151,10 @@ public class RuleAdapter extends RecyclerView.Adapter im public RuleAdapter(Context context) { this.context = context; this.debuggable = Util.isDebuggable(context); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + dark = prefs.getBoolean("dark_theme", false); + colorAccent = ContextCompat.getColor(context, R.color.colorAccent); TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorSecondary}); try { @@ -177,6 +183,7 @@ public class RuleAdapter extends RecyclerView.Adapter im // Update rule String network = ((buttonView == holder.cbWifi) ? "wifi" : "other"); updateRule(rule, network, isChecked); + rule.updateChanged(context); // Update relations if (rule.related == null) @@ -189,6 +196,7 @@ public class RuleAdapter extends RecyclerView.Adapter im updateScreenWifi(related, rule.screen_wifi); updateScreenOther(related, rule.screen_other); updateRoaming(related, rule.roaming); + related.updateChanged(context); } notifyDataSetChanged(); } @@ -206,6 +214,8 @@ public class RuleAdapter extends RecyclerView.Adapter im } }; + holder.itemView.setBackgroundColor(rule.changed ? Color.TRANSPARENT : dark ? Color.DKGRAY : Color.LTGRAY); + holder.llApplication.setOnClickListener(llListener); if (rule.info.applicationInfo == null || rule.info.applicationInfo.icon == 0) @@ -259,6 +269,7 @@ public class RuleAdapter extends RecyclerView.Adapter im public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Update rule updateScreenWifi(rule, isChecked); + rule.updateChanged(context); // Update relations if (rule.related == null) @@ -266,8 +277,10 @@ public class RuleAdapter extends RecyclerView.Adapter im else { for (String pkg : rule.related) for (Rule related : listAll) - if (related.info.packageName.equals(pkg)) + if (related.info.packageName.equals(pkg)) { updateScreenWifi(related, rule.screen_wifi); + related.updateChanged(context); + } notifyDataSetChanged(); } @@ -285,6 +298,7 @@ public class RuleAdapter extends RecyclerView.Adapter im public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Update rule updateScreenOther(rule, isChecked); + rule.updateChanged(context); // Update relations if (rule.related == null) @@ -292,8 +306,10 @@ public class RuleAdapter extends RecyclerView.Adapter im else { for (String pkg : rule.related) for (Rule related : listAll) - if (related.info.packageName.equals(pkg)) + if (related.info.packageName.equals(pkg)) { updateScreenOther(related, rule.screen_other); + related.updateChanged(context); + } notifyDataSetChanged(); } @@ -311,6 +327,7 @@ public class RuleAdapter extends RecyclerView.Adapter im public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Update rule updateRoaming(rule, isChecked); + rule.updateChanged(context); // Update relations if (rule.related == null) @@ -318,8 +335,10 @@ public class RuleAdapter extends RecyclerView.Adapter im else { for (String pkg : rule.related) for (Rule related : listAll) - if (related.info.packageName.equals(pkg)) + if (related.info.packageName.equals(pkg)) { updateRoaming(related, rule.roaming); + related.updateChanged(context); + } notifyDataSetChanged(); } diff --git a/app/src/main/res/layout/rule.xml b/app/src/main/res/layout/rule.xml index 048c1d09..f75b023d 100644 --- a/app/src/main/res/layout/rule.xml +++ b/app/src/main/res/layout/rule.xml @@ -2,8 +2,9 @@ + android:orientation="vertical" + android:paddingBottom="2dp" + android:paddingTop="2dp">