mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Checks if any changes were made, before closing
This commit is contained in:
@ -246,18 +246,65 @@ class EventActivity : SimpleActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getStartEndTimes(): Pair<Long, Long> {
|
||||||
|
val offset = if (!config.allowChangingTimeZones || mEvent.getTimeZoneString().equals(mOriginalTimeZone, true)) {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
val original = if (mOriginalTimeZone.isEmpty()) DateTimeZone.getDefault().id else mOriginalTimeZone
|
||||||
|
(DateTimeZone.forID(mEvent.getTimeZoneString()).getOffset(System.currentTimeMillis()) - DateTimeZone.forID(original).getOffset(System.currentTimeMillis())) / 1000L
|
||||||
|
}
|
||||||
|
|
||||||
|
val newStartTS = mEventStartDateTime.withSecondOfMinute(0).withMillisOfSecond(0).seconds() - offset
|
||||||
|
val newEndTS = mEventEndDateTime.withSecondOfMinute(0).withMillisOfSecond(0).seconds() - offset
|
||||||
|
return Pair(newStartTS, newEndTS)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getReminders(): ArrayList<Reminder> {
|
||||||
|
var reminders = arrayListOf(
|
||||||
|
Reminder(mReminder1Minutes, mReminder1Type),
|
||||||
|
Reminder(mReminder2Minutes, mReminder2Type),
|
||||||
|
Reminder(mReminder3Minutes, mReminder3Type)
|
||||||
|
)
|
||||||
|
reminders = reminders.filter { it.minutes != REMINDER_OFF }.sortedBy { it.minutes }.toMutableList() as ArrayList<Reminder>
|
||||||
|
return reminders
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isEventChanged(): Boolean {
|
||||||
|
var newStartTS = 0L
|
||||||
|
var newEndTS = 0L
|
||||||
|
getStartEndTimes().apply {
|
||||||
|
newStartTS = first
|
||||||
|
newEndTS = second
|
||||||
|
}
|
||||||
|
|
||||||
|
val reminders = getReminders()
|
||||||
|
if (event_title.value != mEvent.title ||
|
||||||
|
event_location.value != mEvent.location ||
|
||||||
|
event_description.value != mEvent.location ||
|
||||||
|
newStartTS != mEvent.startTS ||
|
||||||
|
newEndTS != mEvent.endTS ||
|
||||||
|
event_time_zone.text != mEvent.getTimeZoneString() ||
|
||||||
|
reminders != mEvent.getReminders() ||
|
||||||
|
mRepeatInterval != mEvent.repeatInterval ||
|
||||||
|
mRepeatRule != mEvent.repeatRule ||
|
||||||
|
mEventTypeId != mEvent.eventType) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
if (isEventChanged()) {
|
||||||
CloseEditingDialog(this) {
|
CloseEditingDialog(this) {
|
||||||
ensureBackgroundThread {
|
|
||||||
when (it) {
|
when (it) {
|
||||||
CLOSE_WITHOUT_SAVING -> {
|
CLOSE_WITHOUT_SAVING -> {
|
||||||
runOnUiThread {
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
SAVE_AND_CLOSE -> saveCurrentEvent()
|
||||||
SAVE_AND_CLOSE -> saveEvent()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
super.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +433,8 @@ class EventActivity : SimpleActivity() {
|
|||||||
mRepeatRule = mEvent.repeatRule
|
mRepeatRule = mEvent.repeatRule
|
||||||
mEventTypeId = mEvent.eventType
|
mEventTypeId = mEvent.eventType
|
||||||
mEventCalendarId = mEvent.getCalDAVCalendarId()
|
mEventCalendarId = mEvent.getCalDAVCalendarId()
|
||||||
mAttendees = Gson().fromJson<ArrayList<Attendee>>(mEvent.attendees, object : TypeToken<List<Attendee>>() {}.type) ?: ArrayList()
|
mAttendees = Gson().fromJson<ArrayList<Attendee>>(mEvent.attendees, object : TypeToken<List<Attendee>>() {}.type)
|
||||||
|
?: ArrayList()
|
||||||
checkRepeatTexts(mRepeatInterval)
|
checkRepeatTexts(mRepeatInterval)
|
||||||
checkAttendees()
|
checkAttendees()
|
||||||
}
|
}
|
||||||
@ -396,7 +444,8 @@ class EventActivity : SimpleActivity() {
|
|||||||
event_title.requestFocus()
|
event_title.requestFocus()
|
||||||
updateActionBarTitle(getString(R.string.new_event))
|
updateActionBarTitle(getString(R.string.new_event))
|
||||||
if (config.defaultEventTypeId != -1L) {
|
if (config.defaultEventTypeId != -1L) {
|
||||||
config.lastUsedCaldavCalendarId = mStoredEventTypes.firstOrNull { it.id == config.defaultEventTypeId }?.caldavCalendarId ?: 0
|
config.lastUsedCaldavCalendarId = mStoredEventTypes.firstOrNull { it.id == config.defaultEventTypeId }?.caldavCalendarId
|
||||||
|
?: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
val isLastCaldavCalendarOK = config.caldavSync && config.getSyncedCalendarIdsAsList().contains(config.lastUsedCaldavCalendarId)
|
val isLastCaldavCalendarOK = config.caldavSync && config.getSyncedCalendarIdsAsList().contains(config.lastUsedCaldavCalendarId)
|
||||||
@ -850,7 +899,8 @@ class EventActivity : SimpleActivity() {
|
|||||||
event_caldav_calendar_email.text = currentCalendar.accountName
|
event_caldav_calendar_email.text = currentCalendar.accountName
|
||||||
|
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val calendarColor = eventsHelper.getEventTypeWithCalDAVCalendarId(currentCalendar.id)?.color ?: currentCalendar.color
|
val calendarColor = eventsHelper.getEventTypeWithCalDAVCalendarId(currentCalendar.id)?.color
|
||||||
|
?: currentCalendar.color
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
event_caldav_calendar_color.setFillWithStroke(calendarColor, config.backgroundColor)
|
event_caldav_calendar_color.setFillWithStroke(calendarColor, config.backgroundColor)
|
||||||
@ -935,16 +985,13 @@ class EventActivity : SimpleActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val offset = if (!config.allowChangingTimeZones || mEvent.getTimeZoneString().equals(mOriginalTimeZone, true)) {
|
var newStartTS = 0L
|
||||||
0
|
var newEndTS = 0L
|
||||||
} else {
|
getStartEndTimes().apply {
|
||||||
val original = if (mOriginalTimeZone.isEmpty()) DateTimeZone.getDefault().id else mOriginalTimeZone
|
newStartTS = first
|
||||||
(DateTimeZone.forID(mEvent.getTimeZoneString()).getOffset(System.currentTimeMillis()) - DateTimeZone.forID(original).getOffset(System.currentTimeMillis())) / 1000L
|
newEndTS = second
|
||||||
}
|
}
|
||||||
|
|
||||||
val newStartTS = mEventStartDateTime.withSecondOfMinute(0).withMillisOfSecond(0).seconds() - offset
|
|
||||||
val newEndTS = mEventEndDateTime.withSecondOfMinute(0).withMillisOfSecond(0).seconds() - offset
|
|
||||||
|
|
||||||
if (newStartTS > newEndTS) {
|
if (newStartTS > newEndTS) {
|
||||||
toast(R.string.end_before_start)
|
toast(R.string.end_before_start)
|
||||||
return
|
return
|
||||||
@ -966,7 +1013,8 @@ class EventActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eventsHelper.getEventTypeWithCalDAVCalendarId(mEventCalendarId)?.id ?: config.lastUsedLocalEventTypeId
|
eventsHelper.getEventTypeWithCalDAVCalendarId(mEventCalendarId)?.id
|
||||||
|
?: config.lastUsedLocalEventTypeId
|
||||||
}
|
}
|
||||||
|
|
||||||
val newSource = if (!config.caldavSync || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
val newSource = if (!config.caldavSync || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
||||||
@ -976,13 +1024,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
"$CALDAV-$mEventCalendarId"
|
"$CALDAV-$mEventCalendarId"
|
||||||
}
|
}
|
||||||
|
|
||||||
var reminders = arrayListOf(
|
val reminders = getReminders()
|
||||||
Reminder(mReminder1Minutes, mReminder1Type),
|
|
||||||
Reminder(mReminder2Minutes, mReminder2Type),
|
|
||||||
Reminder(mReminder3Minutes, mReminder3Type)
|
|
||||||
)
|
|
||||||
reminders = reminders.filter { it.minutes != REMINDER_OFF }.sortedBy { it.minutes }.toMutableList() as ArrayList<Reminder>
|
|
||||||
|
|
||||||
val reminder1 = reminders.getOrNull(0) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
|
val reminder1 = reminders.getOrNull(0) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
|
||||||
val reminder2 = reminders.getOrNull(1) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
|
val reminder2 = reminders.getOrNull(1) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
|
||||||
val reminder3 = reminders.getOrNull(2) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
|
val reminder3 = reminders.getOrNull(2) ?: Reminder(REMINDER_OFF, REMINDER_NOTIFICATION)
|
||||||
|
Reference in New Issue
Block a user