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.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.Toast
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.app.AlarmManagerCompat import androidx.core.app.AlarmManagerCompat
import androidx.core.app.NotificationCompat 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 kotlinx.android.synthetic.main.day_monthly_event_view.view.*
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.DateTimeConstants import org.joda.time.DateTimeConstants
import org.joda.time.DateTimeZone
import org.joda.time.LocalDate import org.joda.time.LocalDate
import java.io.File import java.io.File
import java.io.FileOutputStream 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!!) val events = eventsHelper.getRepeatableEventsFor(currentSeconds - WEEK_SECONDS, currentSeconds + YEAR_SECONDS, event.id!!)
for (currEvent in events) { for (currEvent in events) {
eventStartTS = if (currEvent.getIsAllDay()) Formatter.getDayStartTS(Formatter.getDayCodeFromTS(currEvent.startTS)) else currEvent.startTS 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) { if (eventStartTS - firstReminderMinutes * 60 > currentSeconds) {
break break
} }
@ -759,7 +758,11 @@ fun Context.editEvent(event: ListEvent) {
} }
fun Context.getFirstDayOfWeek(date: DateTime): String { 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) { if (!config.startWeekWithCurrentDay) {
startOfWeek = if (config.isSundayFirst) { startOfWeek = if (config.isSundayFirst) {
// a workaround for Joda-time's Monday-as-first-day-of-the-week // 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) startOfWeek.withDayOfWeek(DateTimeConstants.MONDAY)
} }
} }
return startOfWeek.toString() return startOfWeek
} }
fun Context.isTaskCompleted(event: Event): Boolean { fun Context.isTaskCompleted(event: Event): Boolean {

View File

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

View File

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