Display week info above meeting in list

This commit is contained in:
Sylvain Berfini 2024-04-25 15:36:10 +02:00
parent 177eb186a5
commit 9daa433c44
6 changed files with 105 additions and 7 deletions

View file

@ -22,7 +22,10 @@ package org.linphone.ui.main.meetings.model
import androidx.annotation.WorkerThread
import org.linphone.utils.TimestampUtils
class MeetingListItemModel @WorkerThread constructor(meetingModel: MeetingModel?) {
class MeetingListItemModel @WorkerThread constructor(
meetingModel: MeetingModel?,
val firstMeetingOfTheWeek: Boolean
) {
val isToday = meetingModel == null
val month = meetingModel?.month ?: TimestampUtils.month(System.currentTimeMillis(), false)
@ -34,7 +37,16 @@ class MeetingListItemModel @WorkerThread constructor(meetingModel: MeetingModel?
false
)
val weekLabel = meetingModel?.weekLabel ?: TimestampUtils.firstAndLastDayOfWeek(
System.currentTimeMillis(),
false
)
val model = meetingModel ?: TodayModel()
init {
meetingModel?.firstMeetingOfTheWeek?.postValue(firstMeetingOfTheWeek)
}
class TodayModel
}

View file

@ -59,6 +59,10 @@ class MeetingModel @WorkerThread constructor(private val conferenceInfo: Confere
val firstMeetingOfTheDay = MutableLiveData<Boolean>()
val weekLabel = TimestampUtils.firstAndLastDayOfWeek(timestamp)
val firstMeetingOfTheWeek = MutableLiveData<Boolean>()
init {
subject.postValue(conferenceInfo.subject)

View file

@ -30,6 +30,7 @@ import org.linphone.core.tools.Log
import org.linphone.ui.main.meetings.model.MeetingListItemModel
import org.linphone.ui.main.meetings.model.MeetingModel
import org.linphone.ui.main.viewmodel.AbstractMainViewModel
import org.linphone.utils.TimestampUtils
class MeetingsListViewModel @UiThread constructor() : AbstractMainViewModel() {
companion object {
@ -91,6 +92,7 @@ class MeetingsListViewModel @UiThread constructor() : AbstractMainViewModel() {
}
var previousModel: MeetingModel? = null
var previousModelWeekLabel = ""
var meetingForTodayFound = false
for (info: ConferenceInfo in source) {
if (info.duration == 0) continue // This isn't a scheduled conference, don't display it
@ -111,6 +113,9 @@ class MeetingsListViewModel @UiThread constructor() : AbstractMainViewModel() {
if (add) {
val model = MeetingModel(info)
val firstMeetingOfTheWeek = previousModelWeekLabel != model.weekLabel
val firstMeetingOfTheDay = if (previousModel != null) {
previousModel.day != model.day || previousModel.dayNumber != model.dayNumber
} else {
@ -124,18 +129,31 @@ class MeetingsListViewModel @UiThread constructor() : AbstractMainViewModel() {
// If no meeting was found for today, insert "Today" fake model before the next meeting to come
if (!meetingForTodayFound && model.isAfterToday) {
list.add(MeetingListItemModel(null))
val todayWeekLabel = TimestampUtils.firstAndLastDayOfWeek(
System.currentTimeMillis(),
false
)
val firstMeetingOfTheWeek = previousModelWeekLabel != todayWeekLabel
list.add(MeetingListItemModel(null, firstMeetingOfTheWeek))
meetingForTodayFound = true
previousModelWeekLabel = todayWeekLabel
} else {
previousModelWeekLabel = model.weekLabel
}
list.add(MeetingListItemModel(model))
list.add(MeetingListItemModel(model, firstMeetingOfTheWeek))
previousModel = model
}
}
// If no meeting was found after today, insert "Today" fake model at the end
if (!meetingForTodayFound) {
list.add(MeetingListItemModel(null))
val todayWeekLabel = TimestampUtils.firstAndLastDayOfWeek(
System.currentTimeMillis(),
false
)
val firstMeetingOfTheWeek = previousModelWeekLabel != todayWeekLabel
list.add(MeetingListItemModel(null, firstMeetingOfTheWeek))
}
meetings.postValue(list)

View file

@ -96,6 +96,33 @@ class TimestampUtils {
return calendar.get(Calendar.DAY_OF_MONTH).toString()
}
@AnyThread
fun firstAndLastDayOfWeek(timestamp: Long, timestampInSecs: Boolean = true): String {
val calendar = Calendar.getInstance()
calendar.timeInMillis = if (timestampInSecs) timestamp * 1000 else timestamp
while (calendar.get(Calendar.DAY_OF_WEEK) != calendar.firstDayOfWeek) {
calendar.add(Calendar.DATE, -1)
}
val firstDayOfWeek = calendar.get(Calendar.DAY_OF_MONTH).toString()
val firstDayOfWeekMonth = calendar.getDisplayName(
Calendar.MONTH,
TextStyle.SHORT.ordinal,
Locale.getDefault()
)
calendar.add(Calendar.DAY_OF_MONTH, 6)
val lastDayOfWeek = calendar.get(Calendar.DAY_OF_MONTH).toString()
val lastDayOfWeekMonth = calendar.getDisplayName(
Calendar.MONTH,
TextStyle.SHORT.ordinal,
Locale.getDefault()
)
return if (firstDayOfWeekMonth == lastDayOfWeekMonth) {
"$firstDayOfWeek - $lastDayOfWeek $lastDayOfWeekMonth"
} else {
"$firstDayOfWeek $firstDayOfWeekMonth - $lastDayOfWeek $lastDayOfWeekMonth"
}
}
@AnyThread
fun month(timestamp: Long, timestampInSecs: Boolean = true): String {
val calendar = Calendar.getInstance()

View file

@ -22,6 +22,24 @@
android:paddingStart="16dp"
android:paddingEnd="16dp">
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/week_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="@{model.weekLabel, default=`22 - 28 Avril`}"
android:textSize="14sp"
android:textColor="?attr/color_main2_500"
android:maxLines="1"
android:ellipsize="end"
android:visibility="@{model.firstMeetingOfTheWeek ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="@id/cardview"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/header_day"
app:layout_constraintEnd_toEndOf="@id/cardview" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/header_day"
@ -35,7 +53,7 @@
android:textSize="14sp"
app:layout_constraintStart_toStartOf="@id/header_day_number"
app:layout_constraintEnd_toEndOf="@id/header_day_number"
app:layout_constraintTop_toTopOf="parent"/>
app:layout_constraintTop_toBottomOf="@id/week_label"/>
<ImageView
android:id="@+id/today_background"
@ -77,7 +95,7 @@
android:elevation="5dp"
app:layout_constraintStart_toEndOf="@id/header_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/week_label"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.appcompat.widget.AppCompatTextView

View file

@ -16,6 +16,24 @@
android:paddingStart="16dp"
android:paddingEnd="16dp">
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/week_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="@{model.weekLabel, default=`22 - 28 Avril`}"
android:textSize="14sp"
android:textColor="?attr/color_main2_500"
android:maxLines="1"
android:ellipsize="end"
android:visibility="@{model.firstMeetingOfTheWeek ? View.VISIBLE : View.GONE}"
app:layout_constraintStart_toStartOf="@id/title"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/header_day"
app:layout_constraintEnd_toEndOf="@id/title" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/header_day"
@ -27,7 +45,7 @@
android:textSize="14sp"
app:layout_constraintStart_toStartOf="@id/header_day_number"
app:layout_constraintEnd_toEndOf="@id/header_day_number"
app:layout_constraintTop_toTopOf="parent"/>
app:layout_constraintTop_toBottomOf="@id/week_label"/>
<ImageView
android:id="@+id/today_background"
@ -60,6 +78,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginEnd="5dp"
android:paddingStart="16dp"
android:text="@string/meetings_list_no_meeting_for_today"
android:textSize="13sp"
android:textColor="?attr/color_main2_600"