From 9758a69789b0ace632797a90fb57c719d6e04e77 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 13 Feb 2019 15:21:43 +0100 Subject: [PATCH] allow specifying minutes at the default event start time too --- .../pro/activities/SettingsActivity.kt | 26 +++++++++++++++---- .../calendar/pro/extensions/Context.kt | 7 ++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt index d3ed5cbc2..71783af7b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.calendar.pro.activities +import android.app.TimePickerDialog import android.content.Intent import android.content.res.Resources import android.media.AudioManager @@ -21,6 +22,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR import com.simplemobiletools.commons.models.AlarmSound import com.simplemobiletools.commons.models.RadioItem import kotlinx.android.synthetic.main.activity_settings.* +import org.joda.time.DateTime import java.util.* class SettingsActivity : SimpleActivity() { @@ -555,21 +557,35 @@ class SettingsActivity : SimpleActivity() { private fun setupDefaultStartTime() { updateDefaultStartTimeText() settings_set_default_start_time_holder.setOnClickListener { + val currentDefaultTime = if (config.defaultStartTime == -1) -1 else 0 val items = ArrayList() items.add(RadioItem(-1, getString(R.string.next_full_hour))) - (0..24).mapTo(items) { RadioItem(it, getHoursString(it)) } + items.add(RadioItem(0, getString(R.string.other_time))) - RadioGroupDialog(this@SettingsActivity, items, config.defaultStartTime) { - config.defaultStartTime = it as Int - updateDefaultStartTimeText() + RadioGroupDialog(this@SettingsActivity, items, currentDefaultTime) { + if (it as Int == -1) { + config.defaultStartTime = it + updateDefaultStartTimeText() + } else { + val timeListener = TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute -> + config.defaultStartTime = hourOfDay * 60 + minute + updateDefaultStartTimeText() + } + + val currentDateTime = DateTime.now() + TimePickerDialog(this, getDialogTheme(), timeListener, currentDateTime.hourOfDay, currentDateTime.minuteOfHour, config.use24HourFormat).show() + } } } } private fun updateDefaultStartTimeText() { - settings_set_default_start_time.text = getHoursString(config.defaultStartTime) if (config.defaultStartTime == -1) { settings_set_default_start_time.text = getString(R.string.next_full_hour) + } else { + val hours = config.defaultStartTime / 60 + val minutes = config.defaultStartTime % 60 + settings_set_default_start_time.text = String.format("%02d:%02d", hours, minutes) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 73003ffed..f4b7ce726 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -314,13 +314,14 @@ fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode()) { fun Context.getNewEventTimestampFromCode(dayCode: String): Long { val defaultStartTime = config.defaultStartTime - var currHour = DateTime(System.currentTimeMillis(), DateTimeZone.getDefault()).hourOfDay + val currHour = DateTime(System.currentTimeMillis(), DateTimeZone.getDefault()).hourOfDay var dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour) var newDateTime = dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0) if (defaultStartTime != -1) { - currHour = defaultStartTime - dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour) + val hours = defaultStartTime / 60 + val minutes = defaultStartTime % 60 + dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(hours).withMinuteOfHour(minutes) newDateTime = dateTime }