close #38, allow setting reminder in time in other units, not just minutes
This commit is contained in:
parent
053111112a
commit
964c1ed7d1
|
@ -15,6 +15,7 @@ import android.widget.EditText
|
||||||
import com.simplemobiletools.calendar.*
|
import com.simplemobiletools.calendar.*
|
||||||
import com.simplemobiletools.calendar.extensions.beVisibleIf
|
import com.simplemobiletools.calendar.extensions.beVisibleIf
|
||||||
import com.simplemobiletools.calendar.extensions.updateWidget
|
import com.simplemobiletools.calendar.extensions.updateWidget
|
||||||
|
import com.simplemobiletools.calendar.extensions.value
|
||||||
import com.simplemobiletools.calendar.fragments.DayFragment
|
import com.simplemobiletools.calendar.fragments.DayFragment
|
||||||
import com.simplemobiletools.calendar.models.Event
|
import com.simplemobiletools.calendar.models.Event
|
||||||
import kotlinx.android.synthetic.main.activity_event.*
|
import kotlinx.android.synthetic.main.activity_event.*
|
||||||
|
@ -22,6 +23,9 @@ import org.joda.time.DateTime
|
||||||
import org.joda.time.DateTimeZone
|
import org.joda.time.DateTimeZone
|
||||||
|
|
||||||
class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||||
|
val HOUR_MINS = 60
|
||||||
|
val DAY_MINS = 1440
|
||||||
|
|
||||||
private var mWasReminderInit: Boolean = false
|
private var mWasReminderInit: Boolean = false
|
||||||
private var mWasEndDateSet: Boolean = false
|
private var mWasEndDateSet: Boolean = false
|
||||||
private var mWasEndTimeSet: Boolean = false
|
private var mWasEndTimeSet: Boolean = false
|
||||||
|
@ -114,7 +118,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||||
else -> {
|
else -> {
|
||||||
event_reminder.setSelection(2)
|
event_reminder.setSelection(2)
|
||||||
toggleCustomReminderVisibility(true)
|
toggleCustomReminderVisibility(true)
|
||||||
event_reminder_other.setText(mEvent.reminderMinutes.toString())
|
setupReminderPeriod()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,6 +159,21 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupReminderPeriod() {
|
||||||
|
val mins = mEvent.reminderMinutes
|
||||||
|
var value = mins
|
||||||
|
if (mins % DAY_MINS == 0) {
|
||||||
|
value = mins / DAY_MINS
|
||||||
|
event_reminder_other_period.setSelection(2)
|
||||||
|
} else if (mins % HOUR_MINS == 0) {
|
||||||
|
value = mins / HOUR_MINS
|
||||||
|
event_reminder_other_period.setSelection(1)
|
||||||
|
} else {
|
||||||
|
event_reminder_other_period.setSelection(0)
|
||||||
|
}
|
||||||
|
event_reminder_other.setText(value.toString())
|
||||||
|
}
|
||||||
|
|
||||||
fun toggleCustomReminderVisibility(show: Boolean) {
|
fun toggleCustomReminderVisibility(show: Boolean) {
|
||||||
event_reminder_other_period.beVisibleIf(show)
|
event_reminder_other_period.beVisibleIf(show)
|
||||||
event_reminder_other_val.beVisibleIf(show)
|
event_reminder_other_val.beVisibleIf(show)
|
||||||
|
@ -192,29 +211,32 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveEvent() {
|
private fun saveEvent() {
|
||||||
val title = event_title.text.toString().trim { it <= ' ' }
|
val newTitle = event_title.value
|
||||||
if (title.isEmpty()) {
|
if (newTitle.isEmpty()) {
|
||||||
Utils.showToast(applicationContext, R.string.title_empty)
|
Utils.showToast(applicationContext, R.string.title_empty)
|
||||||
event_title.requestFocus()
|
event_title.requestFocus()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val startTS = (mEventStartDateTime.millis / 1000).toInt()
|
val newStartTS = (mEventStartDateTime.millis / 1000).toInt()
|
||||||
val endTS = (mEventEndDateTime.millis / 1000).toInt()
|
val newEndTS = (mEventEndDateTime.millis / 1000).toInt()
|
||||||
|
|
||||||
if (event_end_checkbox.isChecked && startTS > endTS) {
|
if (event_end_checkbox.isChecked && newStartTS > newEndTS) {
|
||||||
Utils.showToast(applicationContext, R.string.end_before_start)
|
Utils.showToast(applicationContext, R.string.end_before_start)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val dbHelper = DBHelper(applicationContext, this)
|
val dbHelper = DBHelper(applicationContext, this)
|
||||||
val description = event_description.text.toString().trim { it <= ' ' }
|
val newDescription = event_description.value
|
||||||
mEvent.startTS = startTS
|
mEvent.apply {
|
||||||
mEvent.endTS = if (event_end_checkbox.isChecked) endTS else startTS
|
startTS = newStartTS
|
||||||
mEvent.title = title
|
endTS = if (event_end_checkbox.isChecked) newEndTS else newStartTS
|
||||||
mEvent.description = description
|
title = newTitle
|
||||||
mEvent.reminderMinutes = reminderMinutes
|
description = newDescription
|
||||||
mEvent.repeatInterval = repeatInterval
|
reminderMinutes = getReminderMinutes()
|
||||||
|
repeatInterval = getRepeatInterval()
|
||||||
|
}
|
||||||
|
|
||||||
if (mEvent.id == 0) {
|
if (mEvent.id == 0) {
|
||||||
dbHelper.insert(mEvent)
|
dbHelper.insert(mEvent)
|
||||||
} else {
|
} else {
|
||||||
|
@ -226,27 +248,30 @@ class EventActivity : SimpleActivity(), DBHelper.EventsListener {
|
||||||
|
|
||||||
private fun saveLastReminderMins() {
|
private fun saveLastReminderMins() {
|
||||||
if (event_reminder.selectedItemPosition == 2) {
|
if (event_reminder.selectedItemPosition == 2) {
|
||||||
mConfig.lastOtherReminderMins = reminderMinutes
|
mConfig.lastOtherReminderMins = getReminderMinutes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val reminderMinutes: Int
|
private fun getReminderMinutes(): Int {
|
||||||
get() {
|
|
||||||
return when (event_reminder.selectedItemPosition) {
|
return when (event_reminder.selectedItemPosition) {
|
||||||
0 -> -1
|
0 -> -1
|
||||||
1 -> 0
|
1 -> 0
|
||||||
else -> {
|
else -> {
|
||||||
val value = event_reminder_other.text.toString().trim { it <= ' ' }
|
val value = event_reminder_other.value
|
||||||
if (value.isEmpty())
|
if (value.isEmpty())
|
||||||
0
|
0
|
||||||
|
|
||||||
Integer.valueOf(value)!!
|
val multiplier = when (event_reminder_other_period.selectedItemPosition) {
|
||||||
|
1 -> HOUR_MINS
|
||||||
|
2 -> DAY_MINS
|
||||||
|
else -> 1
|
||||||
|
}
|
||||||
|
Integer.valueOf(value) * multiplier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val repeatInterval: Int
|
private fun getRepeatInterval(): Int {
|
||||||
get() {
|
|
||||||
return when (event_repetition.selectedItemPosition) {
|
return when (event_repetition.selectedItemPosition) {
|
||||||
1 -> Constants.DAY
|
1 -> Constants.DAY
|
||||||
2 -> Constants.WEEK
|
2 -> Constants.WEEK
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.simplemobiletools.calendar.extensions
|
||||||
|
|
||||||
|
import android.widget.EditText
|
||||||
|
|
||||||
|
val EditText.value: String get() = this.text.toString().trim()
|
Loading…
Reference in New Issue