summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-05-28 22:20:44 -0400
committerJohn Spurlock <jspurlock@google.com>2015-05-28 22:20:44 -0400
commitbd352af3cfd200cc66bbc34a3a0174e2da334ab7 (patch)
treec203081d0e887121f1e6a09fdaa9efaa82c09571
parente6f9c110c7ce71c00f6c6b646ad3aada74ee0f76 (diff)
downloadpackages_apps_Settings-bd352af3cfd200cc66bbc34a3a0174e2da334ab7.tar.gz
packages_apps_Settings-bd352af3cfd200cc66bbc34a3a0174e2da334ab7.tar.bz2
packages_apps_Settings-bd352af3cfd200cc66bbc34a3a0174e2da334ab7.zip
Settings: Migrate zen event conditions to use calendar name.
And make sure any existing calendar value always appears in the picker, even before it exists in the calendar provider. Bug: 17755700 Change-Id: I8aa298a0d5804c288e2596f18c2dc7318f752121
-rw-r--r--src/com/android/settings/notification/ZenModeAutomationSettings.java9
-rw-r--r--src/com/android/settings/notification/ZenModeEventRuleSettings.java25
-rw-r--r--src/com/android/settings/notification/ZenRuleNameDialog.java2
3 files changed, 19 insertions, 17 deletions
diff --git a/src/com/android/settings/notification/ZenModeAutomationSettings.java b/src/com/android/settings/notification/ZenModeAutomationSettings.java
index 1cfa22a99..1cf3fe9f4 100644
--- a/src/com/android/settings/notification/ZenModeAutomationSettings.java
+++ b/src/com/android/settings/notification/ZenModeAutomationSettings.java
@@ -214,13 +214,8 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
}
private String computeCalendarName(EventInfo event) {
- if (event.calendar != EventInfo.ANY_CALENDAR) {
- final CalendarInfo calendar = ZenModeEventRuleSettings.findCalendar(mContext, event);
- if (calendar != null) {
- return calendar.name;
- }
- }
- return getString(R.string.zen_mode_event_rule_summary_any_calendar);
+ return event.calendar != null ? event.calendar
+ : getString(R.string.zen_mode_event_rule_summary_any_calendar);
}
private int computeReply(EventInfo event) {
diff --git a/src/com/android/settings/notification/ZenModeEventRuleSettings.java b/src/com/android/settings/notification/ZenModeEventRuleSettings.java
index c67ab4cbf..004d5dff4 100644
--- a/src/com/android/settings/notification/ZenModeEventRuleSettings.java
+++ b/src/com/android/settings/notification/ZenModeEventRuleSettings.java
@@ -16,8 +16,6 @@
package com.android.settings.notification;
-import static android.service.notification.ZenModeConfig.EventInfo.ANY_CALENDAR;
-
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
@@ -81,9 +79,17 @@ public class ZenModeEventRuleSettings extends ZenModeRuleSettingsBase {
private void reloadCalendar() {
mCalendars = getCalendars(mContext);
mCalendar.clearItems();
- mCalendar.addItem(R.string.zen_mode_event_rule_calendar_any, key(0, ANY_CALENDAR));
+ mCalendar.addItem(R.string.zen_mode_event_rule_calendar_any, key(0, null));
+ final String eventCalendar = mEvent != null ? mEvent.calendar : null;
+ boolean found = false;
for (CalendarInfo calendar : mCalendars) {
mCalendar.addItem(calendar.name, key(calendar));
+ if (eventCalendar != null && eventCalendar.equals(calendar.name)) {
+ found = true;
+ }
+ }
+ if (eventCalendar != null && !found) {
+ mCalendar.addItem(eventCalendar, key(mEvent.userId, eventCalendar));
}
}
@@ -101,7 +107,10 @@ public class ZenModeEventRuleSettings extends ZenModeRuleSettingsBase {
if (calendarKey.equals(key(mEvent))) return true;
final int i = calendarKey.indexOf(':');
mEvent.userId = Integer.parseInt(calendarKey.substring(0, i));
- mEvent.calendar = Long.parseLong(calendarKey.substring(i + 1));
+ mEvent.calendar = calendarKey.substring(i + 1);
+ if (mEvent.calendar.isEmpty()) {
+ mEvent.calendar = null;
+ }
updateRule(ZenModeConfig.toEventConditionId(mEvent));
return true;
}
@@ -185,7 +194,6 @@ public class ZenModeEventRuleSettings extends ZenModeRuleSettingsBase {
}
while (cursor.moveToNext()) {
final CalendarInfo ci = new CalendarInfo();
- ci.id = cursor.getLong(0);
ci.name = cursor.getString(1);
ci.userId = context.getUserId();
outCalendars.add(ci);
@@ -198,15 +206,15 @@ public class ZenModeEventRuleSettings extends ZenModeRuleSettingsBase {
}
private static String key(CalendarInfo calendar) {
- return key(calendar.userId, calendar.id);
+ return key(calendar.userId, calendar.name);
}
private static String key(EventInfo event) {
return key(event.userId, event.calendar);
}
- private static String key(int userId, long calendarId) {
- return EventInfo.resolveUserId(userId) + ":" + calendarId;
+ private static String key(int userId, String calendar) {
+ return EventInfo.resolveUserId(userId) + ":" + (calendar == null ? "" : calendar);
}
private static final Comparator<CalendarInfo> CALENDAR_NAME = new Comparator<CalendarInfo>() {
@@ -217,7 +225,6 @@ public class ZenModeEventRuleSettings extends ZenModeRuleSettingsBase {
};
public static class CalendarInfo {
- public long id;
public String name;
public int userId;
}
diff --git a/src/com/android/settings/notification/ZenRuleNameDialog.java b/src/com/android/settings/notification/ZenRuleNameDialog.java
index 984241933..937940ac8 100644
--- a/src/com/android/settings/notification/ZenRuleNameDialog.java
+++ b/src/com/android/settings/notification/ZenRuleNameDialog.java
@@ -165,7 +165,7 @@ public abstract class ZenRuleNameDialog {
private static RuleInfo defaultNewEvent() {
final EventInfo event = new EventInfo();
- event.calendar = EventInfo.ANY_CALENDAR;
+ event.calendar = null; // any calendar
event.reply = EventInfo.REPLY_ANY_EXCEPT_NO;
final RuleInfo rt = new RuleInfo();
rt.settingsAction = ZenModeEventRuleSettings.ACTION;