mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fix #1314, avoid switching day at creating a new event on some views
This commit is contained in:
@@ -86,7 +86,9 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
checkWhatsNewDialog()
|
checkWhatsNewDialog()
|
||||||
calendar_fab.beVisibleIf(config.storedView != YEARLY_VIEW && config.storedView != WEEKLY_VIEW)
|
calendar_fab.beVisibleIf(config.storedView != YEARLY_VIEW && config.storedView != WEEKLY_VIEW)
|
||||||
calendar_fab.setOnClickListener {
|
calendar_fab.setOnClickListener {
|
||||||
launchNewEventIntent(currentFragments.last().getNewEventDayCode())
|
val lastFragment = currentFragments.last()
|
||||||
|
val allowChangingDay = lastFragment !is DayFragmentsHolder && lastFragment !is MonthDayFragmentsHolder
|
||||||
|
launchNewEventIntent(lastFragment.getNewEventDayCode(), allowChangingDay)
|
||||||
}
|
}
|
||||||
|
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
|
@@ -331,20 +331,24 @@ fun Context.rescheduleReminder(event: Event?, minutes: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode()) {
|
// if the default event start time is set to "Next full hour" and the event is created before midnight, it could change the day
|
||||||
|
fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode(), allowChangingDay: Boolean = false) {
|
||||||
Intent(applicationContext, EventActivity::class.java).apply {
|
Intent(applicationContext, EventActivity::class.java).apply {
|
||||||
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(dayCode))
|
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(dayCode, allowChangingDay))
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
startActivity(this)
|
startActivity(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getNewEventTimestampFromCode(dayCode: String): Long {
|
fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Boolean = false): Long {
|
||||||
val calendar = Calendar.getInstance()
|
val calendar = Calendar.getInstance()
|
||||||
val defaultStartTime = config.defaultStartTime
|
val defaultStartTime = config.defaultStartTime
|
||||||
val currHour = calendar.get(Calendar.HOUR_OF_DAY)
|
val currHour = calendar.get(Calendar.HOUR_OF_DAY)
|
||||||
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 (!allowChangingDay && dateTime.dayOfMonth() != newDateTime.dayOfMonth()) {
|
||||||
|
newDateTime = newDateTime.minusDays(1)
|
||||||
|
}
|
||||||
|
|
||||||
return if (defaultStartTime == -1) {
|
return if (defaultStartTime == -1) {
|
||||||
newDateTime.seconds()
|
newDateTime.seconds()
|
||||||
|
Reference in New Issue
Block a user