From 12a6e73a0f8062147d371c1beee0cc33d215380d Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 20 Feb 2014 11:57:38 +0100 Subject: [PATCH] Added template for on demand restricting Closes #1376 Refs #1395 --- CHANGELOG.md | 1 + res/layout/templateentry.xml | 10 +++++----- src/biz/bokhorst/xprivacy/ActivityMain.java | 15 +++++++-------- src/biz/bokhorst/xprivacy/PrivacyManager.java | 10 ++++++---- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f76b18a24..23358f9fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Changelog * Fixed select/unselect all ([issue](/../../issues/1390)) * Fixed some more repeated asking on demand, thanks @[jpeg729](https://github.com/jpeg729) * Improved tutorial/info background ([issue](/../../issues/1391)) +* Added template for on demand restricting, thanks @[jpeg729](https://github.com/jpeg729) ([issue](/../../issues/1376)) * Updated German translation * Updated French translation * Updated Lithuanian translation diff --git a/res/layout/templateentry.xml b/res/layout/templateentry.xml index 3ead8091b..67c4a41c0 100644 --- a/res/layout/templateentry.xml +++ b/res/layout/templateentry.xml @@ -2,16 +2,16 @@ + android:orientation="horizontal" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" > \ No newline at end of file diff --git a/src/biz/bokhorst/xprivacy/ActivityMain.java b/src/biz/bokhorst/xprivacy/ActivityMain.java index 0f33a3ca1..5725ad8a8 100644 --- a/src/biz/bokhorst/xprivacy/ActivityMain.java +++ b/src/biz/bokhorst/xprivacy/ActivityMain.java @@ -1110,17 +1110,16 @@ public View getView(int position, View convertView, ViewGroup parent) { convertView = mInflater.inflate(R.layout.templateentry, null); holder = new ViewHolder(convertView, position); convertView.setTag(holder); - } else { + } else holder = (ViewHolder) convertView.getTag(); - } // Get info final String templateName = PrivacyManager.cSettingTemplate + "." + listRestrictionName.get(position); - String value = PrivacyManager.getSetting(0, templateName, "false+ask", false); + String value = PrivacyManager.getSetting(0, templateName, Boolean.toString(!ondemand) + "+ask", false); holder.restricted = value.contains("true"); - holder.asked = !ondemand || value.contains("asked"); - Bitmap check = holder.asked ? (holder.restricted ? getFullCheckBox() : getOffCheckBox()) - : getOnDemandCheckBox(); + holder.asked = (!ondemand || value.contains("asked")); + Bitmap check = (holder.asked ? (holder.restricted ? getFullCheckBox() : getOffCheckBox()) + : getOnDemandCheckBox()); // Set data holder.tvRestriction.setText(listLocalizedTitle.get(position)); @@ -1140,8 +1139,8 @@ public void onClick(View arg0) { holder.restricted = true; holder.asked = true; } - PrivacyManager.setSetting(0, templateName, (holder.restricted ? "true" : "false") - + "+" + (holder.asked ? "asked" : "ask")); + PrivacyManager.setSetting(0, templateName, (holder.restricted ? "true" : "false") + "+" + + (holder.asked ? "asked" : "ask")); Bitmap check = holder.asked ? (holder.restricted ? getFullCheckBox() : getOffCheckBox()) : getOnDemandCheckBox(); diff --git a/src/biz/bokhorst/xprivacy/PrivacyManager.java b/src/biz/bokhorst/xprivacy/PrivacyManager.java index 5fa28e5e2..682a89829 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyManager.java +++ b/src/biz/bokhorst/xprivacy/PrivacyManager.java @@ -411,14 +411,16 @@ public static void applyTemplate(int uid) { // Enable on-demand boolean ondemand = PrivacyManager.getSettingBool(0, PrivacyManager.cSettingOnDemand, true, false); if (ondemand) - PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(true)); + ondemand = PrivacyManager.getSettingBool(-uid, PrivacyManager.cSettingOnDemand, false, false); // Apply template for (String restrictionName : PrivacyManager.getRestrictions()) { String templateName = PrivacyManager.cSettingTemplate + "." + restrictionName; - String templateValue = PrivacyManager.getSetting(0, templateName, "false+ask", false); - PrivacyManager.setRestriction(uid, restrictionName, null, templateValue.contains("true"), - !ondemand || templateValue.contains("asked")); + String templateValue = PrivacyManager.getSetting(0, templateName, Boolean.toString(!ondemand) + "+ask", + false); + boolean restrict = templateValue.contains("true"); + boolean asked = templateValue.contains("asked"); + PrivacyManager.setRestriction(uid, restrictionName, null, restrict, asked || !ondemand); } }