mirror of
https://github.com/FossifyOrg/Calendar.git
synced 2026-02-19 15:54:52 -05:00
fix: resolve proper CalDAV calendar ID when saving events (#1023)
* fix: resolve proper CalDAV calendar ID when saving events Refs: https://github.com/FossifyOrg/Calendar/issues/1019 * docs: update changelog * fix: properly reset last used calendar when switching to local calendars * refactor: break down code into smaller functions
This commit is contained in:
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Changed
|
||||
- Updated holiday data
|
||||
|
||||
### Fixed
|
||||
- Fixed last used default calendar preference for new events ([#1019])
|
||||
|
||||
## [1.10.0] - 2026-01-30
|
||||
### Added
|
||||
- Added support for custom fonts
|
||||
@@ -217,6 +220,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
[#889]: https://github.com/FossifyOrg/Calendar/issues/889
|
||||
[#917]: https://github.com/FossifyOrg/Calendar/issues/917
|
||||
[#1003]: https://github.com/FossifyOrg/Calendar/issues/1003
|
||||
[#1019]: https://github.com/FossifyOrg/Calendar/issues/1019
|
||||
|
||||
[Unreleased]: https://github.com/FossifyOrg/Calendar/compare/1.10.0...HEAD
|
||||
[1.10.0]: https://github.com/FossifyOrg/Calendar/compare/1.9.0...1.10.0
|
||||
|
||||
@@ -416,9 +416,19 @@ class EventActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
mCalendarId = if (config.defaultCalendarId == -1L) {
|
||||
config.lastUsedLocalCalendarId
|
||||
val lastCaldavId = config.lastUsedCaldavCalendarId
|
||||
val canUseLastCaldav = config.caldavSync
|
||||
&& lastCaldavId != STORED_LOCALLY_ONLY
|
||||
&& config.getSyncedCalendarIdsAsList().contains(lastCaldavId)
|
||||
if (canUseLastCaldav) {
|
||||
mStoredCalendars.firstOrNull { it.caldavCalendarId == lastCaldavId }?.id
|
||||
?: config.lastUsedLocalCalendarId
|
||||
} else {
|
||||
config.lastUsedLocalCalendarId
|
||||
}
|
||||
} else {
|
||||
config.defaultCalendarId
|
||||
mStoredCalendars.firstOrNull { it.id == config.defaultCalendarId }?.id
|
||||
?: config.lastUsedLocalCalendarId
|
||||
}
|
||||
|
||||
if (event != null) {
|
||||
@@ -760,7 +770,6 @@ class EventActivity : SimpleActivity() {
|
||||
|
||||
if (isSelectedCaldavOk) {
|
||||
mEventCalendarId = selectedCaldavId
|
||||
config.lastUsedCaldavCalendarId = selectedCaldavId
|
||||
} else {
|
||||
mEventCalendarId = STORED_LOCALLY_ONLY
|
||||
if (selectedCalendar == null || selectedCalendar.caldavCalendarId != 0) {
|
||||
@@ -1157,6 +1166,7 @@ class EventActivity : SimpleActivity() {
|
||||
if (calendar.caldavCalendarId == 0) {
|
||||
mEventCalendarId = STORED_LOCALLY_ONLY
|
||||
config.lastUsedLocalCalendarId = mCalendarId
|
||||
config.lastUsedCaldavCalendarId = STORED_LOCALLY_ONLY
|
||||
} else {
|
||||
mEventCalendarId = calendar.caldavCalendarId
|
||||
config.lastUsedCaldavCalendarId = calendar.caldavCalendarId
|
||||
@@ -1624,6 +1634,7 @@ class EventActivity : SimpleActivity() {
|
||||
config.lastUsedCaldavCalendarId = selectedCaldavId
|
||||
} else {
|
||||
config.lastUsedLocalCalendarId = mCalendarId
|
||||
config.lastUsedCaldavCalendarId = STORED_LOCALLY_ONLY
|
||||
}
|
||||
|
||||
val newCalendarId = mCalendarId
|
||||
|
||||
@@ -167,7 +167,7 @@ class TaskActivity : SimpleActivity() {
|
||||
storedCalendars.firstOrNull { it.id == config.lastUsedLocalCalendarId }
|
||||
runOnUiThread {
|
||||
if (!isDestroyed && !isFinishing) {
|
||||
gotTask(savedInstanceState, localCalendar, task)
|
||||
gotTask(savedInstanceState, storedCalendars, localCalendar, task)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -324,73 +324,25 @@ class TaskActivity : SimpleActivity() {
|
||||
updateActionBarTitle()
|
||||
}
|
||||
|
||||
private fun gotTask(savedInstanceState: Bundle?, localCalendar: CalendarEntity?, task: Event?) {
|
||||
if (localCalendar == null) {
|
||||
private fun gotTask(
|
||||
savedInstanceState: Bundle?,
|
||||
storedCalendars: ArrayList<CalendarEntity>,
|
||||
localCalendar: CalendarEntity?,
|
||||
task: Event?
|
||||
) {
|
||||
if (localCalendar == null || localCalendar.caldavCalendarId != 0) {
|
||||
config.lastUsedLocalCalendarId = LOCAL_CALENDAR_ID
|
||||
}
|
||||
|
||||
mCalendarId =
|
||||
if (config.defaultCalendarId == -1L) config.lastUsedLocalCalendarId else config.defaultCalendarId
|
||||
mCalendarId = resolveTaskCalendarId(storedCalendars)
|
||||
|
||||
if (task != null) {
|
||||
mTask = task
|
||||
mTaskOccurrenceTS = intent.getLongExtra(EVENT_OCCURRENCE_TS, 0L)
|
||||
mTaskCompleted = intent.getBooleanExtra(IS_TASK_COMPLETED, false)
|
||||
if (savedInstanceState == null) {
|
||||
setupEditTask()
|
||||
}
|
||||
|
||||
if (intent.getBooleanExtra(IS_DUPLICATE_INTENT, false)) {
|
||||
mTask.id = null
|
||||
binding.taskToolbar.title = getString(R.string.new_task)
|
||||
}
|
||||
setupExistingTask(task, savedInstanceState)
|
||||
} else {
|
||||
mTask = Event(null)
|
||||
config.apply {
|
||||
mReminder1Minutes =
|
||||
if (usePreviousEventReminders && lastEventReminderMinutes1 >= -1) lastEventReminderMinutes1 else defaultReminder1
|
||||
mReminder2Minutes =
|
||||
if (usePreviousEventReminders && lastEventReminderMinutes2 >= -1) lastEventReminderMinutes2 else defaultReminder2
|
||||
mReminder3Minutes =
|
||||
if (usePreviousEventReminders && lastEventReminderMinutes3 >= -1) lastEventReminderMinutes3 else defaultReminder3
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
setupNewTask()
|
||||
}
|
||||
}
|
||||
|
||||
binding.apply {
|
||||
taskAllDay.setOnCheckedChangeListener { _, isChecked -> toggleAllDay(isChecked) }
|
||||
taskAllDayHolder.setOnClickListener {
|
||||
taskAllDay.toggle()
|
||||
}
|
||||
|
||||
taskDate.setOnClickListener { setupDate() }
|
||||
taskTime.setOnClickListener { setupTime() }
|
||||
calendarHolder.setOnClickListener { showCalendarDialog() }
|
||||
taskRepetition.setOnClickListener { showRepeatIntervalDialog() }
|
||||
taskRepetitionRuleHolder.setOnClickListener { showRepetitionRuleDialog() }
|
||||
taskRepetitionLimitHolder.setOnClickListener { showRepetitionTypePicker() }
|
||||
|
||||
taskReminder1.setOnClickListener {
|
||||
handleNotificationAvailability {
|
||||
if (config.wasAlarmWarningShown) {
|
||||
showReminder1Dialog()
|
||||
} else {
|
||||
ReminderWarningDialog(this@TaskActivity) {
|
||||
config.wasAlarmWarningShown = true
|
||||
showReminder1Dialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taskReminder2.setOnClickListener { showReminder2Dialog() }
|
||||
taskReminder3.setOnClickListener { showReminder3Dialog() }
|
||||
taskColorHolder.setOnClickListener { showTaskColorDialog() }
|
||||
setupNewTask(savedInstanceState)
|
||||
}
|
||||
|
||||
setupTaskClickListeners()
|
||||
refreshMenuItems()
|
||||
setupMarkCompleteButton()
|
||||
|
||||
@@ -400,6 +352,78 @@ class TaskActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupExistingTask(task: Event, savedInstanceState: Bundle?) {
|
||||
mTask = task
|
||||
mTaskOccurrenceTS = intent.getLongExtra(EVENT_OCCURRENCE_TS, 0L)
|
||||
mTaskCompleted = intent.getBooleanExtra(IS_TASK_COMPLETED, false)
|
||||
if (savedInstanceState == null) {
|
||||
setupEditTask()
|
||||
}
|
||||
|
||||
if (intent.getBooleanExtra(IS_DUPLICATE_INTENT, false)) {
|
||||
mTask.id = null
|
||||
binding.taskToolbar.title = getString(R.string.new_task)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupNewTask(savedInstanceState: Bundle?) {
|
||||
mTask = Event(null)
|
||||
config.apply {
|
||||
mReminder1Minutes =
|
||||
if (usePreviousEventReminders && lastEventReminderMinutes1 >= -1) lastEventReminderMinutes1 else defaultReminder1
|
||||
mReminder2Minutes =
|
||||
if (usePreviousEventReminders && lastEventReminderMinutes2 >= -1) lastEventReminderMinutes2 else defaultReminder2
|
||||
mReminder3Minutes =
|
||||
if (usePreviousEventReminders && lastEventReminderMinutes3 >= -1) lastEventReminderMinutes3 else defaultReminder3
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) setupNewTask()
|
||||
}
|
||||
|
||||
private fun resolveTaskCalendarId(storedCalendars: ArrayList<CalendarEntity>): Long {
|
||||
return if (config.defaultCalendarId == -1L) {
|
||||
config.lastUsedLocalCalendarId
|
||||
} else {
|
||||
val defaultCalendar = storedCalendars.firstOrNull { it.id == config.defaultCalendarId }
|
||||
if (defaultCalendar?.caldavCalendarId == 0) {
|
||||
config.defaultCalendarId
|
||||
} else {
|
||||
config.lastUsedLocalCalendarId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupTaskClickListeners() = binding.apply {
|
||||
taskAllDay.setOnCheckedChangeListener { _, isChecked -> toggleAllDay(isChecked) }
|
||||
taskAllDayHolder.setOnClickListener {
|
||||
taskAllDay.toggle()
|
||||
}
|
||||
|
||||
taskDate.setOnClickListener { setupDate() }
|
||||
taskTime.setOnClickListener { setupTime() }
|
||||
calendarHolder.setOnClickListener { showCalendarDialog() }
|
||||
taskRepetition.setOnClickListener { showRepeatIntervalDialog() }
|
||||
taskRepetitionRuleHolder.setOnClickListener { showRepetitionRuleDialog() }
|
||||
taskRepetitionLimitHolder.setOnClickListener { showRepetitionTypePicker() }
|
||||
|
||||
taskReminder1.setOnClickListener {
|
||||
handleNotificationAvailability {
|
||||
if (config.wasAlarmWarningShown) {
|
||||
showReminder1Dialog()
|
||||
} else {
|
||||
ReminderWarningDialog(this@TaskActivity) {
|
||||
config.wasAlarmWarningShown = true
|
||||
showReminder1Dialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taskReminder2.setOnClickListener { showReminder2Dialog() }
|
||||
taskReminder3.setOnClickListener { showReminder3Dialog() }
|
||||
taskColorHolder.setOnClickListener { showTaskColorDialog() }
|
||||
}
|
||||
|
||||
private fun setupEditTask() {
|
||||
mIsNewTask = false
|
||||
val realStart = if (mTaskOccurrenceTS == 0L) mTask.startTS else mTaskOccurrenceTS
|
||||
|
||||
Reference in New Issue
Block a user