From 4bdedfbc0ded2378bc98678610d269ea62b6b2a5 Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Thu, 5 Dec 2024 15:19:55 +0100 Subject: [PATCH] show userAbsence period Signed-off-by: sowjanyakch --- .../com/nextcloud/talk/chat/ChatActivity.kt | 41 ++++++++++++++++--- .../main/res/layout/out_of_office_view.xml | 16 +++++--- app/src/main/res/values/strings.xml | 1 + 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 72f1b69a4..a5a3175ed 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -206,6 +206,7 @@ import java.io.File import java.io.IOException import java.net.HttpURLConnection import java.text.SimpleDateFormat +import java.util.Calendar import java.util.Date import java.util.Locale import java.util.concurrent.ExecutionException @@ -569,7 +570,7 @@ class ChatActivity : this.lifecycle.removeObserver(chatViewModel) } - @SuppressLint("NotifyDataSetChanged") + @SuppressLint("NotifyDataSetChanged", "SetTextI18n") @Suppress("LongMethod") private fun initObservers() { Log.d(TAG, "initObservers Called") @@ -1081,10 +1082,40 @@ class ChatActivity : } is ChatViewModel.OutOfOfficeUIState.Success -> { binding.outOfOfficeContainer.visibility = View.VISIBLE - binding.outOfOfficeContainer.findViewById(R.id.userAbsenceShortMessage).text = String.format( - context.resources.getString(R.string.user_absence), - uiState.userAbsence.userId - ) + + + val startDateTimestamp:Long = uiState.userAbsence.startDate.toLong() + val endDateTimestamp:Long = uiState.userAbsence.endDate.toLong() + + val startDate = Date(startDateTimestamp * 1000) + val endDate = Date(endDateTimestamp * 1000) + + val date1 = Calendar.getInstance().apply{time = startDate} + val date2 = Calendar.getInstance().apply{time = endDate} + + val isSameDay = date1.get(Calendar.YEAR) == date2.get(Calendar.YEAR) && + date1.get(Calendar.DAY_OF_YEAR) == date2.get(Calendar.DAY_OF_YEAR) + + if (isSameDay) { + binding.outOfOfficeContainer.findViewById(R.id.userAbsenceShortMessage).text = String.format( + context.resources.getString(R.string.user_absence_for_one_day), + uiState.userAbsence.userId + ) + binding.outOfOfficeContainer.findViewById(R.id.userAbsencePeriod).visibility = + View.GONE + } else { + val dateFormatter = SimpleDateFormat("MMM d, yyyy", Locale.getDefault()) + val startDateString = dateFormatter.format(startDate) + val endDateString = dateFormatter.format(endDate) + binding.outOfOfficeContainer.findViewById(R.id.userAbsenceShortMessage).text = String.format( + context.resources.getString(R.string.user_absence), + uiState.userAbsence.userId + ) + + binding.outOfOfficeContainer.findViewById(R.id.userAbsencePeriod).text = "$startDateString - $endDateString" + } + + if(uiState.userAbsence.replacementUserDisplayName != null){ binding.outOfOfficeContainer.findViewById(R.id.absenceReplacement).text = String.format( context.resources.getString(R.string.user_absence_replacement), diff --git a/app/src/main/res/layout/out_of_office_view.xml b/app/src/main/res/layout/out_of_office_view.xml index 7b6bbc0a1..4d3639768 100644 --- a/app/src/main/res/layout/out_of_office_view.xml +++ b/app/src/main/res/layout/out_of_office_view.xml @@ -18,7 +18,6 @@ android:layout_height="wrap_content" android:orientation="vertical" android:padding="8dp" - android:layout_margin="8dp" android:elevation="4dp" app:cornerRadius="8dp"> @@ -26,27 +25,32 @@ android:id="@+id/userAbsenceShortMessage" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textColor="@color/scrollview_out_of_office_text" android:textSize="16sp" android:textStyle="bold" + android:layout_marginTop ="8dp" tools:text="Jane is out of office"/> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f5a5849e9..2357fd8ef 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -841,5 +841,6 @@ How to translate with transifex: Your status was set automatically %1$s is out of office and might not respond + %1$s is out of office today Replacement: %1$s