Fixed IMDN status when file transfer goes into error state

This commit is contained in:
Sylvain Berfini 2022-12-08 10:09:55 +01:00
parent df8cd8c2cb
commit 5b3460d1e7
4 changed files with 23 additions and 25 deletions

View file

@ -66,9 +66,8 @@ class ChatMessageContentData(
val filePath = MutableLiveData<String>()
val downloadable = MutableLiveData<Boolean>()
val downloadEnabled = MutableLiveData<Boolean>()
val downloadProgressInt = MutableLiveData<Int>()
val downloadProgressString = MutableLiveData<String>()
val fileTransferProgress = MutableLiveData<Boolean>()
val fileTransferProgressInt = MutableLiveData<Int>()
val downloadLabel = MutableLiveData<Spannable>()
val voiceRecordDuration = MutableLiveData<Int>()
@ -118,18 +117,18 @@ class ChatMessageContentData(
total: Int
) {
if (c.filePath == getContent().filePath) {
val percent = offset * 100 / total
Log.d("[Content] Download progress is: $offset / $total ($percent%)")
downloadProgressInt.value = percent
downloadProgressString.value = "$percent%"
if (fileTransferProgress.value == false) {
fileTransferProgress.value = true
}
val percent = ((offset * 100.0) / total).toInt() // Conversion from int to double and back to int is required
Log.d("[Content] Transfer progress is: $offset / $total -> $percent%")
fileTransferProgressInt.value = percent
}
}
override fun onMsgStateChanged(message: ChatMessage, state: ChatMessage.State) {
downloadEnabled.value = state != ChatMessage.State.FileTransferInProgress
if (state == ChatMessage.State.FileTransferDone || state == ChatMessage.State.FileTransferError) {
fileTransferProgress.value = false
updateContent()
if (state == ChatMessage.State.FileTransferDone) {
@ -149,6 +148,8 @@ class ChatMessageContentData(
isVoiceRecordPlaying.value = false
voiceRecordDuration.value = 0
voiceRecordPlayingPosition.value = 0
fileTransferProgress.value = false
fileTransferProgressInt.value = 0
updateContent()
chatMessage.addListener(chatMessageListener)
@ -191,7 +192,6 @@ class ChatMessageContentData(
Log.w("[Content] File path already set [$filePath] using it (auto download that failed probably)")
}
downloadEnabled.value = false
if (!chatMessage.downloadContent(content)) {
Log.e("[Content] Failed to start content download!")
}
@ -303,9 +303,6 @@ class ChatMessageContentData(
}
isGenericFile.value = !isPdf.value!! && !isAudio.value!! && !isVideo.value!! && !isImage.value!! && !isVoiceRecording.value!! && !isConferenceSchedule.value!!
downloadEnabled.value = !chatMessage.isFileTransferInProgress
downloadProgressInt.value = 0
downloadProgressString.value = "0%"
}
private fun parseConferenceInvite(content: Content) {

View file

@ -38,8 +38,6 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
val sendInProgress = MutableLiveData<Boolean>()
val transferInProgress = MutableLiveData<Boolean>()
val showImdn = MutableLiveData<Boolean>()
val imdnIcon = MutableLiveData<Int>()
@ -157,18 +155,21 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
}
private fun updateChatMessageState(state: ChatMessage.State) {
transferInProgress.value = state == ChatMessage.State.FileTransferInProgress
sendInProgress.value = state == ChatMessage.State.InProgress || state == ChatMessage.State.FileTransferInProgress
sendInProgress.value = when (state) {
ChatMessage.State.InProgress, ChatMessage.State.FileTransferInProgress, ChatMessage.State.FileTransferDone -> true
else -> false
}
showImdn.value = when (state) {
ChatMessage.State.DeliveredToUser, ChatMessage.State.Displayed, ChatMessage.State.NotDelivered -> true
ChatMessage.State.DeliveredToUser, ChatMessage.State.Displayed,
ChatMessage.State.NotDelivered, ChatMessage.State.FileTransferError -> true
else -> false
}
imdnIcon.value = when (state) {
ChatMessage.State.DeliveredToUser -> R.drawable.chat_delivered
ChatMessage.State.Displayed -> R.drawable.chat_read
ChatMessage.State.FileTransferError, ChatMessage.State.NotDelivered -> R.drawable.chat_error
else -> R.drawable.chat_error
}

View file

@ -90,20 +90,20 @@
<com.google.android.material.progressindicator.CircularProgressIndicator
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="@{data.downloadProgressInt > 0 ? View.VISIBLE : View.GONE, default=gone}"
android:visibility="@{data.fileTransferProgress ? View.VISIBLE : View.GONE, default=gone}"
android:max="100"
android:layout_centerInParent="true"
app:trackColor="?attr/backgroundColor"
android:progress="@{data.downloadProgressInt, default=50}"
android:progress="@{data.fileTransferProgressInt, default=50}"
android:background="@drawable/background_round_secondary_color" />
<TextView
android:visibility="@{data.downloadProgressInt > 0 ? View.VISIBLE : View.GONE, default=gone}"
android:visibility="@{data.fileTransferProgress ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@style/file_transfer_progress_font"
android:text="@{data.downloadProgressString, default=`50%`}"/>
android:text="@{data.fileTransferProgressInt + `%`, default=`50%`}"/>
</RelativeLayout>

View file

@ -206,7 +206,7 @@
android:layout_alignBottom="@id/background"
android:layout_toRightOf="@id/background"
android:indeterminateTint="?attr/accentColor"
android:visibility="@{data.transferInProgress || data.sendInProgress ? View.VISIBLE : View.GONE}" />
android:visibility="@{data.sendInProgress ? View.VISIBLE : View.GONE}" />
</RelativeLayout>