use the next full hour as the default event time, not 13:00 the next day

This commit is contained in:
tibbi 2017-09-06 13:44:09 +02:00
parent 7f89761e21
commit 867a6252d4
3 changed files with 10 additions and 7 deletions

View File

@ -221,17 +221,20 @@ private fun getSnoozePendingIntent(context: Context, event: Event): PendingInten
return PendingIntent.getService(context, event.id, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
fun Context.launchNewEventIntent(startNewTask: Boolean = false, today: Boolean = false) {
val code = Formatter.getDayCodeFromDateTime(DateTime(DateTimeZone.getDefault()).plusDays(if (today) 0 else 1))
fun Context.launchNewEventIntent() {
val code = Formatter.getDayCodeFromDateTime(DateTime(DateTimeZone.getDefault()))
Intent(applicationContext, EventActivity::class.java).apply {
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(code))
if (startNewTask)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(this)
}
}
fun Context.getNewEventTimestampFromCode(dayCode: String) = Formatter.getLocalDateTimeFromCode(dayCode).withTime(13, 0, 0, 0).seconds()
fun Context.getNewEventTimestampFromCode(dayCode: String): Int {
val currHour = DateTime(System.currentTimeMillis(), DateTimeZone.getDefault()).hourOfDay
val dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(currHour)
return dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).seconds()
}
fun Context.getCurrentOffset() = SimpleDateFormat("Z", Locale.getDefault()).format(Date())

View File

@ -87,7 +87,7 @@ class MyWidgetListProvider : AppWidgetProvider() {
mContext = context
when (intent.action) {
NEW_EVENT -> context.launchNewEventIntent(true, true)
NEW_EVENT -> context.launchNewEventIntent()
LAUNCH_TODAY -> launchDayActivity()
else -> super.onReceive(context, intent)
}

View File

@ -120,7 +120,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
when (action) {
PREV -> getPrevMonth()
NEXT -> getNextMonth()
NEW_EVENT -> mContext.launchNewEventIntent(true)
NEW_EVENT -> mContext.launchNewEventIntent()
else -> super.onReceive(context, intent)
}
}