Gray background for unchanged rules

This commit is contained in:
M66B 2015-11-24 18:34:41 +01:00
parent c5316320d0
commit ad3672bde6
3 changed files with 42 additions and 10 deletions

View File

@ -154,11 +154,7 @@ public class Rule implements Comparable<Rule> {
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<Rule> {
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) {

View File

@ -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<RuleAdapter.ViewHolder> im
private Context context;
private boolean debuggable;
private boolean dark;
private int colorText;
private int colorAccent;
private List<Rule> listAll = new ArrayList<>();
@ -149,6 +151,10 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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();
}

View File

@ -2,8 +2,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:orientation="vertical">
android:orientation="vertical"
android:paddingBottom="2dp"
android:paddingTop="2dp">
<LinearLayout
android:layout_width="match_parent"