CalendarEventModel.java revision 28dab653f55caccbed32f700274f5274abaee089
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17package com.android.calendar; 18 19import com.android.calendar.event.EditEventHelper; 20import com.android.common.Rfc822Validator; 21 22import android.content.Context; 23import android.content.Intent; 24import android.content.SharedPreferences; 25import android.provider.CalendarContract.Attendees; 26import android.provider.CalendarContract.Calendars; 27import android.provider.CalendarContract.Events; 28import android.provider.CalendarContract.Reminders; 29import android.text.TextUtils; 30import android.text.util.Rfc822Token; 31import android.widget.AutoCompleteTextView; 32 33import java.io.Serializable; 34import java.util.ArrayList; 35import java.util.Collections; 36import java.util.LinkedHashMap; 37import java.util.LinkedHashSet; 38import java.util.TimeZone; 39 40/** 41 * Stores all the information needed to fill out an entry in the events table. 42 * This is a convenient way for storing information needed by the UI to write to 43 * the events table. Only fields that are important to the UI are included. 44 */ 45public class CalendarEventModel implements Serializable { 46 private static final String TAG = "CalendarEventModel"; 47 48 public static class Attendee implements Serializable { 49 @Override 50 public int hashCode() { 51 return (mEmail == null) ? 0 : mEmail.hashCode(); 52 } 53 54 @Override 55 public boolean equals(Object obj) { 56 if (this == obj) { 57 return true; 58 } 59 if (!(obj instanceof Attendee)) { 60 return false; 61 } 62 Attendee other = (Attendee) obj; 63 if (!TextUtils.equals(mEmail, other.mEmail)) { 64 return false; 65 } 66 return true; 67 } 68 69 String getDisplayName() { 70 if (TextUtils.isEmpty(mName)) { 71 return mEmail; 72 } else { 73 return mName; 74 } 75 } 76 77 public String mName; 78 public String mEmail; 79 public int mStatus; 80 81 public Attendee(String name, String email) { 82 mName = name; 83 mEmail = email; 84 mStatus = Attendees.ATTENDEE_STATUS_NONE; 85 } 86 public Attendee(String name, String email, int status) { 87 mName = name; 88 mEmail = email; 89 mStatus = status; 90 } 91 } 92 93 /** 94 * A single reminder entry. 95 * 96 * Instances of the class are immutable. 97 */ 98 public static class ReminderEntry implements Comparable<ReminderEntry>, Serializable { 99 private final int mMinutes; 100 private final int mMethod; 101 102 /** 103 * Returns a new ReminderEntry, with the specified minutes and method. 104 * 105 * @param minutes Number of minutes before the start of the event that the alert will fire. 106 * @param method Type of alert ({@link Reminders#METHOD_ALERT}, etc). 107 */ 108 public static ReminderEntry valueOf(int minutes, int method) { 109 // TODO: cache common instances 110 return new ReminderEntry(minutes, method); 111 } 112 113 /** 114 * Returns a ReminderEntry, with the specified number of minutes and a default alert method. 115 * 116 * @param minutes Number of minutes before the start of the event that the alert will fire. 117 */ 118 public static ReminderEntry valueOf(int minutes) { 119 return valueOf(minutes, Reminders.METHOD_DEFAULT); 120 } 121 122 /** 123 * Constructs a new ReminderEntry. 124 * 125 * @param minutes Number of minutes before the start of the event that the alert will fire. 126 * @param method Type of alert ({@link Reminders#METHOD_ALERT}, etc). 127 */ 128 private ReminderEntry(int minutes, int method) { 129 // TODO: error-check args 130 mMinutes = minutes; 131 mMethod = method; 132 } 133 134 @Override 135 public int hashCode() { 136 return mMinutes * 10 + mMethod; 137 } 138 139 @Override 140 public boolean equals(Object obj) { 141 if (this == obj) { 142 return true; 143 } 144 if (!(obj instanceof ReminderEntry)) { 145 return false; 146 } 147 148 ReminderEntry re = (ReminderEntry) obj; 149 150 if (re.mMinutes != mMinutes) { 151 return false; 152 } 153 154 // Treat ALERT and DEFAULT as equivalent. This is useful during the "has anything 155 // "changed" test, so that if DEFAULT is present, but we don't change anything, 156 // the internal conversion of DEFAULT to ALERT doesn't force a database update. 157 return re.mMethod == mMethod || 158 (re.mMethod == Reminders.METHOD_DEFAULT && mMethod == Reminders.METHOD_ALERT) || 159 (re.mMethod == Reminders.METHOD_ALERT && mMethod == Reminders.METHOD_DEFAULT); 160 } 161 162 @Override 163 public String toString() { 164 return "ReminderEntry min=" + mMinutes + " meth=" + mMethod; 165 } 166 167 /** 168 * Comparison function for a sort ordered primarily descending by minutes, 169 * secondarily ascending by method type. 170 */ 171 public int compareTo(ReminderEntry re) { 172 if (re.mMinutes != mMinutes) { 173 return re.mMinutes - mMinutes; 174 } 175 if (re.mMethod != mMethod) { 176 return mMethod - re.mMethod; 177 } 178 return 0; 179 } 180 181 /** Returns the minutes. */ 182 public int getMinutes() { 183 return mMinutes; 184 } 185 186 /** Returns the alert method. */ 187 public int getMethod() { 188 return mMethod; 189 } 190 } 191 192 // TODO strip out fields that don't ever get used 193 /** 194 * The uri of the event in the db. This should only be null for new events. 195 */ 196 public String mUri = null; 197 public long mId = -1; 198 public long mCalendarId = -1; 199 public String mCalendarDisplayName = ""; // Make sure this is in sync with the mCalendarId 200 public int mCalendarColor = 0; 201 public int mCalendarMaxReminders; 202 public String mCalendarAllowedReminders; 203 204 public String mSyncId = null; 205 public String mSyncAccount = null; 206 public String mSyncAccountType = null; 207 208 // PROVIDER_NOTES owner account comes from the calendars table 209 public String mOwnerAccount = null; 210 public String mTitle = null; 211 public String mLocation = null; 212 public String mDescription = null; 213 public String mRrule = null; 214 public String mOrganizer = null; 215 public String mOrganizerDisplayName = null; 216 /** 217 * Read-Only - Derived from other fields 218 */ 219 public boolean mIsOrganizer = true; 220 public boolean mIsFirstEventInSeries = true; 221 222 // This should be set the same as mStart when created and is used for making changes to 223 // recurring events. It should not be updated after it is initially set. 224 public long mOriginalStart = -1; 225 public long mStart = -1; 226 227 // This should be set the same as mEnd when created and is used for making changes to 228 // recurring events. It should not be updated after it is initially set. 229 public long mOriginalEnd = -1; 230 public long mEnd = -1; 231 public String mDuration = null; 232 public String mTimezone = null; 233 public String mTimezone2 = null; 234 public boolean mAllDay = false; 235 public boolean mHasAlarm = false; 236 public boolean mAvailability = false; 237 238 // PROVIDER_NOTES How does an event not have attendee data? The owner is added 239 // as an attendee by default. 240 public boolean mHasAttendeeData = true; 241 public int mSelfAttendeeStatus = -1; 242 public int mOwnerAttendeeId = -1; 243 public String mOriginalSyncId = null; 244 public long mOriginalId = -1; 245 public Long mOriginalTime = null; 246 public Boolean mOriginalAllDay = null; 247 public boolean mGuestsCanModify = false; 248 public boolean mGuestsCanInviteOthers = false; 249 public boolean mGuestsCanSeeGuests = false; 250 251 public boolean mOrganizerCanRespond = false; 252 public int mCalendarAccessLevel = Calendars.CAL_ACCESS_CONTRIBUTOR; 253 254 // The model can't be updated with a calendar cursor until it has been 255 // updated with an event cursor. 256 public boolean mModelUpdatedWithEventCursor; 257 258 public int mAccessLevel = 0; 259 public ArrayList<ReminderEntry> mReminders; 260 public ArrayList<ReminderEntry> mDefaultReminders; 261 262 // PROVIDER_NOTES Using EditEventHelper the owner should not be included in this 263 // list and will instead be added by saveEvent. Is this what we want? 264 public LinkedHashMap<String, Attendee> mAttendeesList; 265 266 public CalendarEventModel() { 267 mReminders = new ArrayList<ReminderEntry>(); 268 mDefaultReminders = new ArrayList<ReminderEntry>(); 269 mAttendeesList = new LinkedHashMap<String, Attendee>(); 270 mTimezone = TimeZone.getDefault().getID(); 271 } 272 273 public CalendarEventModel(Context context) { 274 this(); 275 276 mTimezone = Utils.getTimeZone(context, null); 277 SharedPreferences prefs = GeneralPreferences.getSharedPreferences(context); 278 279 String defaultReminder = prefs.getString( 280 GeneralPreferences.KEY_DEFAULT_REMINDER, GeneralPreferences.NO_REMINDER_STRING); 281 int defaultReminderMins = Integer.parseInt(defaultReminder); 282 if (defaultReminderMins != GeneralPreferences.NO_REMINDER) { 283 // Assume all calendars allow at least one reminder. 284 mHasAlarm = true; 285 mReminders.add(ReminderEntry.valueOf(defaultReminderMins)); 286 mDefaultReminders.add(ReminderEntry.valueOf(defaultReminderMins)); 287 } 288 } 289 290 public CalendarEventModel(Context context, Intent intent) { 291 this(context); 292 293 if (intent == null) { 294 return; 295 } 296 297 String title = intent.getStringExtra(Events.TITLE); 298 if (title != null) { 299 mTitle = title; 300 } 301 302 String location = intent.getStringExtra(Events.EVENT_LOCATION); 303 if (location != null) { 304 mLocation = location; 305 } 306 307 String description = intent.getStringExtra(Events.DESCRIPTION); 308 if (description != null) { 309 mDescription = description; 310 } 311 312 int availability = intent.getIntExtra(Events.AVAILABILITY, -1); 313 if (availability != -1) { 314 mAvailability = availability != 0; 315 } 316 317 int accessLevel = intent.getIntExtra(Events.ACCESS_LEVEL, -1); 318 if (accessLevel != -1) { 319 mAccessLevel = accessLevel; 320 } 321 322 String rrule = intent.getStringExtra(Events.RRULE); 323 if (!TextUtils.isEmpty(rrule)) { 324 mRrule = rrule; 325 } 326 327 String emails = intent.getStringExtra(Intent.EXTRA_EMAIL); 328 if (!TextUtils.isEmpty(emails)) { 329 String[] emailArray = emails.split("[ ,;]"); 330 for (String email : emailArray) { 331 if (!TextUtils.isEmpty(email) && email.contains("@")) { 332 email = email.trim(); 333 if (!mAttendeesList.containsKey(email)) { 334 mAttendeesList.put(email, new Attendee("", email)); 335 } 336 } 337 } 338 } 339 } 340 341 public boolean isValid() { 342 if (mCalendarId == -1) { 343 return false; 344 } 345 if (TextUtils.isEmpty(mOwnerAccount)) { 346 return false; 347 } 348 return true; 349 } 350 351 private boolean isEmpty() { 352 if (mTitle != null && mTitle.length() > 0) { 353 return false; 354 } 355 356 if (mLocation != null && mLocation.length() > 0) { 357 return false; 358 } 359 360 if (mDescription != null && mDescription.length() > 0) { 361 return false; 362 } 363 364 return true; 365 } 366 367 public void clear() { 368 mUri = null; 369 mId = -1; 370 mCalendarId = -1; 371 372 mSyncId = null; 373 mSyncAccount = null; 374 mSyncAccountType = null; 375 mOwnerAccount = null; 376 377 mTitle = null; 378 mLocation = null; 379 mDescription = null; 380 mRrule = null; 381 mOrganizer = null; 382 mOrganizerDisplayName = null; 383 mIsOrganizer = true; 384 mIsFirstEventInSeries = true; 385 386 mOriginalStart = -1; 387 mStart = -1; 388 mOriginalEnd = -1; 389 mEnd = -1; 390 mDuration = null; 391 mTimezone = null; 392 mTimezone2 = null; 393 mAllDay = false; 394 mHasAlarm = false; 395 396 mHasAttendeeData = true; 397 mSelfAttendeeStatus = -1; 398 mOwnerAttendeeId = -1; 399 mOriginalId = -1; 400 mOriginalSyncId = null; 401 mOriginalTime = null; 402 mOriginalAllDay = null; 403 404 mGuestsCanModify = false; 405 mGuestsCanInviteOthers = false; 406 mGuestsCanSeeGuests = false; 407 mAccessLevel = 0; 408 mOrganizerCanRespond = false; 409 mCalendarAccessLevel = Calendars.CAL_ACCESS_CONTRIBUTOR; 410 mModelUpdatedWithEventCursor = false; 411 412 mReminders = new ArrayList<ReminderEntry>(); 413 mAttendeesList.clear(); 414 } 415 416 public void addAttendee(Attendee attendee) { 417 mAttendeesList.put(attendee.mEmail, attendee); 418 } 419 420 public void addAttendees(String attendees, Rfc822Validator validator) { 421 final LinkedHashSet<Rfc822Token> addresses = EditEventHelper.getAddressesFromList( 422 attendees, validator); 423 synchronized (this) { 424 for (final Rfc822Token address : addresses) { 425 final Attendee attendee = new Attendee(address.getName(), address.getAddress()); 426 if (TextUtils.isEmpty(attendee.mName)) { 427 attendee.mName = attendee.mEmail; 428 } 429 addAttendee(attendee); 430 } 431 } 432 } 433 434 public void removeAttendee(Attendee attendee) { 435 mAttendeesList.remove(attendee.mEmail); 436 } 437 438 public String getAttendeesString() { 439 StringBuilder b = new StringBuilder(); 440 for (Attendee attendee : mAttendeesList.values()) { 441 String name = attendee.mName; 442 String email = attendee.mEmail; 443 String status = Integer.toString(attendee.mStatus); 444 b.append("name:").append(name); 445 b.append(" email:").append(email); 446 b.append(" status:").append(status); 447 } 448 return b.toString(); 449 } 450 451 @Override 452 public int hashCode() { 453 final int prime = 31; 454 int result = 1; 455 result = prime * result + (mAllDay ? 1231 : 1237); 456 result = prime * result + ((mAttendeesList == null) ? 0 : getAttendeesString().hashCode()); 457 result = prime * result + (int) (mCalendarId ^ (mCalendarId >>> 32)); 458 result = prime * result + ((mDescription == null) ? 0 : mDescription.hashCode()); 459 result = prime * result + ((mDuration == null) ? 0 : mDuration.hashCode()); 460 result = prime * result + (int) (mEnd ^ (mEnd >>> 32)); 461 result = prime * result + (mGuestsCanInviteOthers ? 1231 : 1237); 462 result = prime * result + (mGuestsCanModify ? 1231 : 1237); 463 result = prime * result + (mGuestsCanSeeGuests ? 1231 : 1237); 464 result = prime * result + (mOrganizerCanRespond ? 1231 : 1237); 465 result = prime * result + (mModelUpdatedWithEventCursor ? 1231 : 1237); 466 result = prime * result + mCalendarAccessLevel; 467 result = prime * result + (mHasAlarm ? 1231 : 1237); 468 result = prime * result + (mHasAttendeeData ? 1231 : 1237); 469 result = prime * result + (int) (mId ^ (mId >>> 32)); 470 result = prime * result + (mIsFirstEventInSeries ? 1231 : 1237); 471 result = prime * result + (mIsOrganizer ? 1231 : 1237); 472 result = prime * result + ((mLocation == null) ? 0 : mLocation.hashCode()); 473 result = prime * result + ((mOrganizer == null) ? 0 : mOrganizer.hashCode()); 474 result = prime * result + ((mOriginalAllDay == null) ? 0 : mOriginalAllDay.hashCode()); 475 result = prime * result + (int) (mOriginalEnd ^ (mOriginalEnd >>> 32)); 476 result = prime * result + ((mOriginalSyncId == null) ? 0 : mOriginalSyncId.hashCode()); 477 result = prime * result + (int) (mOriginalId ^ (mOriginalEnd >>> 32)); 478 result = prime * result + (int) (mOriginalStart ^ (mOriginalStart >>> 32)); 479 result = prime * result + ((mOriginalTime == null) ? 0 : mOriginalTime.hashCode()); 480 result = prime * result + ((mOwnerAccount == null) ? 0 : mOwnerAccount.hashCode()); 481 result = prime * result + ((mReminders == null) ? 0 : mReminders.hashCode()); 482 result = prime * result + ((mRrule == null) ? 0 : mRrule.hashCode()); 483 result = prime * result + mSelfAttendeeStatus; 484 result = prime * result + mOwnerAttendeeId; 485 result = prime * result + (int) (mStart ^ (mStart >>> 32)); 486 result = prime * result + ((mSyncAccount == null) ? 0 : mSyncAccount.hashCode()); 487 result = prime * result + ((mSyncAccountType == null) ? 0 : mSyncAccountType.hashCode()); 488 result = prime * result + ((mSyncId == null) ? 0 : mSyncId.hashCode()); 489 result = prime * result + ((mTimezone == null) ? 0 : mTimezone.hashCode()); 490 result = prime * result + ((mTimezone2 == null) ? 0 : mTimezone2.hashCode()); 491 result = prime * result + ((mTitle == null) ? 0 : mTitle.hashCode()); 492 result = prime * result + (mAvailability ? 1231 : 1237); 493 result = prime * result + ((mUri == null) ? 0 : mUri.hashCode()); 494 result = prime * result + mAccessLevel; 495 return result; 496 } 497 498 // Autogenerated equals method 499 @Override 500 public boolean equals(Object obj) { 501 if (this == obj) { 502 return true; 503 } 504 if (obj == null) { 505 return false; 506 } 507 if (!(obj instanceof CalendarEventModel)) { 508 return false; 509 } 510 511 CalendarEventModel other = (CalendarEventModel) obj; 512 if (!checkOriginalModelFields(other)) { 513 return false; 514 } 515 516 if (mLocation == null) { 517 if (other.mLocation != null) { 518 return false; 519 } 520 } else if (!mLocation.equals(other.mLocation)) { 521 return false; 522 } 523 524 if (mTitle == null) { 525 if (other.mTitle != null) { 526 return false; 527 } 528 } else if (!mTitle.equals(other.mTitle)) { 529 return false; 530 } 531 532 if (mDescription == null) { 533 if (other.mDescription != null) { 534 return false; 535 } 536 } else if (!mDescription.equals(other.mDescription)) { 537 return false; 538 } 539 540 if (mDuration == null) { 541 if (other.mDuration != null) { 542 return false; 543 } 544 } else if (!mDuration.equals(other.mDuration)) { 545 return false; 546 } 547 548 if (mEnd != other.mEnd) { 549 return false; 550 } 551 if (mIsFirstEventInSeries != other.mIsFirstEventInSeries) { 552 return false; 553 } 554 if (mOriginalEnd != other.mOriginalEnd) { 555 return false; 556 } 557 558 if (mOriginalStart != other.mOriginalStart) { 559 return false; 560 } 561 if (mStart != other.mStart) { 562 return false; 563 } 564 565 if (mOriginalId != other.mOriginalId) { 566 return false; 567 } 568 569 if (mOriginalSyncId == null) { 570 if (other.mOriginalSyncId != null) { 571 return false; 572 } 573 } else if (!mOriginalSyncId.equals(other.mOriginalSyncId)) { 574 return false; 575 } 576 577 if (mRrule == null) { 578 if (other.mRrule != null) { 579 return false; 580 } 581 } else if (!mRrule.equals(other.mRrule)) { 582 return false; 583 } 584 return true; 585 } 586 587 /** 588 * Whether the event has been modified based on its original model. 589 * 590 * @param originalModel 591 * @return true if the model is unchanged, false otherwise 592 */ 593 public boolean isUnchanged(CalendarEventModel originalModel) { 594 if (this == originalModel) { 595 return true; 596 } 597 if (originalModel == null) { 598 return false; 599 } 600 601 if (!checkOriginalModelFields(originalModel)) { 602 return false; 603 } 604 605 if (TextUtils.isEmpty(mLocation)) { 606 if (!TextUtils.isEmpty(originalModel.mLocation)) { 607 return false; 608 } 609 } else if (!mLocation.equals(originalModel.mLocation)) { 610 return false; 611 } 612 613 if (TextUtils.isEmpty(mTitle)) { 614 if (!TextUtils.isEmpty(originalModel.mTitle)) { 615 return false; 616 } 617 } else if (!mTitle.equals(originalModel.mTitle)) { 618 return false; 619 } 620 621 if (TextUtils.isEmpty(mDescription)) { 622 if (!TextUtils.isEmpty(originalModel.mDescription)) { 623 return false; 624 } 625 } else if (!mDescription.equals(originalModel.mDescription)) { 626 return false; 627 } 628 629 if (TextUtils.isEmpty(mDuration)) { 630 if (!TextUtils.isEmpty(originalModel.mDuration)) { 631 return false; 632 } 633 } else if (!mDuration.equals(originalModel.mDuration)) { 634 return false; 635 } 636 637 if (mEnd != mOriginalEnd) { 638 return false; 639 } 640 if (mStart != mOriginalStart) { 641 return false; 642 } 643 644 // If this changed the original id and it's not just an exception to the 645 // original event 646 if (mOriginalId != originalModel.mOriginalId && mOriginalId != originalModel.mId) { 647 return false; 648 } 649 650 if (TextUtils.isEmpty(mRrule)) { 651 // if the rrule is no longer empty check if this is an exception 652 if (!TextUtils.isEmpty(originalModel.mRrule)) { 653 boolean syncIdNotReferenced = mOriginalSyncId == null 654 || !mOriginalSyncId.equals(originalModel.mSyncId); 655 boolean localIdNotReferenced = mOriginalId == -1 656 || !(mOriginalId == originalModel.mId); 657 if (syncIdNotReferenced && localIdNotReferenced) { 658 return false; 659 } 660 } 661 } else if (!mRrule.equals(originalModel.mRrule)) { 662 return false; 663 } 664 665 return true; 666 } 667 668 /** 669 * Checks against an original model for changes to an event. This covers all 670 * the fields that should remain consistent between an original event model 671 * and the new one if nothing in the event was modified. This is also the 672 * portion that overlaps with equality between two event models. 673 * 674 * @param originalModel 675 * @return true if these fields are unchanged, false otherwise 676 */ 677 protected boolean checkOriginalModelFields(CalendarEventModel originalModel) { 678 if (mAllDay != originalModel.mAllDay) { 679 return false; 680 } 681 if (mAttendeesList == null) { 682 if (originalModel.mAttendeesList != null) { 683 return false; 684 } 685 } else if (!mAttendeesList.equals(originalModel.mAttendeesList)) { 686 return false; 687 } 688 689 if (mCalendarId != originalModel.mCalendarId) { 690 return false; 691 } 692 693 if (mGuestsCanInviteOthers != originalModel.mGuestsCanInviteOthers) { 694 return false; 695 } 696 if (mGuestsCanModify != originalModel.mGuestsCanModify) { 697 return false; 698 } 699 if (mGuestsCanSeeGuests != originalModel.mGuestsCanSeeGuests) { 700 return false; 701 } 702 if (mOrganizerCanRespond != originalModel.mOrganizerCanRespond) { 703 return false; 704 } 705 if (mCalendarAccessLevel != originalModel.mCalendarAccessLevel) { 706 return false; 707 } 708 if (mModelUpdatedWithEventCursor != originalModel.mModelUpdatedWithEventCursor) { 709 return false; 710 } 711 if (mHasAlarm != originalModel.mHasAlarm) { 712 return false; 713 } 714 if (mHasAttendeeData != originalModel.mHasAttendeeData) { 715 return false; 716 } 717 if (mId != originalModel.mId) { 718 return false; 719 } 720 if (mIsOrganizer != originalModel.mIsOrganizer) { 721 return false; 722 } 723 724 if (mOrganizer == null) { 725 if (originalModel.mOrganizer != null) { 726 return false; 727 } 728 } else if (!mOrganizer.equals(originalModel.mOrganizer)) { 729 return false; 730 } 731 732 if (mOriginalAllDay == null) { 733 if (originalModel.mOriginalAllDay != null) { 734 return false; 735 } 736 } else if (!mOriginalAllDay.equals(originalModel.mOriginalAllDay)) { 737 return false; 738 } 739 740 if (mOriginalTime == null) { 741 if (originalModel.mOriginalTime != null) { 742 return false; 743 } 744 } else if (!mOriginalTime.equals(originalModel.mOriginalTime)) { 745 return false; 746 } 747 748 if (mOwnerAccount == null) { 749 if (originalModel.mOwnerAccount != null) { 750 return false; 751 } 752 } else if (!mOwnerAccount.equals(originalModel.mOwnerAccount)) { 753 return false; 754 } 755 756 if (mReminders == null) { 757 if (originalModel.mReminders != null) { 758 return false; 759 } 760 } else if (!mReminders.equals(originalModel.mReminders)) { 761 return false; 762 } 763 764 if (mSelfAttendeeStatus != originalModel.mSelfAttendeeStatus) { 765 return false; 766 } 767 if (mOwnerAttendeeId != originalModel.mOwnerAttendeeId) { 768 return false; 769 } 770 if (mSyncAccount == null) { 771 if (originalModel.mSyncAccount != null) { 772 return false; 773 } 774 } else if (!mSyncAccount.equals(originalModel.mSyncAccount)) { 775 return false; 776 } 777 778 if (mSyncAccountType == null) { 779 if (originalModel.mSyncAccountType != null) { 780 return false; 781 } 782 } else if (!mSyncAccountType.equals(originalModel.mSyncAccountType)) { 783 return false; 784 } 785 786 if (mSyncId == null) { 787 if (originalModel.mSyncId != null) { 788 return false; 789 } 790 } else if (!mSyncId.equals(originalModel.mSyncId)) { 791 return false; 792 } 793 794 if (mTimezone == null) { 795 if (originalModel.mTimezone != null) { 796 return false; 797 } 798 } else if (!mTimezone.equals(originalModel.mTimezone)) { 799 return false; 800 } 801 802 if (mTimezone2 == null) { 803 if (originalModel.mTimezone2 != null) { 804 return false; 805 } 806 } else if (!mTimezone2.equals(originalModel.mTimezone2)) { 807 return false; 808 } 809 810 if (mAvailability != originalModel.mAvailability) { 811 return false; 812 } 813 814 if (mUri == null) { 815 if (originalModel.mUri != null) { 816 return false; 817 } 818 } else if (!mUri.equals(originalModel.mUri)) { 819 return false; 820 } 821 822 if (mAccessLevel != originalModel.mAccessLevel) { 823 return false; 824 } 825 return true; 826 } 827 828 /** 829 * Sort and uniquify mReminderMinutes. 830 * 831 * @return true (for convenience of caller) 832 */ 833 public boolean normalizeReminders() { 834 if (mReminders.size() <= 1) { 835 return true; 836 } 837 838 // sort 839 Collections.sort(mReminders); 840 841 // remove duplicates 842 ReminderEntry prev = mReminders.get(mReminders.size()-1); 843 for (int i = mReminders.size()-2; i >= 0; --i) { 844 ReminderEntry cur = mReminders.get(i); 845 if (prev.equals(cur)) { 846 // match, remove later entry 847 mReminders.remove(i+1); 848 } 849 prev = cur; 850 } 851 852 return true; 853 } 854} 855