mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-01-27 09:01:20 +01:00
allow specifying minutes at the default event start time too
This commit is contained in:
parent
eeb88b8a59
commit
9758a69789
@ -1,5 +1,6 @@
|
|||||||
package com.simplemobiletools.calendar.pro.activities
|
package com.simplemobiletools.calendar.pro.activities
|
||||||
|
|
||||||
|
import android.app.TimePickerDialog
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.media.AudioManager
|
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.AlarmSound
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
|
import org.joda.time.DateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class SettingsActivity : SimpleActivity() {
|
class SettingsActivity : SimpleActivity() {
|
||||||
@ -555,21 +557,35 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
private fun setupDefaultStartTime() {
|
private fun setupDefaultStartTime() {
|
||||||
updateDefaultStartTimeText()
|
updateDefaultStartTimeText()
|
||||||
settings_set_default_start_time_holder.setOnClickListener {
|
settings_set_default_start_time_holder.setOnClickListener {
|
||||||
|
val currentDefaultTime = if (config.defaultStartTime == -1) -1 else 0
|
||||||
val items = ArrayList<RadioItem>()
|
val items = ArrayList<RadioItem>()
|
||||||
items.add(RadioItem(-1, getString(R.string.next_full_hour)))
|
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) {
|
RadioGroupDialog(this@SettingsActivity, items, currentDefaultTime) {
|
||||||
config.defaultStartTime = it as Int
|
if (it as Int == -1) {
|
||||||
updateDefaultStartTimeText()
|
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() {
|
private fun updateDefaultStartTimeText() {
|
||||||
settings_set_default_start_time.text = getHoursString(config.defaultStartTime)
|
|
||||||
if (config.defaultStartTime == -1) {
|
if (config.defaultStartTime == -1) {
|
||||||
settings_set_default_start_time.text = getString(R.string.next_full_hour)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,13 +314,14 @@ fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode()) {
|
|||||||
|
|
||||||
fun Context.getNewEventTimestampFromCode(dayCode: String): Long {
|
fun Context.getNewEventTimestampFromCode(dayCode: String): Long {
|
||||||
val defaultStartTime = config.defaultStartTime
|
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 dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour)
|
||||||
var newDateTime = dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)
|
var newDateTime = dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)
|
||||||
|
|
||||||
if (defaultStartTime != -1) {
|
if (defaultStartTime != -1) {
|
||||||
currHour = defaultStartTime
|
val hours = defaultStartTime / 60
|
||||||
dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour)
|
val minutes = defaultStartTime % 60
|
||||||
|
dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(hours).withMinuteOfHour(minutes)
|
||||||
newDateTime = dateTime
|
newDateTime = dateTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user