mirror of
				https://github.com/SimpleMobileTools/Simple-Calendar.git
				synced 2025-06-05 21:59:17 +02:00 
			
		
		
		
	make more use of Attendees model class
This commit is contained in:
		| @@ -12,15 +12,14 @@ import android.view.WindowManager | ||||
| import android.widget.ImageView | ||||
| import android.widget.RelativeLayout | ||||
| import androidx.core.app.NotificationManagerCompat | ||||
| import com.google.gson.Gson | ||||
| import com.google.gson.reflect.TypeToken | ||||
| import com.simplemobiletools.calendar.pro.R | ||||
| import com.simplemobiletools.calendar.pro.dialogs.* | ||||
| import com.simplemobiletools.calendar.pro.extensions.* | ||||
| import com.simplemobiletools.calendar.pro.helpers.* | ||||
| import com.simplemobiletools.calendar.pro.helpers.Formatter | ||||
| import com.simplemobiletools.calendar.pro.models.CalDAVCalendar | ||||
| import com.simplemobiletools.calendar.pro.models.Event | ||||
| import com.simplemobiletools.calendar.pro.models.EventType | ||||
| import com.simplemobiletools.calendar.pro.models.Reminder | ||||
| import com.simplemobiletools.calendar.pro.models.* | ||||
| import com.simplemobiletools.commons.dialogs.ConfirmationDialog | ||||
| import com.simplemobiletools.commons.dialogs.RadioGroupDialog | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| @@ -67,6 +66,7 @@ class EventActivity : SimpleActivity() { | ||||
|     private var mEventOccurrenceTS = 0L | ||||
|     private var mEventCalendarId = STORED_LOCALLY_ONLY | ||||
|     private var mWasActivityInitialized = false | ||||
|     private var mAttendees = ArrayList<Attendee>() | ||||
|     private var mAttendeeViews = ArrayList<MyEditText>() | ||||
|  | ||||
|     private lateinit var mEventStartDateTime: DateTime | ||||
| @@ -238,7 +238,7 @@ class EventActivity : SimpleActivity() { | ||||
|             putInt(REPEAT_RULE, mRepeatRule) | ||||
|             putLong(REPEAT_LIMIT, mRepeatLimit) | ||||
|  | ||||
|             putStringArrayList(ATTENDEES, getAllAttendees()) | ||||
|             putString(ATTENDEES, getAllAttendees()) | ||||
|  | ||||
|             putLong(EVENT_TYPE_ID, mEventTypeId) | ||||
|             putInt(EVENT_CALENDAR_ID, mEventCalendarId) | ||||
| @@ -269,7 +269,8 @@ class EventActivity : SimpleActivity() { | ||||
|             mRepeatRule = getInt(REPEAT_RULE) | ||||
|             mRepeatLimit = getLong(REPEAT_LIMIT) | ||||
|  | ||||
|             mEvent.attendees = getStringArrayList(ATTENDEES) as ArrayList<String> | ||||
|             mAttendees = Gson().fromJson<ArrayList<Attendee>>(getString(ATTENDEES), object : TypeToken<List<Attendee>>() {}.type) | ||||
|                     ?: ArrayList() | ||||
|  | ||||
|             mEventTypeId = getLong(EVENT_TYPE_ID) | ||||
|             mEventCalendarId = getInt(EVENT_CALENDAR_ID) | ||||
| @@ -313,6 +314,7 @@ class EventActivity : SimpleActivity() { | ||||
|         mRepeatRule = mEvent.repeatRule | ||||
|         mEventTypeId = mEvent.eventType | ||||
|         mEventCalendarId = mEvent.getCalDAVCalendarId() | ||||
|         mAttendees = Gson().fromJson<ArrayList<Attendee>>(mEvent.attendees, object : TypeToken<List<Attendee>>() {}.type) ?: ArrayList() | ||||
|         checkRepeatTexts(mRepeatInterval) | ||||
|     } | ||||
|  | ||||
| @@ -892,7 +894,7 @@ class EventActivity : SimpleActivity() { | ||||
|             flags = mEvent.flags.addBitIf(event_all_day.isChecked, FLAG_ALL_DAY) | ||||
|             repeatLimit = if (repeatInterval == 0) 0 else mRepeatLimit | ||||
|             repeatRule = mRepeatRule | ||||
|             attendees = if (mEventCalendarId == STORED_LOCALLY_ONLY) ArrayList() else getAllAttendees() | ||||
|             attendees = if (mEventCalendarId == STORED_LOCALLY_ONLY) "" else getAllAttendees() | ||||
|             eventType = newEventType | ||||
|             lastUpdated = System.currentTimeMillis() | ||||
|             source = newSource | ||||
| @@ -1109,8 +1111,8 @@ class EventActivity : SimpleActivity() { | ||||
|     } | ||||
|  | ||||
|     private fun updateAttendees() { | ||||
|         mEvent.attendees.forEach { | ||||
|             addAttendee(it) | ||||
|         mAttendees.forEach { | ||||
|             addAttendee(it.getPublicName()) | ||||
|         } | ||||
|         addAttendee() | ||||
|  | ||||
| @@ -1140,7 +1142,14 @@ class EventActivity : SimpleActivity() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun getAllAttendees() = mAttendeeViews.map { it.value }.filter { it.isNotEmpty() }.toMutableList() as ArrayList<String> | ||||
|     private fun getAllAttendees(): String { | ||||
|         val attendeeEmails = mAttendeeViews.map { it.value }.filter { it.isNotEmpty() }.toMutableList() as ArrayList<String> | ||||
|         val attendees = ArrayList<Attendee>() | ||||
|         attendeeEmails.mapTo(attendees) { | ||||
|             Attendee("", it, 0) | ||||
|         } | ||||
|         return Gson().toJson(attendees) | ||||
|     } | ||||
|  | ||||
|     private fun updateIconColors() { | ||||
|         val textColor = config.textColor | ||||
|   | ||||
| @@ -67,7 +67,7 @@ abstract class EventsDatabase : RoomDatabase() { | ||||
|                     execSQL("ALTER TABLE events ADD COLUMN reminder_1_type INTEGER NOT NULL DEFAULT 0") | ||||
|                     execSQL("ALTER TABLE events ADD COLUMN reminder_2_type INTEGER NOT NULL DEFAULT 0") | ||||
|                     execSQL("ALTER TABLE events ADD COLUMN reminder_3_type INTEGER NOT NULL DEFAULT 0") | ||||
|                     execSQL("ALTER TABLE events ADD COLUMN attendees TEXT NOT NULL DEFAULT '[]'") | ||||
|                     execSQL("ALTER TABLE events ADD COLUMN attendees TEXT NOT NULL DEFAULT ''") | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -8,6 +8,7 @@ import android.database.Cursor | ||||
| import android.provider.CalendarContract | ||||
| import android.provider.CalendarContract.Reminders | ||||
| import android.util.SparseIntArray | ||||
| import com.google.gson.Gson | ||||
| import com.simplemobiletools.calendar.pro.R | ||||
| import com.simplemobiletools.calendar.pro.extensions.* | ||||
| import com.simplemobiletools.calendar.pro.models.* | ||||
| @@ -203,6 +204,7 @@ class CalDAVHelper(val context: Context) { | ||||
|                     val originalId = cursor.getStringValue(CalendarContract.Events.ORIGINAL_ID) | ||||
|                     val originalInstanceTime = cursor.getLongValue(CalendarContract.Events.ORIGINAL_INSTANCE_TIME) | ||||
|                     val reminders = getCalDAVEventReminders(id) | ||||
|                     val attendees = Gson().toJson(getCalDAVEventAttendees(id)) | ||||
|  | ||||
|                     if (endTS == 0L) { | ||||
|                         val duration = cursor.getStringValue(CalendarContract.Events.DURATION) ?: "" | ||||
| @@ -219,7 +221,7 @@ class CalDAVHelper(val context: Context) { | ||||
|                             reminder2?.minutes ?: REMINDER_OFF, reminder3?.minutes ?: REMINDER_OFF, reminder1?.type | ||||
|                             ?: REMINDER_NOTIFICATION, reminder2?.type ?: REMINDER_NOTIFICATION, reminder3?.type | ||||
|                             ?: REMINDER_NOTIFICATION, repeatRule.repeatInterval, repeatRule.repeatRule, | ||||
|                             repeatRule.repeatLimit, ArrayList(), ArrayList(), importId, allDay, eventTypeId, source = source) | ||||
|                             repeatRule.repeatLimit, ArrayList(), attendees, importId, allDay, eventTypeId, source = source) | ||||
|  | ||||
|                     if (event.getIsAllDay()) { | ||||
|                         event.startTS = Formatter.getShiftedImportTimestamp(event.startTS) | ||||
|   | ||||
| @@ -166,7 +166,7 @@ class IcsImporter(val activity: SimpleActivity) { | ||||
|                         val source = if (calDAVCalendarId == 0 || eventType?.isSyncedEventType() == false) SOURCE_IMPORTED_ICS else "$CALDAV-$calDAVCalendarId" | ||||
|                         val event = Event(null, curStart, curEnd, curTitle, curLocation, curDescription, reminders[0].minutes, | ||||
|                                 reminders[1].minutes, reminders[2].minutes, reminders[0].type, reminders[1].type, reminders[2].type, curRepeatInterval, curRepeatRule, | ||||
|                                 curRepeatLimit, curRepeatExceptions, ArrayList(), curImportId, curFlags, curEventTypeId, 0, curLastModified, source) | ||||
|                                 curRepeatLimit, curRepeatExceptions, "", curImportId, curFlags, curEventTypeId, 0, curLastModified, source) | ||||
|  | ||||
|                         if (event.getIsAllDay() && curEnd > curStart) { | ||||
|                             event.endTS -= DAY | ||||
|   | ||||
| @@ -29,7 +29,7 @@ data class Event( | ||||
|         @ColumnInfo(name = "repeat_rule") var repeatRule: Int = 0, | ||||
|         @ColumnInfo(name = "repeat_limit") var repeatLimit: Long = 0L, | ||||
|         @ColumnInfo(name = "repetition_exceptions") var repetitionExceptions: ArrayList<String> = ArrayList(), | ||||
|         @ColumnInfo(name = "attendees") var attendees: ArrayList<String> = ArrayList(), | ||||
|         @ColumnInfo(name = "attendees") var attendees: String = "", | ||||
|         @ColumnInfo(name = "import_id") var importId: String = "", | ||||
|         @ColumnInfo(name = "flags") var flags: Int = 0, | ||||
|         @ColumnInfo(name = "event_type") var eventType: Long = REGULAR_EVENT_TYPE_ID, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user