diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index 76b4c52ba..4db5646aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -33,6 +33,7 @@ import kotlinx.android.synthetic.main.item_attendee.view.* import org.joda.time.DateTime import java.util.* import java.util.regex.Pattern +import kotlin.collections.ArrayList class EventActivity : SimpleActivity() { private val LAT_LON_PATTERN = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)([,;])\\s*[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)\$" @@ -48,6 +49,7 @@ class EventActivity : SimpleActivity() { private val REPEAT_INTERVAL = "REPEAT_INTERVAL" private val REPEAT_LIMIT = "REPEAT_LIMIT" private val REPEAT_RULE = "REPEAT_RULE" + private val ATTENDEES = "ATTENDEES" private val EVENT_TYPE_ID = "EVENT_TYPE_ID" private val EVENT_CALENDAR_ID = "EVENT_CALENDAR_ID" @@ -236,6 +238,8 @@ class EventActivity : SimpleActivity() { putInt(REPEAT_RULE, mRepeatRule) putLong(REPEAT_LIMIT, mRepeatLimit) + putStringArrayList(ATTENDEES, getAllAttendees()) + putLong(EVENT_TYPE_ID, mEventTypeId) putInt(EVENT_CALENDAR_ID, mEventCalendarId) } @@ -265,6 +269,8 @@ class EventActivity : SimpleActivity() { mRepeatRule = getInt(REPEAT_RULE) mRepeatLimit = getLong(REPEAT_LIMIT) + mEvent.attendees = getStringArrayList(ATTENDEES) as ArrayList + mEventTypeId = getLong(EVENT_TYPE_ID) mEventCalendarId = getInt(EVENT_CALENDAR_ID) } @@ -877,7 +883,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 = mAttendeeViews.map { it.value }.filter { it.isNotEmpty() }.toMutableList() as ArrayList + attendees = getAllAttendees() eventType = newEventType lastUpdated = System.currentTimeMillis() source = newSource @@ -1094,23 +1100,39 @@ class EventActivity : SimpleActivity() { } private fun updateAttendees() { + mEvent.attendees.forEach { + addAttendee(it) + } addAttendee() - event_attendees_image.layoutParams.height = event_repetition_image.height + + val imageHeight = event_repetition_image.height + if (imageHeight > 0) { + event_attendees_image.layoutParams.height = imageHeight + } else { + event_repetition_image.onGlobalLayout { + event_attendees_image.layoutParams.height = event_repetition_image.height + } + } } - private fun addAttendee() { + private fun addAttendee(value: String? = null) { val attendeeHolder = layoutInflater.inflate(R.layout.item_attendee, event_attendees_holder, false) as RelativeLayout mAttendeeViews.add(attendeeHolder.event_attendee) attendeeHolder.event_attendee.onTextChangeListener { - if (mAttendeeViews.none { it.value.isEmpty() }) { + if (value == null && mAttendeeViews.none { it.value.isEmpty() }) { addAttendee() } } event_attendees_holder.addView(attendeeHolder) attendeeHolder.event_attendee.setColors(config.textColor, getAdjustedPrimaryColor(), config.backgroundColor) + if (value != null) { + attendeeHolder.event_attendee.setText(value) + } } + private fun getAllAttendees() = mAttendeeViews.map { it.value }.filter { it.isNotEmpty() }.toMutableList() as ArrayList + private fun updateIconColors() { val textColor = config.textColor event_time_image.applyColorFilter(textColor)