From 08a5088c48712abfb225c543dfbffdc7eb84008c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Fri, 17 Sep 2021 12:21:18 +0200 Subject: [PATCH 1/2] Add conversation description to lobby screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: #1557 Signed-off-by: Tim Krüger --- .../main/java/com/nextcloud/talk/controllers/ChatController.kt | 3 ++- app/src/main/res/layout/lobby_view.xml | 3 ++- app/src/main/res/values/strings.xml | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 5eee74f0c..ed6c7a312 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -1127,7 +1127,8 @@ class ChatController(args: Bundle) : DateUtils.getLocalDateStringFromTimestampForLobby( currentConversation?.lobbyTimer ?: 0 - ) + ), + currentConversation!!.description ) } else { binding.lobby.lobbyTextView.setText(R.string.nc_lobby_waiting) diff --git a/app/src/main/res/layout/lobby_view.xml b/app/src/main/res/layout/lobby_view.xml index d267090c3..d16c81011 100644 --- a/app/src/main/res/layout/lobby_view.xml +++ b/app/src/main/res/layout/lobby_view.xml @@ -47,6 +47,7 @@ android:text="@string/nc_lobby_waiting" android:textAlignment="center" android:textColor="@color/grey_600" - android:textSize="16sp" /> + android:textSize="16sp" + android:autoLink="web" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5f35a4b8f..1586a051e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -350,7 +350,8 @@ Lobby Start time You are currently waiting in the lobby. - You are currently waiting in the lobby.\n This meeting is scheduled for %1$s. + You are currently waiting in the lobby.\n\nThis meeting is scheduled for + %1$s.\n\n%2$s Not set From 4e8c8eb8d757854cf2e3e1c379a41545900a385f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Fri, 17 Sep 2021 16:24:25 +0200 Subject: [PATCH 2/2] Show relative timer on lobby screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: #1557 Signed-off-by: Tim Krüger --- .../talk/controllers/ChatController.kt | 24 +++++--- .../com/nextcloud/talk/utils/DateUtils.kt | 60 ++++++++++++++++++- app/src/main/res/values/strings.xml | 4 +- 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index ed6c7a312..4b386cb81 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -1119,20 +1119,26 @@ class ChatController(args: Bundle) : binding.messageInputView.visibility = View.GONE binding.progressBar.visibility = View.GONE + val sb = StringBuilder() + sb.append(resources!!.getText(R.string.nc_lobby_waiting)) + .append("\n\n") + if (currentConversation?.lobbyTimer != null && currentConversation?.lobbyTimer != 0L ) { - binding.lobby.lobbyTextView.text = String.format( - resources!!.getString(R.string.nc_lobby_waiting_with_date), - DateUtils.getLocalDateStringFromTimestampForLobby( - currentConversation?.lobbyTimer - ?: 0 - ), - currentConversation!!.description + val timestamp = currentConversation?.lobbyTimer ?: 0 + val stringWithStartDate = String.format( + resources!!.getString(R.string.nc_lobby_start_date), + DateUtils.getLocalDateStringFromTimestampForLobby(timestamp) ) - } else { - binding.lobby.lobbyTextView.setText(R.string.nc_lobby_waiting) + val relativeTime = DateUtils.relativeStartTimeForLobby(timestamp, resources!!) + + sb.append("$stringWithStartDate - $relativeTime") + .append("\n\n") } + + sb.append(currentConversation!!.description) + binding.lobby.lobbyTextView.text = sb.toString() } else { binding.lobby.lobbyView.visibility = View.GONE binding.messagesListView.visibility = View.VISIBLE diff --git a/app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt index afa477884..201ceb5fc 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/DateUtils.kt @@ -20,12 +20,26 @@ package com.nextcloud.talk.utils +import android.content.res.Resources +import android.icu.text.RelativeDateTimeFormatter +import android.icu.text.RelativeDateTimeFormatter.Direction +import android.icu.text.RelativeDateTimeFormatter.RelativeUnit +import android.os.Build +import com.nextcloud.talk.R import java.text.DateFormat import java.util.Calendar import java.util.Date import java.util.Locale +import kotlin.math.roundToInt object DateUtils { + + private const val TIMESTAMP_CORRECTION_MULTIPLIER = 1000 + private const val SECOND_DIVIDER = 1000 + private const val MINUTES_DIVIDER = 60 + private const val HOURS_DIVIDER = 60 + private const val DAYS_DIVIDER = 24 + fun getLocalDateTimeStringFromTimestamp(timestamp: Long): String { val cal = Calendar.getInstance() val tz = cal.timeZone @@ -41,6 +55,50 @@ object DateUtils { } fun getLocalDateStringFromTimestampForLobby(timestamp: Long): String { - return getLocalDateTimeStringFromTimestamp(timestamp * 1000) + return getLocalDateTimeStringFromTimestamp(timestamp * TIMESTAMP_CORRECTION_MULTIPLIER) + } + + fun relativeStartTimeForLobby(timestamp: Long, resources: Resources): String { + + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + val fmt = RelativeDateTimeFormatter.getInstance() + val timeLeftMillis = timestamp * TIMESTAMP_CORRECTION_MULTIPLIER - System.currentTimeMillis() + val minutes = timeLeftMillis.toDouble() / SECOND_DIVIDER / MINUTES_DIVIDER + val hours = minutes / HOURS_DIVIDER + val days = hours / DAYS_DIVIDER + + val minutesInt = minutes.roundToInt() + val hoursInt = hours.roundToInt() + val daysInt = days.roundToInt() + + when { + daysInt > 0 -> { + fmt.format( + daysInt.toDouble(), + Direction.NEXT, + RelativeUnit.DAYS + ) + } + hoursInt > 0 -> { + fmt.format( + hoursInt.toDouble(), + Direction.NEXT, + RelativeUnit.HOURS + ) + } + minutesInt > 1 -> { + fmt.format( + minutesInt.toDouble(), + Direction.NEXT, + RelativeUnit.MINUTES + ) + } + else -> { + resources.getString(R.string.nc_lobby_start_soon) + } + } + } else { + "" + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1586a051e..0ce32898d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -350,8 +350,8 @@ Lobby Start time You are currently waiting in the lobby. - You are currently waiting in the lobby.\n\nThis meeting is scheduled for - %1$s.\n\n%2$s + This meeting is scheduled for %1$s + The meeting will start soon Not set