mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Fixed sent files size missing
This commit is contained in:
parent
5256ee79c6
commit
1833b1985d
4 changed files with 38 additions and 12 deletions
|
|
@ -92,7 +92,7 @@ class FileModel
|
|||
|
||||
init {
|
||||
updateTransferProgress(-1)
|
||||
formattedFileSize.postValue(FileUtils.bytesToDisplayableSize(fileSize))
|
||||
computeFileSize(fileSize)
|
||||
|
||||
if (!isWaitingToBeDownloaded) {
|
||||
val extension = FileUtils.getExtensionFromFileName(path)
|
||||
|
|
@ -141,6 +141,11 @@ class FileModel
|
|||
}
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun computeFileSize(fileSize: Long) {
|
||||
formattedFileSize.postValue(FileUtils.bytesToDisplayableSize(fileSize))
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun updateTransferProgress(percent: Int) {
|
||||
transferProgress.postValue(percent)
|
||||
|
|
|
|||
|
|
@ -217,13 +217,13 @@ class MessageModel
|
|||
transferringFileModel = null
|
||||
if (!allFilesDownloaded) {
|
||||
computeContentsList()
|
||||
}
|
||||
|
||||
for (content in message.contents) {
|
||||
if (content.isVoiceRecording) {
|
||||
Log.i("$TAG File transfer done, updating voice record info")
|
||||
computeVoiceRecordContent(content)
|
||||
break
|
||||
} else {
|
||||
for (content in message.contents) {
|
||||
if (content.isVoiceRecording) {
|
||||
Log.i("$TAG File transfer done, updating voice record info")
|
||||
computeVoiceRecordContent(content)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -406,7 +406,7 @@ class MessageModel
|
|||
private fun computeContentsList() {
|
||||
Log.d("$TAG Computing message contents list")
|
||||
text.postValue(Spannable.Factory.getInstance().newSpannable(""))
|
||||
filesList.postValue(arrayListOf())
|
||||
filesList.value.orEmpty().forEach(FileModel::destroy)
|
||||
|
||||
var displayableContentFound = false
|
||||
var contentIndex = 0
|
||||
|
|
@ -461,7 +461,11 @@ class MessageModel
|
|||
Log.d(
|
||||
"$TAG Found file ready to be displayed [$path] with MIME [${content.type}/${content.subtype}] for message [${chatMessage.messageId}]"
|
||||
)
|
||||
val fileSize = content.fileSize.toLong()
|
||||
val fileSize = if (content.fileSize.toLong() > 0) {
|
||||
content.fileSize.toLong()
|
||||
} else {
|
||||
FileUtils.getFileSize(path)
|
||||
}
|
||||
val timestamp = content.creationTimestamp
|
||||
val fileModel = FileModel(
|
||||
path,
|
||||
|
|
@ -492,10 +496,15 @@ class MessageModel
|
|||
if (name.isNotEmpty()) {
|
||||
val fileModel = if (isOutgoing && chatMessage.isFileTransferInProgress) {
|
||||
val path = content.filePath.orEmpty()
|
||||
val fileSize = if (content.fileSize.toLong() > 0) {
|
||||
content.fileSize.toLong()
|
||||
} else {
|
||||
FileUtils.getFileSize(path)
|
||||
}
|
||||
FileModel(
|
||||
path,
|
||||
name,
|
||||
content.fileSize.toLong(),
|
||||
fileSize,
|
||||
timestamp,
|
||||
isFileEncrypted,
|
||||
path,
|
||||
|
|
|
|||
|
|
@ -401,7 +401,8 @@ class SendMessageInConversationViewModel
|
|||
|
||||
val fileName = FileUtils.getNameFromFilePath(file)
|
||||
val timestamp = System.currentTimeMillis() / 1000
|
||||
val model = FileModel(file, fileName, 0, timestamp, false, file, false) { model ->
|
||||
val size = FileUtils.getFileSize(file)
|
||||
val model = FileModel(file, fileName, size, timestamp, false, file, false) { model ->
|
||||
removeAttachment(model.path)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,17 @@ class FileUtils {
|
|||
return Formatter.formatShortFileSize(coreContext.context, bytes)
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun getFileSize(filePath: String): Long {
|
||||
try {
|
||||
val file = File(filePath)
|
||||
return file.length()
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Failed to get file [$filePath] size: $e")
|
||||
}
|
||||
return 0L
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun isExtensionImage(path: String): Boolean {
|
||||
val extension = getExtensionFromFileName(path)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue