diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/EventModel.kt b/app/src/main/java/org/linphone/ui/main/chat/model/EventModel.kt index 167336caf..45070f2b3 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/model/EventModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/model/EventModel.kt @@ -27,6 +27,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext import org.linphone.R import org.linphone.core.EventLog import org.linphone.utils.AppUtils +import org.linphone.utils.LinphoneUtils class EventModel @WorkerThread constructor(private val eventLog: EventLog) { val text: String @@ -77,7 +78,7 @@ class EventModel @WorkerThread constructor(private val eventLog: EventLog) { ) EventLog.Type.ConferenceEphemeralMessageLifetimeChanged -> AppUtils.getFormattedString( R.string.conversation_event_ephemeral_messages_lifetime_changed, - formatEphemeralExpiration(eventLog.ephemeralMessageLifetime).lowercase( + LinphoneUtils.formatEphemeralExpiration(eventLog.ephemeralMessageLifetime).lowercase( Locale.getDefault() ) ) @@ -126,29 +127,4 @@ class EventModel @WorkerThread constructor(private val eventLog: EventLog) { } return name } - - @WorkerThread - private fun formatEphemeralExpiration(duration: Long): String { - return when (duration) { - 0L -> AppUtils.getString( - R.string.conversation_ephemeral_messages_duration_disabled - ) - 60L -> AppUtils.getString( - R.string.conversation_ephemeral_messages_duration_one_minute - ) - 3600L -> AppUtils.getString( - R.string.conversation_ephemeral_messages_duration_one_hour - ) - 86400L -> AppUtils.getString( - R.string.conversation_ephemeral_messages_duration_one_day - ) - 259200L -> AppUtils.getString( - R.string.conversation_ephemeral_messages_duration_three_days - ) - 604800L -> AppUtils.getString( - R.string.conversation_ephemeral_messages_duration_one_week - ) - else -> "$duration s" - } - } } diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt index 69251abdf..bdbce077a 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt @@ -80,6 +80,8 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo val ephemeralLifetime = MutableLiveData() + val ephemeralLifeTimeLabel = MutableLiveData() + val composingLabel = MutableLiveData() val searchBarVisible = MutableLiveData() @@ -247,6 +249,9 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo ephemeralLifetime.postValue( if (!chatRoom.isEphemeralEnabled) 0L else chatRoom.ephemeralLifetime ) + ephemeralLifeTimeLabel.postValue( + LinphoneUtils.formatEphemeralExpiration(chatRoom.ephemeralLifetime) + ) } @WorkerThread @@ -460,6 +465,9 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo ephemeralLifetime.postValue( if (!chatRoom.isEphemeralEnabled) 0L else chatRoom.ephemeralLifetime ) + ephemeralLifeTimeLabel.postValue( + LinphoneUtils.formatEphemeralExpiration(chatRoom.ephemeralLifetime) + ) } } @@ -575,6 +583,9 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo ephemeralLifetime.postValue( if (!chatRoom.isEphemeralEnabled) 0L else chatRoom.ephemeralLifetime ) + ephemeralLifeTimeLabel.postValue( + LinphoneUtils.formatEphemeralExpiration(chatRoom.ephemeralLifetime) + ) } @WorkerThread @@ -835,7 +846,7 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo composingFriends.add(name) label += "$name, " } - if (composingFriends.size > 0) { + if (composingFriends.isNotEmpty()) { label = label.dropLast(2) val format = AppUtils.getStringWithPlural( diff --git a/app/src/main/java/org/linphone/utils/LinphoneUtils.kt b/app/src/main/java/org/linphone/utils/LinphoneUtils.kt index e23357dcf..a0db7c3e8 100644 --- a/app/src/main/java/org/linphone/utils/LinphoneUtils.kt +++ b/app/src/main/java/org/linphone/utils/LinphoneUtils.kt @@ -316,6 +316,31 @@ class LinphoneUtils { } } + @AnyThread + fun formatEphemeralExpiration(duration: Long): String { + return when (duration) { + 0L -> AppUtils.getString( + R.string.conversation_ephemeral_messages_duration_disabled + ) + 60L -> AppUtils.getString( + R.string.conversation_ephemeral_messages_duration_one_minute + ) + 3600L -> AppUtils.getString( + R.string.conversation_ephemeral_messages_duration_one_hour + ) + 86400L -> AppUtils.getString( + R.string.conversation_ephemeral_messages_duration_one_day + ) + 259200L -> AppUtils.getString( + R.string.conversation_ephemeral_messages_duration_three_days + ) + 604800L -> AppUtils.getString( + R.string.conversation_ephemeral_messages_duration_one_week + ) + else -> "$duration s" + } + } + @WorkerThread fun getChatRoomId(room: ChatRoom): String { return getChatRoomId(room.localAddress, room.peerAddress) diff --git a/app/src/main/res/layout/chat_bubble_incoming.xml b/app/src/main/res/layout/chat_bubble_incoming.xml index ed766cc42..cdf5289e4 100644 --- a/app/src/main/res/layout/chat_bubble_incoming.xml +++ b/app/src/main/res/layout/chat_bubble_incoming.xml @@ -260,9 +260,10 @@ style="@style/default_text_style_300" android:id="@+id/countdown_clock" android:layout_width="@dimen/small_icon_size" - android:layout_height="@dimen/small_icon_size" + android:layout_height="match_parent" android:layout_marginStart="5dp" - android:layout_marginTop="2dp" + android:paddingTop="7dp" + android:layout_gravity="bottom" android:contentDescription="@null" android:src="@drawable/clock_countdown" app:tint="?attr/color_main2_600" @@ -274,7 +275,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="2dp" - android:textAlignment="textEnd" + android:layout_gravity="bottom" android:text="@{model.ephemeralLifetime, default=`00:00`}" android:textSize="12sp" android:visibility="@{model.isEphemeral ? View.VISIBLE : View.GONE, default=gone}"/> diff --git a/app/src/main/res/layout/chat_bubble_outgoing.xml b/app/src/main/res/layout/chat_bubble_outgoing.xml index 44e8a6e11..e9ead00c5 100644 --- a/app/src/main/res/layout/chat_bubble_outgoing.xml +++ b/app/src/main/res/layout/chat_bubble_outgoing.xml @@ -208,6 +208,7 @@ android:id="@+id/ephemeral_timer" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="bottom" android:text="@{model.ephemeralLifetime, default=`00:00`}" android:textSize="12sp" android:visibility="@{model.isEphemeral ? View.VISIBLE : View.GONE, default=gone}"/> @@ -216,10 +217,10 @@ style="@style/default_text_style_300" android:id="@+id/countdown_clock" android:layout_width="@dimen/small_icon_size" - android:layout_height="@dimen/small_icon_size" - android:layout_gravity="center_vertical|start" + android:layout_height="match_parent" android:layout_marginStart="2dp" - android:layout_marginTop="2dp" + android:paddingTop="7dp" + android:layout_gravity="bottom" android:contentDescription="@null" android:src="@drawable/clock_countdown" app:tint="?attr/color_main2_600" diff --git a/app/src/main/res/layout/chat_conversation_fragment.xml b/app/src/main/res/layout/chat_conversation_fragment.xml index 1ca94aa1f..9de550b1a 100644 --- a/app/src/main/res/layout/chat_conversation_fragment.xml +++ b/app/src/main/res/layout/chat_conversation_fragment.xml @@ -137,6 +137,7 @@ android:id="@+id/ephemeral_enabled" android:layout_width="@dimen/small_icon_size" android:layout_height="@dimen/small_icon_size" + android:layout_marginStart="@{viewModel.isMuted ? @dimen/five : @dimen/zero}" android:layout_marginEnd="5dp" android:src="@drawable/clock_countdown" android:contentDescription="@string/content_description_chat_ephemeral_enabled" @@ -146,6 +147,21 @@ app:layout_constraintBottom_toBottomOf="@id/avatar" app:tint="?attr/color_main1_500"/> + + 0dp + 5dp 10dp