allow setting the current time as the default at new events

This commit is contained in:
tibbi 2021-04-14 22:51:25 +02:00
parent 42135f9b5b
commit dfb7061450
3 changed files with 31 additions and 17 deletions

View File

@ -572,13 +572,19 @@ class SettingsActivity : SimpleActivity() {
private fun setupDefaultStartTime() { private fun setupDefaultStartTime() {
updateDefaultStartTimeText() updateDefaultStartTimeText()
settings_default_start_time_holder.setOnClickListener { settings_default_start_time_holder.setOnClickListener {
val currentDefaultTime = if (config.defaultStartTime == DEFAULT_START_TIME_NEXT_FULL_HOUR) DEFAULT_START_TIME_NEXT_FULL_HOUR else 0 val currentDefaultTime = when (config.defaultStartTime) {
DEFAULT_START_TIME_NEXT_FULL_HOUR -> DEFAULT_START_TIME_NEXT_FULL_HOUR
DEFAULT_START_TIME_CURRENT_TIME -> DEFAULT_START_TIME_CURRENT_TIME
else -> 0
}
val items = ArrayList<RadioItem>() val items = ArrayList<RadioItem>()
items.add(RadioItem(DEFAULT_START_TIME_CURRENT_TIME, getString(R.string.current_time)))
items.add(RadioItem(DEFAULT_START_TIME_NEXT_FULL_HOUR, getString(R.string.next_full_hour))) items.add(RadioItem(DEFAULT_START_TIME_NEXT_FULL_HOUR, getString(R.string.next_full_hour)))
items.add(RadioItem(0, getString(R.string.other_time))) items.add(RadioItem(0, getString(R.string.other_time)))
RadioGroupDialog(this@SettingsActivity, items, currentDefaultTime) { RadioGroupDialog(this@SettingsActivity, items, currentDefaultTime) {
if (it as Int == DEFAULT_START_TIME_NEXT_FULL_HOUR) { if (it as Int == DEFAULT_START_TIME_NEXT_FULL_HOUR || it == DEFAULT_START_TIME_CURRENT_TIME) {
config.defaultStartTime = it config.defaultStartTime = it
updateDefaultStartTimeText() updateDefaultStartTimeText()
} else { } else {
@ -595,14 +601,16 @@ class SettingsActivity : SimpleActivity() {
} }
private fun updateDefaultStartTimeText() { private fun updateDefaultStartTimeText() {
if (config.defaultStartTime == DEFAULT_START_TIME_NEXT_FULL_HOUR) { when (config.defaultStartTime) {
settings_default_start_time.text = getString(R.string.next_full_hour) DEFAULT_START_TIME_CURRENT_TIME -> settings_default_start_time.text = getString(R.string.current_time)
} else { DEFAULT_START_TIME_NEXT_FULL_HOUR -> settings_default_start_time.text = getString(R.string.next_full_hour)
else -> {
val hours = config.defaultStartTime / 60 val hours = config.defaultStartTime / 60
val minutes = config.defaultStartTime % 60 val minutes = config.defaultStartTime % 60
settings_default_start_time.text = String.format("%02d:%02d", hours, minutes) settings_default_start_time.text = String.format("%02d:%02d", hours, minutes)
} }
} }
}
private fun setupDefaultDuration() { private fun setupDefaultDuration() {
updateDefaultDurationText() updateDefaultDurationText()

View File

@ -350,9 +350,13 @@ fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Bool
newDateTime = newDateTime.minusDays(1) newDateTime = newDateTime.minusDays(1)
} }
return if (defaultStartTime == -1) { return when (defaultStartTime) {
newDateTime.seconds() DEFAULT_START_TIME_CURRENT_TIME -> {
} else { val currMinutes = calendar.get(Calendar.MINUTE)
dateTime.withMinuteOfHour(currMinutes).seconds()
}
DEFAULT_START_TIME_NEXT_FULL_HOUR -> newDateTime.seconds()
else -> {
val hours = defaultStartTime / 60 val hours = defaultStartTime / 60
val minutes = defaultStartTime % 60 val minutes = defaultStartTime % 60
dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(hours).withMinuteOfHour(minutes) dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(hours).withMinuteOfHour(minutes)
@ -362,6 +366,7 @@ fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Bool
newDateTime.withDate(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth).seconds() newDateTime.withDate(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth).seconds()
} }
} }
}
fun Context.getSyncedCalDAVCalendars() = calDAVHelper.getCalDAVCalendars(config.caldavSyncedCalendarIds, false) fun Context.getSyncedCalDAVCalendars() = calDAVHelper.getCalDAVCalendars(config.caldavSyncedCalendarIds, false)

View File

@ -35,6 +35,7 @@ const val ITEM_EVENT_SIMPLE = 1
const val ITEM_HEADER = 2 const val ITEM_HEADER = 2
const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1 const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1
const val DEFAULT_START_TIME_CURRENT_TIME = -2
const val DAY = 86400 const val DAY = 86400
const val WEEK = 604800 const val WEEK = 604800