From a13e8f114749af1da14b0666bfc334bc24b1cad3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 8 Oct 2017 17:52:46 +0200 Subject: [PATCH] fix a glitch with wrong calendar source at creating new events --- .../calendar/activities/EventActivity.kt | 15 ++++++++++++--- .../calendar/extensions/Context.kt | 1 - .../calendar/helpers/MonthlyCalendarImpl.kt | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index 6378d678a..2a3e4d92f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -399,7 +399,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { val calendars = CalDAVHandler(applicationContext).getCalDAVCalendars().filter { it.canWrite() && config.getSyncedCalendarIdsAsList().contains(it.id.toString()) } - updateCurrentCalendarInfo(getCalendarWithId(calendars, getCalendarId())) + updateCurrentCalendarInfo(if (mEventCalendarId == STORED_LOCALLY_ONLY) null else getCalendarWithId(calendars, getCalendarId())) event_caldav_calendar_holder.setOnClickListener { hideKeyboard() @@ -503,8 +503,17 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { val oldSource = mEvent.source val newImportId = if (mEvent.id != 0) mEvent.importId else UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString() - val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0) mEventTypeId else dbHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendar)!!.id - val newSource = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0) SOURCE_SIMPLE_CALENDAR else "$CALDAV-${config.lastUsedCaldavCalendar}" + val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) { + mEventTypeId + } else { + dbHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendar)!!.id + } + + val newSource = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) { + SOURCE_SIMPLE_CALENDAR + } else { + "$CALDAV-${config.lastUsedCaldavCalendar}" + } val reminders = sortedSetOf(mReminder1Minutes, mReminder2Minutes, mReminder3Minutes).filter { it != REMINDER_OFF } val newDescription = event_description.value diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index c22f2a341..d8e948f93 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -318,7 +318,6 @@ fun Context.addDayEvents(day: DayMonthly, linearLayout: LinearLayout, res: Resou (View.inflate(this, R.layout.day_monthly_item_view, null) as TextView).apply { setTextColor(textColor) text = it.title.replace(" ", "\u00A0") // allow word break by char - gravity = Gravity.START background = backgroundDrawable layoutParams = eventLayoutParams linearLayout.addView(this) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt index b692bb5ec..009da3079 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt @@ -19,7 +19,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context) private val mToday: String = DateTime().toString(Formatter.DAYCODE_PATTERN) private var mEvents = ArrayList() private var days = ArrayList(DAYS_CNT) - var mFilterEventTypes = true + private var mFilterEventTypes = true lateinit var mTargetDate: DateTime