OSDN Git Service

Settings: Migrate zen event conditions to use calendar name.
authorJohn Spurlock <jspurlock@google.com>
Fri, 29 May 2015 02:20:44 +0000 (22:20 -0400)
committerJohn Spurlock <jspurlock@google.com>
Fri, 29 May 2015 02:20:44 +0000 (22:20 -0400)
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

src/com/android/settings/notification/ZenModeAutomationSettings.java
src/com/android/settings/notification/ZenModeEventRuleSettings.java
src/com/android/settings/notification/ZenRuleNameDialog.java

index 1cfa22a..1cf3fe9 100644 (file)
@@ -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) {
index c67ab4c..004d5df 100644 (file)
@@ -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;
     }
index 9842419..937940a 100644 (file)
@@ -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;