properly handle last used event type at Importing events

This commit is contained in:
tibbi 2018-05-02 10:47:02 +02:00
parent e6d49184a5
commit 47f5adf5f3
3 changed files with 31 additions and 9 deletions

View File

@ -155,8 +155,8 @@ class EventActivity : SimpleActivity() {
private fun setupNewEvent() {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
supportActionBar?.title = resources.getString(R.string.new_event)
val isLastCaldavCalendarOK = config.caldavSync && config.getSyncedCalendarIdsAsList().contains(config.lastUsedCaldavCalendar.toString())
mEventCalendarId = if (isLastCaldavCalendarOK) config.lastUsedCaldavCalendar else STORED_LOCALLY_ONLY
val isLastCaldavCalendarOK = config.caldavSync && config.getSyncedCalendarIdsAsList().contains(config.lastUsedCaldavCalendarId.toString())
mEventCalendarId = if (isLastCaldavCalendarOK) config.lastUsedCaldavCalendarId else STORED_LOCALLY_ONLY
if (intent.action == Intent.ACTION_EDIT || intent.action == Intent.ACTION_INSERT) {
val startTS = (intent.getLongExtra("beginTime", System.currentTimeMillis()) / 1000).toInt()
@ -450,7 +450,7 @@ class EventActivity : SimpleActivity() {
updateEventType()
}
mEventCalendarId = it
config.lastUsedCaldavCalendar = it
config.lastUsedCaldavCalendarId = it
updateCurrentCalendarInfo(getCalendarWithId(calendars, it))
}
}
@ -459,7 +459,7 @@ class EventActivity : SimpleActivity() {
}
}
private fun getCalendarId() = if (mEvent.source == SOURCE_SIMPLE_CALENDAR) config.lastUsedCaldavCalendar else mEvent.getCalDAVCalendarId()
private fun getCalendarId() = if (mEvent.source == SOURCE_SIMPLE_CALENDAR) config.lastUsedCaldavCalendarId else mEvent.getCalDAVCalendarId()
private fun getCalendarWithId(calendars: List<CalDAVCalendar>, calendarId: Int): CalDAVCalendar? =
calendars.firstOrNull { it.id == calendarId }
@ -525,17 +525,17 @@ class EventActivity : SimpleActivity() {
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 || mEventCalendarId == STORED_LOCALLY_ONLY) {
val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendarId == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) {
mEventTypeId
} else {
dbHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendar)?.id ?: config.lastUsedLocalEventTypeId
dbHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendarId)?.id ?: config.lastUsedLocalEventTypeId
}
val newSource = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) {
val newSource = if (!config.caldavSync || config.lastUsedCaldavCalendarId == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) {
config.lastUsedLocalEventTypeId = newEventType
SOURCE_SIMPLE_CALENDAR
} else {
"$CALDAV-${config.lastUsedCaldavCalendar}"
"$CALDAV-${config.lastUsedCaldavCalendarId}"
}
val reminders = sortedSetOf(mReminder1Minutes, mReminder2Minutes, mReminder3Minutes).filter { it != REMINDER_OFF }

View File

@ -19,12 +19,34 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
var currEventTypeCalDAVCalendarId = 0
init {
val config = activity.config
if (activity.dbHelper.getEventType(config.lastUsedLocalEventTypeId) == null) {
config.lastUsedLocalEventTypeId = DBHelper.REGULAR_EVENT_TYPE_ID
}
val isLastCaldavCalendarOK = config.caldavSync && config.getSyncedCalendarIdsAsList().contains(config.lastUsedCaldavCalendarId.toString())
currEventTypeId = if (isLastCaldavCalendarOK) {
val lastUsedCalDAVCalendar = activity.dbHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendarId)
if (lastUsedCalDAVCalendar != null) {
currEventTypeCalDAVCalendarId = config.lastUsedCaldavCalendarId
lastUsedCalDAVCalendar.id
} else {
DBHelper.REGULAR_EVENT_TYPE_ID
}
} else {
config.lastUsedLocalEventTypeId
}
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_events, null) as ViewGroup).apply {
updateEventType(this)
import_event_type_holder.setOnClickListener {
SelectEventTypeDialog(activity, currEventTypeId, true) {
currEventTypeId = it.id
currEventTypeCalDAVCalendarId = it.caldavCalendarId
config.lastUsedLocalEventTypeId = it.id
config.lastUsedCaldavCalendarId = it.caldavCalendarId
updateEventType(this)
}
}

View File

@ -77,7 +77,7 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getString(CALDAV_SYNCED_CALENDAR_IDS, "")
set(calendarIDs) = prefs.edit().putString(CALDAV_SYNCED_CALENDAR_IDS, calendarIDs).apply()
var lastUsedCaldavCalendar: Int
var lastUsedCaldavCalendarId: Int
get() = prefs.getInt(LAST_USED_CALDAV_CALENDAR, getSyncedCalendarIdsAsList().first().toInt())
set(calendarId) = prefs.edit().putInt(LAST_USED_CALDAV_CALENDAR, calendarId).apply()