OSDN Git Service

b/2102011 Fix the problem where multi-day events may appear multiple times in the...
authorMichael Chan <mchan@android.com>
Tue, 8 Sep 2009 17:52:58 +0000 (10:52 -0700)
committerMichael Chan <mchan@android.com>
Wed, 9 Sep 2009 00:15:55 +0000 (17:15 -0700)
src/com/android/calendar/AgendaByDayAdapter.java
src/com/android/calendar/AgendaWindowAdapter.java

index 5349350..e7c74a2 100644 (file)
@@ -26,6 +26,8 @@ import android.view.ViewGroup;
 import android.widget.BaseAdapter;
 import android.widget.TextView;
 
+import com.android.calendar.AgendaWindowAdapter.DayAdapterInfo;
+
 import java.util.ArrayList;
 import java.util.Formatter;
 import java.util.Iterator;
@@ -168,12 +170,13 @@ public class AgendaByDayAdapter extends BaseAdapter {
         mRowInfo = null;
     }
 
-    public void changeCursor(Cursor cursor) {
-        calculateDays(cursor);
-        mAgendaAdapter.changeCursor(cursor);
+    public void changeCursor(DayAdapterInfo info) {
+        calculateDays(info);
+        mAgendaAdapter.changeCursor(info.cursor);
     }
 
-    public void calculateDays(Cursor cursor) {
+    public void calculateDays(DayAdapterInfo dayAdapterInfo) {
+        Cursor cursor = dayAdapterInfo.cursor;
         ArrayList<RowInfo> rowInfo = new ArrayList<RowInfo>();
         int prevStartDay = -1;
         Time time = new Time();
@@ -185,6 +188,9 @@ public class AgendaByDayAdapter extends BaseAdapter {
             boolean allDay = cursor.getInt(AgendaWindowAdapter.INDEX_ALL_DAY) != 0;
             int startDay = cursor.getInt(AgendaWindowAdapter.INDEX_START_DAY);
 
+            // Skip over the days outside of the adapter's range
+            startDay = Math.max(startDay, dayAdapterInfo.start);
+
             if (startDay != prevStartDay) {
                 // Check if we skipped over any empty days
                 if (prevStartDay == -1) {
@@ -231,6 +237,9 @@ public class AgendaByDayAdapter extends BaseAdapter {
             // If this event spans multiple days, then add it to the multipleDay
             // list.
             int endDay = cursor.getInt(AgendaWindowAdapter.INDEX_END_DAY);
+
+            // Skip over the days outside of the adapter's range
+            endDay = Math.min(endDay, dayAdapterInfo.end);
             if (endDay > startDay) {
                 multipleDayList.add(new MultipleDayInfo(position, endDay));
             }
@@ -239,16 +248,8 @@ public class AgendaByDayAdapter extends BaseAdapter {
         // There are no more cursor events but we might still have multiple-day
         // events left.  So create day headers and events for those.
         if (prevStartDay > 0) {
-            // Get the Julian day for the last day of this month.  To do that,
-            // we set the date to one less than the first day of the next month,
-            // and then normalize.
-            time.setJulianDay(prevStartDay);
-            time.month += 1;  // TODO remove month query reference
-            time.monthDay = 0;  // monthDay starts with 1, so this is the previous day
-            long millis = time.normalize(true /* ignore isDst */);
-            int lastDayOfMonth = Time.getJulianDay(millis, time.gmtoff);
-
-            for (int currentDay = prevStartDay + 1; currentDay <= lastDayOfMonth; currentDay++) {
+            for (int currentDay = prevStartDay + 1; currentDay <= dayAdapterInfo.end;
+                    currentDay++) {
                 boolean dayHeaderAdded = false;
                 Iterator<MultipleDayInfo> iter = multipleDayList.iterator();
                 while (iter.hasNext()) {
index cee686b..cc915c2 100644 (file)
@@ -228,7 +228,7 @@ public class AgendaWindowAdapter extends BaseAdapter {
         long id;
     }
 
-    private static class DayAdapterInfo {
+    static class DayAdapterInfo {
         Cursor cursor;
 
         AgendaByDayAdapter dayAdapter;
@@ -816,7 +816,7 @@ public class AgendaWindowAdapter extends BaseAdapter {
                 info.start = data.start;
                 info.end = data.end;
                 info.cursor = cursor;
-                info.dayAdapter.changeCursor(cursor);
+                info.dayAdapter.changeCursor(info);
                 info.size = info.dayAdapter.getCount();
 
                 // Insert into adapterInfos