mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-04-22 05:47:27 +02:00
Save and restore state important values
This commit is contained in:
parent
4375284612
commit
d70e844448
@ -77,6 +77,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
private var mOriginalTimeZone = DateTimeZone.getDefault().id
|
private var mOriginalTimeZone = DateTimeZone.getDefault().id
|
||||||
private var mOriginalStartTS = 0L
|
private var mOriginalStartTS = 0L
|
||||||
private var mOriginalEndTS = 0L
|
private var mOriginalEndTS = 0L
|
||||||
|
private var mIsNewEvent = true
|
||||||
|
|
||||||
private lateinit var mEventStartDateTime: DateTime
|
private lateinit var mEventStartDateTime: DateTime
|
||||||
private lateinit var mEventEndDateTime: DateTime
|
private lateinit var mEventEndDateTime: DateTime
|
||||||
@ -353,6 +354,9 @@ class EventActivity : SimpleActivity() {
|
|||||||
|
|
||||||
putLong(EVENT_TYPE_ID, mEventTypeId)
|
putLong(EVENT_TYPE_ID, mEventTypeId)
|
||||||
putInt(EVENT_CALENDAR_ID, mEventCalendarId)
|
putInt(EVENT_CALENDAR_ID, mEventCalendarId)
|
||||||
|
putBoolean(IS_NEW_EVENT, mIsNewEvent)
|
||||||
|
putLong(ORIGINAL_START_TS, mOriginalStartTS)
|
||||||
|
putLong(ORIGINAL_END_TS, mOriginalEndTS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,6 +393,9 @@ class EventActivity : SimpleActivity() {
|
|||||||
|
|
||||||
mEventTypeId = getLong(EVENT_TYPE_ID)
|
mEventTypeId = getLong(EVENT_TYPE_ID)
|
||||||
mEventCalendarId = getInt(EVENT_CALENDAR_ID)
|
mEventCalendarId = getInt(EVENT_CALENDAR_ID)
|
||||||
|
mIsNewEvent = getBoolean(IS_NEW_EVENT)
|
||||||
|
mOriginalStartTS = getLong(ORIGINAL_START_TS)
|
||||||
|
mOriginalEndTS = getLong(ORIGINAL_END_TS)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRepeatTexts(mRepeatInterval)
|
checkRepeatTexts(mRepeatInterval)
|
||||||
@ -397,6 +404,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
updateEventType()
|
updateEventType()
|
||||||
updateCalDAVCalendar()
|
updateCalDAVCalendar()
|
||||||
checkAttendees()
|
checkAttendees()
|
||||||
|
updateActionBarTitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
@ -420,6 +428,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupEditEvent() {
|
private fun setupEditEvent() {
|
||||||
|
mIsNewEvent = false
|
||||||
val realStart = if (mEventOccurrenceTS == 0L) mEvent.startTS else mEventOccurrenceTS
|
val realStart = if (mEventOccurrenceTS == 0L) mEvent.startTS else mEventOccurrenceTS
|
||||||
val duration = mEvent.endTS - mEvent.startTS
|
val duration = mEvent.endTS - mEvent.startTS
|
||||||
mOriginalStartTS = realStart
|
mOriginalStartTS = realStart
|
||||||
@ -1105,15 +1114,15 @@ class EventActivity : SimpleActivity() {
|
|||||||
|
|
||||||
val reminders = getReminders()
|
val reminders = getReminders()
|
||||||
if (!event_all_day.isChecked) {
|
if (!event_all_day.isChecked) {
|
||||||
if (reminders.getOrNull(2)?.minutes ?: 0 < -1) {
|
if ((reminders.getOrNull(2)?.minutes ?: 0) < -1) {
|
||||||
reminders.removeAt(2)
|
reminders.removeAt(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reminders.getOrNull(1)?.minutes ?: 0 < -1) {
|
if ((reminders.getOrNull(1)?.minutes ?: 0) < -1) {
|
||||||
reminders.removeAt(1)
|
reminders.removeAt(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reminders.getOrNull(0)?.minutes ?: 0 < -1) {
|
if ((reminders.getOrNull(0)?.minutes ?: 0) < -1) {
|
||||||
reminders.removeAt(0)
|
reminders.removeAt(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1701,4 +1710,12 @@ class EventActivity : SimpleActivity() {
|
|||||||
it.applyColorFilter(textColor)
|
it.applyColorFilter(textColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateActionBarTitle() {
|
||||||
|
if (mIsNewEvent) {
|
||||||
|
updateActionBarTitle(getString(R.string.new_event))
|
||||||
|
} else {
|
||||||
|
updateActionBarTitle(getString(R.string.edit_event))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
|||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.EVERY_DAY_BIT
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.helpers.SAVE_DISCARD_PROMPT_INTERVAL
|
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import kotlinx.android.synthetic.main.activity_task.*
|
import kotlinx.android.synthetic.main.activity_task.*
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
@ -53,6 +51,7 @@ class TaskActivity : SimpleActivity() {
|
|||||||
private var mOriginalStartTS = 0L
|
private var mOriginalStartTS = 0L
|
||||||
private var mTaskCompleted = false
|
private var mTaskCompleted = false
|
||||||
private var mLastSavePromptTS = 0L
|
private var mLastSavePromptTS = 0L
|
||||||
|
private var mIsNewEvent = true
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -167,6 +166,8 @@ class TaskActivity : SimpleActivity() {
|
|||||||
putLong(REPEAT_LIMIT, mRepeatLimit)
|
putLong(REPEAT_LIMIT, mRepeatLimit)
|
||||||
|
|
||||||
putLong(EVENT_TYPE_ID, mEventTypeId)
|
putLong(EVENT_TYPE_ID, mEventTypeId)
|
||||||
|
putBoolean(IS_NEW_EVENT, mIsNewEvent)
|
||||||
|
putLong(ORIGINAL_START_TS, mOriginalStartTS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,10 +192,16 @@ class TaskActivity : SimpleActivity() {
|
|||||||
mRepeatRule = getInt(REPEAT_RULE)
|
mRepeatRule = getInt(REPEAT_RULE)
|
||||||
mRepeatLimit = getLong(REPEAT_LIMIT)
|
mRepeatLimit = getLong(REPEAT_LIMIT)
|
||||||
mEventTypeId = getLong(EVENT_TYPE_ID)
|
mEventTypeId = getLong(EVENT_TYPE_ID)
|
||||||
|
mIsNewEvent = getBoolean(IS_NEW_EVENT)
|
||||||
|
mOriginalStartTS = getLong(ORIGINAL_START_TS)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateEventType()
|
updateEventType()
|
||||||
updateTexts()
|
updateTexts()
|
||||||
|
setupMarkCompleteButton()
|
||||||
|
checkRepeatTexts(mRepeatInterval)
|
||||||
|
checkRepeatRule()
|
||||||
|
updateActionBarTitle()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun gotTask(savedInstanceState: Bundle?, localEventType: EventType?, task: Event?) {
|
private fun gotTask(savedInstanceState: Bundle?, localEventType: EventType?, task: Event?) {
|
||||||
@ -264,6 +271,7 @@ class TaskActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupEditTask() {
|
private fun setupEditTask() {
|
||||||
|
mIsNewEvent = false
|
||||||
val realStart = if (mTaskOccurrenceTS == 0L) mTask.startTS else mTaskOccurrenceTS
|
val realStart = if (mTaskOccurrenceTS == 0L) mTask.startTS else mTaskOccurrenceTS
|
||||||
mOriginalStartTS = realStart
|
mOriginalStartTS = realStart
|
||||||
mTaskDateTime = Formatter.getDateTimeFromTS(realStart)
|
mTaskDateTime = Formatter.getDateTimeFromTS(realStart)
|
||||||
@ -453,6 +461,7 @@ class TaskActivity : SimpleActivity() {
|
|||||||
private fun dateSet(year: Int, month: Int, day: Int) {
|
private fun dateSet(year: Int, month: Int, day: Int) {
|
||||||
mTaskDateTime = mTaskDateTime.withDate(year, month + 1, day)
|
mTaskDateTime = mTaskDateTime.withDate(year, month + 1, day)
|
||||||
updateDateText()
|
updateDateText()
|
||||||
|
checkRepeatRule()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun timeSet(hours: Int, minutes: Int) {
|
private fun timeSet(hours: Int, minutes: Int) {
|
||||||
@ -467,6 +476,21 @@ class TaskActivity : SimpleActivity() {
|
|||||||
updateRepetitionText()
|
updateRepetitionText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkRepeatRule() {
|
||||||
|
if (mRepeatInterval.isXWeeklyRepetition()) {
|
||||||
|
val day = mRepeatRule
|
||||||
|
if (day == MONDAY_BIT || day == TUESDAY_BIT || day == WEDNESDAY_BIT || day == THURSDAY_BIT || day == FRIDAY_BIT || day == SATURDAY_BIT || day == SUNDAY_BIT) {
|
||||||
|
setRepeatRule(2.0.pow((mTaskDateTime.dayOfWeek - 1).toDouble()).toInt())
|
||||||
|
}
|
||||||
|
} else if (mRepeatInterval.isXMonthlyRepetition() || mRepeatInterval.isXYearlyRepetition()) {
|
||||||
|
if (mRepeatRule == REPEAT_LAST_DAY && !isLastDayOfTheMonth()) {
|
||||||
|
mRepeatRule = REPEAT_SAME_DAY
|
||||||
|
}
|
||||||
|
checkRepetitionRuleText()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun updateDateText() {
|
private fun updateDateText() {
|
||||||
task_date.text = Formatter.getDate(this, mTaskDateTime)
|
task_date.text = Formatter.getDate(this, mTaskDateTime)
|
||||||
}
|
}
|
||||||
@ -483,17 +507,17 @@ class TaskActivity : SimpleActivity() {
|
|||||||
private fun setupMarkCompleteButton() {
|
private fun setupMarkCompleteButton() {
|
||||||
toggle_mark_complete.setOnClickListener { toggleCompletion() }
|
toggle_mark_complete.setOnClickListener { toggleCompletion() }
|
||||||
toggle_mark_complete.beVisibleIf(mTask.id != null)
|
toggle_mark_complete.beVisibleIf(mTask.id != null)
|
||||||
updateTaskCompleted()
|
updateTaskCompletedButton()
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
// the stored value might be incorrect so update it (e.g. user completed the task via notification action before editing)
|
// the stored value might be incorrect so update it (e.g. user completed the task via notification action before editing)
|
||||||
mTaskCompleted = isTaskCompleted(mTask.copy(startTS = mOriginalStartTS, endTS = mOriginalStartTS))
|
mTaskCompleted = isTaskCompleted(mTask.copy(startTS = mOriginalStartTS))
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
updateTaskCompleted()
|
updateTaskCompletedButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateTaskCompleted() {
|
private fun updateTaskCompletedButton() {
|
||||||
if (mTaskCompleted) {
|
if (mTaskCompleted) {
|
||||||
toggle_mark_complete.background = ContextCompat.getDrawable(this, R.drawable.button_background_stroke)
|
toggle_mark_complete.background = ContextCompat.getDrawable(this, R.drawable.button_background_stroke)
|
||||||
toggle_mark_complete.setText(R.string.mark_incomplete)
|
toggle_mark_complete.setText(R.string.mark_incomplete)
|
||||||
@ -847,4 +871,12 @@ class TaskActivity : SimpleActivity() {
|
|||||||
private fun updateRepetitionText() {
|
private fun updateRepetitionText() {
|
||||||
task_repetition.text = getRepetitionText(mRepeatInterval)
|
task_repetition.text = getRepetitionText(mRepeatInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateActionBarTitle() {
|
||||||
|
if (mIsNewEvent) {
|
||||||
|
updateActionBarTitle(getString(R.string.new_task))
|
||||||
|
} else {
|
||||||
|
updateActionBarTitle(getString(R.string.edit_task))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,8 @@ const val EVENT = "EVENT"
|
|||||||
const val TASK = "TASK"
|
const val TASK = "TASK"
|
||||||
const val START_TS = "START_TS"
|
const val START_TS = "START_TS"
|
||||||
const val END_TS = "END_TS"
|
const val END_TS = "END_TS"
|
||||||
|
const val ORIGINAL_START_TS = "ORIGINAL_START_TS"
|
||||||
|
const val ORIGINAL_END_TS = "ORIGINAL_END_TS"
|
||||||
const val REMINDER_1_MINUTES = "REMINDER_1_MINUTES"
|
const val REMINDER_1_MINUTES = "REMINDER_1_MINUTES"
|
||||||
const val REMINDER_2_MINUTES = "REMINDER_2_MINUTES"
|
const val REMINDER_2_MINUTES = "REMINDER_2_MINUTES"
|
||||||
const val REMINDER_3_MINUTES = "REMINDER_3_MINUTES"
|
const val REMINDER_3_MINUTES = "REMINDER_3_MINUTES"
|
||||||
@ -220,6 +222,7 @@ const val ATTENDEES = "ATTENDEES"
|
|||||||
const val AVAILABILITY = "AVAILABILITY"
|
const val AVAILABILITY = "AVAILABILITY"
|
||||||
const val EVENT_TYPE_ID = "EVENT_TYPE_ID"
|
const val EVENT_TYPE_ID = "EVENT_TYPE_ID"
|
||||||
const val EVENT_CALENDAR_ID = "EVENT_CALENDAR_ID"
|
const val EVENT_CALENDAR_ID = "EVENT_CALENDAR_ID"
|
||||||
|
const val IS_NEW_EVENT = "IS_NEW_EVENT"
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
const val ACTION_MARK_COMPLETED = "ACTION_MARK_COMPLETED"
|
const val ACTION_MARK_COMPLETED = "ACTION_MARK_COMPLETED"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user