mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-02-01 03:09:22 +00:00
Improved multiple files upload/sending chat bubble
This commit is contained in:
parent
4098827253
commit
e438617241
3 changed files with 34 additions and 26 deletions
|
|
@ -29,7 +29,7 @@ class FileModel @AnyThread constructor(
|
|||
|
||||
val formattedFileSize = MutableLiveData<String>()
|
||||
|
||||
val downloadProgress = MutableLiveData<Int>()
|
||||
val transferProgress = MutableLiveData<Int>()
|
||||
|
||||
val mimeType: FileUtils.MimeType
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ class FileModel @AnyThread constructor(
|
|||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
init {
|
||||
downloadProgress.postValue(-1)
|
||||
transferProgress.postValue(-1)
|
||||
formattedFileSize.postValue(FileUtils.bytesToDisplayableSize(fileSize))
|
||||
|
||||
if (!isWaitingToBeDownloaded) {
|
||||
|
|
|
|||
|
|
@ -171,21 +171,27 @@ class MessageModel @WorkerThread constructor(
|
|||
|
||||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
private var downloadingFileModel: FileModel? = null
|
||||
private var transferringFileModel: FileModel? = null
|
||||
|
||||
private var allFilesDownloaded = true
|
||||
|
||||
private val chatMessageListener = object : ChatMessageListenerStub() {
|
||||
@WorkerThread
|
||||
override fun onMsgStateChanged(message: ChatMessage, messageState: ChatMessage.State?) {
|
||||
statusIcon.postValue(LinphoneUtils.getChatIconResId(chatMessage.state))
|
||||
if (messageState != ChatMessage.State.FileTransferDone && messageState != ChatMessage.State.FileTransferInProgress) {
|
||||
statusIcon.postValue(LinphoneUtils.getChatIconResId(chatMessage.state))
|
||||
|
||||
if (messageState == ChatMessage.State.FileTransferDone) {
|
||||
if (messageState == ChatMessage.State.Displayed) {
|
||||
isRead = chatMessage.isRead
|
||||
}
|
||||
} else if (messageState == ChatMessage.State.FileTransferDone) {
|
||||
Log.i("$TAG File transfer is done")
|
||||
downloadingFileModel?.downloadProgress?.postValue(-1)
|
||||
downloadingFileModel = null
|
||||
computeContentsList()
|
||||
transferringFileModel?.transferProgress?.postValue(-1)
|
||||
transferringFileModel = null
|
||||
if (!allFilesDownloaded) {
|
||||
computeContentsList()
|
||||
}
|
||||
}
|
||||
|
||||
isRead = chatMessage.isRead
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
@ -209,17 +215,16 @@ class MessageModel @WorkerThread constructor(
|
|||
offset: Int,
|
||||
total: Int
|
||||
) {
|
||||
val model = downloadingFileModel
|
||||
if (model != null) {
|
||||
val percent = ((offset * 100.0) / total).toInt() // Conversion from int to double and back to int is required
|
||||
model.downloadProgress.postValue(percent)
|
||||
} else {
|
||||
Log.w("$TAG A file is being downloaded but no downloadingFileModel set!")
|
||||
val percent = ((offset * 100.0) / total).toInt() // Conversion from int to double and back to int is required
|
||||
|
||||
val model = transferringFileModel
|
||||
if (model == null) {
|
||||
Log.w("$TAG A file is being uploaded/downloaded but no transferringFileModel set!")
|
||||
val found = filesList.value.orEmpty().find {
|
||||
it.fileName == content.name
|
||||
}
|
||||
if (found != null) {
|
||||
downloadingFileModel = found
|
||||
transferringFileModel = found
|
||||
Log.i("$TAG Found matching FileModel in files list using content name")
|
||||
} else {
|
||||
Log.w(
|
||||
|
|
@ -227,6 +232,7 @@ class MessageModel @WorkerThread constructor(
|
|||
)
|
||||
}
|
||||
}
|
||||
model?.transferProgress?.postValue(percent)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -314,6 +320,7 @@ class MessageModel @WorkerThread constructor(
|
|||
val filesPath = arrayListOf<FileModel>()
|
||||
|
||||
val contents = chatMessage.contents
|
||||
allFilesDownloaded = true
|
||||
for (content in contents) {
|
||||
val isFileEncrypted = content.isFileEncrypted
|
||||
|
||||
|
|
@ -388,6 +395,7 @@ class MessageModel @WorkerThread constructor(
|
|||
Log.d(
|
||||
"$TAG Found file content (not downloaded yet) with type [${content.type}/${content.subtype}] and name [${content.name}]"
|
||||
)
|
||||
allFilesDownloaded = false
|
||||
filesContentCount += 1
|
||||
val name = content.name ?: ""
|
||||
if (name.isNotEmpty()) {
|
||||
|
|
@ -439,8 +447,8 @@ class MessageModel @WorkerThread constructor(
|
|||
"$TAG File [$contentName] will be downloaded at [${content.filePath}]"
|
||||
)
|
||||
|
||||
model.downloadProgress.postValue(0)
|
||||
downloadingFileModel = model
|
||||
model.transferProgress.postValue(0)
|
||||
transferringFileModel = model
|
||||
chatMessage.downloadContent(content)
|
||||
} else {
|
||||
Log.e("$TAG Content name is null, can't download it!")
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
android:id="@+id/file_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="@{model.isImage || model.isVideoPreview ? View.GONE : View.VISIBLE, default=gone}"
|
||||
android:visibility="@{model.isImage || model.isVideoPreview ? View.GONE : View.VISIBLE}"
|
||||
app:constraint_referenced_ids="file_name, file_size, file_background, file_icon" />
|
||||
|
||||
<ImageView
|
||||
|
|
@ -80,19 +80,19 @@
|
|||
app:tint="?attr/color_main2_600" />
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
android:id="@+id/download_progress"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:id="@+id/transfer_progress"
|
||||
android:layout_width="@dimen/chat_bubble_grid_image_size"
|
||||
android:layout_height="@dimen/chat_bubble_grid_image_size"
|
||||
android:padding="18dp"
|
||||
android:indeterminate="false"
|
||||
android:progress="@{model.downloadProgress}"
|
||||
android:progress="@{model.transferProgress}"
|
||||
android:max="100"
|
||||
android:visibility="@{!model.isWaitingToBeDownloaded || model.downloadProgress == -1 || model.downloadProgress >= 100 ? View.GONE : View.VISIBLE}"
|
||||
android:visibility="@{model.transferProgress == -1 || model.transferProgress >= 100 ? View.GONE : View.VISIBLE}"
|
||||
app:trackColor="?attr/color_main1_100"
|
||||
app:indicatorColor="?attr/color_main1_500"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@id/file_icon"
|
||||
tools:progress="40" />
|
||||
|
||||
<View
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue