Merge pull request #2154 from Naveen3Singh/weekly_view_tz_fix

Use local timezone to configure weekly views
This commit is contained in:
Tibor Kaputa 2023-07-16 15:05:24 +02:00 committed by GitHub
commit 7ab69e974d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 21 deletions

View file

@ -20,7 +20,6 @@ import android.provider.CalendarContract
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.Toast
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.app.AlarmManagerCompat
import androidx.core.app.NotificationCompat
@ -48,7 +47,6 @@ import com.simplemobiletools.commons.helpers.*
import kotlinx.android.synthetic.main.day_monthly_event_view.view.*
import org.joda.time.DateTime
import org.joda.time.DateTimeConstants
import org.joda.time.DateTimeZone
import org.joda.time.LocalDate
import java.io.File
import java.io.FileOutputStream
@ -327,7 +325,8 @@ fun Context.notifyEvent(originalEvent: Event) {
val events = eventsHelper.getRepeatableEventsFor(currentSeconds - WEEK_SECONDS, currentSeconds + YEAR_SECONDS, event.id!!)
for (currEvent in events) {
eventStartTS = if (currEvent.getIsAllDay()) Formatter.getDayStartTS(Formatter.getDayCodeFromTS(currEvent.startTS)) else currEvent.startTS
val firstReminderMinutes = arrayOf(currEvent.reminder3Minutes, currEvent.reminder2Minutes, currEvent.reminder1Minutes).filter { it != REMINDER_OFF }.max()
val firstReminderMinutes =
arrayOf(currEvent.reminder3Minutes, currEvent.reminder2Minutes, currEvent.reminder1Minutes).filter { it != REMINDER_OFF }.max()
if (eventStartTS - firstReminderMinutes * 60 > currentSeconds) {
break
}
@ -759,7 +758,11 @@ fun Context.editEvent(event: ListEvent) {
}
fun Context.getFirstDayOfWeek(date: DateTime): String {
var startOfWeek = date.withZoneRetainFields(DateTimeZone.UTC).withTimeAtStartOfDay()
return getFirstDayOfWeekDt(date).toString()
}
fun Context.getFirstDayOfWeekDt(date: DateTime): DateTime {
var startOfWeek = date.withTimeAtStartOfDay()
if (!config.startWeekWithCurrentDay) {
startOfWeek = if (config.isSundayFirst) {
// a workaround for Joda-time's Monday-as-first-day-of-the-week
@ -772,7 +775,7 @@ fun Context.getFirstDayOfWeek(date: DateTime): String {
startOfWeek.withDayOfWeek(DateTimeConstants.MONDAY)
}
}
return startOfWeek.toString()
return startOfWeek
}
fun Context.isTaskCompleted(event: Event): Boolean {

View file

@ -196,14 +196,14 @@ class WeekFragment : Fragment(), WeeklyCalendar {
mView.week_events_columns_holder.removeAllViews()
(0 until config.weeklyViewDays).forEach {
val column = inflater.inflate(R.layout.weekly_view_day_column, mView.week_events_columns_holder, false) as RelativeLayout
column.tag = Formatter.getUTCDayCodeFromTS(weekTimestamp + it * DAY_SECONDS)
column.tag = Formatter.getDayCodeFromTS(weekTimestamp + it * DAY_SECONDS)
mView.week_events_columns_holder.addView(column)
dayColumns.add(column)
}
}
private fun setupDayLabels() {
var curDay = Formatter.getUTCDateTimeFromTS(weekTimestamp)
var curDay = Formatter.getDateTimeFromTS(weekTimestamp)
val todayCode = Formatter.getDayCodeFromDateTime(DateTime())
val screenWidth = context?.usableScreenSize?.x ?: return
val dayWidth = screenWidth / config.weeklyViewDays

View file

@ -189,22 +189,11 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
}
private fun dateSelected(dateTime: DateTime, datePicker: DatePicker) {
val isSundayFirst = requireContext().config.isSundayFirst
val month = datePicker.month + 1
val year = datePicker.year
val day = datePicker.dayOfMonth
var newDateTime = dateTime.withDate(year, month, day)
if (isSundayFirst) {
newDateTime = newDateTime.plusDays(1)
}
var selectedWeek = newDateTime.withDayOfWeek(1).withTimeAtStartOfDay().minusDays(if (isSundayFirst) 1 else 0)
if (newDateTime.minusDays(7).seconds() > selectedWeek.seconds()) {
selectedWeek = selectedWeek.plusDays(7)
}
currentWeekTS = selectedWeek.seconds()
val newDateTime = dateTime.withDate(year, month, day)
currentWeekTS = requireContext().getFirstDayOfWeekDt(newDateTime).seconds()
setupFragment()
}
@ -311,7 +300,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
override fun getCurrentDate(): DateTime? {
return if (currentWeekTS != 0L) {
Formatter.getUTCDateTimeFromTS(currentWeekTS)
Formatter.getDateTimeFromTS(currentWeekTS)
} else {
null
}