mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-24 14:05:40 +03:00
Merge pull request #1589 from nextcloud/feature/1557/show-lobby-timer-and-description-in-lobby-screen
Show lobby timer and description in lobby screen
This commit is contained in:
commit
f96392d05c
4 changed files with 78 additions and 11 deletions
|
@ -1119,19 +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
|
||||
)
|
||||
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
|
||||
|
|
|
@ -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 {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -353,7 +353,8 @@
|
|||
<string name="nc_lobby">Lobby</string>
|
||||
<string name="nc_start_time">Start time</string>
|
||||
<string name="nc_lobby_waiting">You are currently waiting in the lobby.</string>
|
||||
<string name="nc_lobby_waiting_with_date">You are currently waiting in the lobby.\n This meeting is scheduled for %1$s.</string>
|
||||
<string name="nc_lobby_start_date">This meeting is scheduled for %1$s</string>
|
||||
<string name="nc_lobby_start_soon">The meeting will start soon</string>
|
||||
<string name="nc_manual">Not set</string>
|
||||
|
||||
<!-- Errors -->
|
||||
|
|
Loading…
Reference in a new issue