mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Added layout for not downloaded file
This commit is contained in:
parent
6ae57158b7
commit
a8aa3be08a
5 changed files with 37 additions and 19 deletions
|
|
@ -53,7 +53,6 @@ import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
|||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.AudioRouteUtils
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.FileUtils
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
import org.linphone.utils.PatternClickableSpan
|
||||
import org.linphone.utils.SpannableClickedListener
|
||||
|
|
@ -199,7 +198,7 @@ class ChatMessageModel @WorkerThread constructor(
|
|||
)
|
||||
when (content.type) {
|
||||
"image", "video" -> {
|
||||
val fileModel = FileModel(path, "") { file ->
|
||||
val fileModel = FileModel(path, content.fileSize.toLong()) { file ->
|
||||
onContentClicked?.invoke(file)
|
||||
}
|
||||
filesPath.add(fileModel)
|
||||
|
|
@ -223,10 +222,7 @@ class ChatMessageModel @WorkerThread constructor(
|
|||
displayableContentFound = true
|
||||
}
|
||||
else -> {
|
||||
val size = FileUtils.bytesToDisplayableSize(
|
||||
content.fileSize.toLong()
|
||||
)
|
||||
val fileModel = FileModel(path, size) { file ->
|
||||
val fileModel = FileModel(path, content.fileSize.toLong()) { file ->
|
||||
onContentClicked?.invoke(file)
|
||||
}
|
||||
filesPath.add(fileModel)
|
||||
|
|
@ -235,8 +231,19 @@ class ChatMessageModel @WorkerThread constructor(
|
|||
}
|
||||
}
|
||||
} else {
|
||||
Log.i("$TAG Content path is empty : have to download it first")
|
||||
// TODO: download it
|
||||
Log.e("$TAG No path found for File Content!")
|
||||
}
|
||||
} else if (content.isFileTransfer) {
|
||||
val name = content.name ?: ""
|
||||
if (name.isNotEmpty()) {
|
||||
val fileModel = FileModel(name, content.fileSize.toLong(), true) { file ->
|
||||
onContentClicked?.invoke(file)
|
||||
}
|
||||
filesPath.add(fileModel)
|
||||
|
||||
displayableContentFound = true
|
||||
} else {
|
||||
Log.e("$TAG No name found for FileTransfer Content!")
|
||||
}
|
||||
} else {
|
||||
Log.i("$TAG Content is not a File")
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import org.linphone.utils.FileUtils
|
|||
|
||||
class FileModel @AnyThread constructor(
|
||||
val file: String,
|
||||
val fileSize: String,
|
||||
fileSize: Long,
|
||||
val isWaitingToBeDownloaded: Boolean = false,
|
||||
private val onClicked: ((file: String) -> Unit)? = null
|
||||
) {
|
||||
companion object {
|
||||
|
|
@ -18,6 +19,8 @@ class FileModel @AnyThread constructor(
|
|||
|
||||
val fileName: String = FileUtils.getNameFromFilePath(file)
|
||||
|
||||
val formattedFileSize = MutableLiveData<String>()
|
||||
|
||||
val path = MutableLiveData<String>()
|
||||
|
||||
val mimeType: FileUtils.MimeType
|
||||
|
|
@ -30,14 +33,22 @@ class FileModel @AnyThread constructor(
|
|||
|
||||
init {
|
||||
path.postValue(file)
|
||||
formattedFileSize.postValue(FileUtils.bytesToDisplayableSize(fileSize))
|
||||
|
||||
val extension = FileUtils.getExtensionFromFileName(file)
|
||||
isPdf = extension == "pdf"
|
||||
if (!isWaitingToBeDownloaded) {
|
||||
val extension = FileUtils.getExtensionFromFileName(file)
|
||||
isPdf = extension == "pdf"
|
||||
|
||||
val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
mimeType = FileUtils.getMimeType(mime)
|
||||
isImage = mimeType == FileUtils.MimeType.Image
|
||||
isVideoPreview = mimeType == FileUtils.MimeType.Video
|
||||
val mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
|
||||
mimeType = FileUtils.getMimeType(mime)
|
||||
isImage = mimeType == FileUtils.MimeType.Image
|
||||
isVideoPreview = mimeType == FileUtils.MimeType.Video
|
||||
} else {
|
||||
mimeType = FileUtils.MimeType.Unknown
|
||||
isPdf = false
|
||||
isImage = false
|
||||
isVideoPreview = false
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ class SendMessageInConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
fun addAttachment(file: String) {
|
||||
val list = arrayListOf<FileModel>()
|
||||
list.addAll(attachments.value.orEmpty())
|
||||
val model = FileModel(file, "") { file ->
|
||||
val model = FileModel(file, 0) { file ->
|
||||
removeAttachment(file)
|
||||
}
|
||||
list.add(model)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
android:layout_height="@dimen/chat_bubble_grid_image_size"
|
||||
android:adjustViewBounds="true"
|
||||
android:padding="18dp"
|
||||
android:src="@{model.isPdf ? @drawable/file_pdf : @drawable/file, default=@drawable/file_pdf}"
|
||||
android:src="@{model.isWaitingToBeDownloaded ? @drawable/download_simple : model.isPdf ? @drawable/file_pdf : @drawable/file, default=@drawable/file_pdf}"
|
||||
android:background="@drawable/shape_squircle_main2_200_left"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="@{model.fileSize, default=`42 kb`}"
|
||||
android:text="@{model.formattedFileSize, default=`42 kb`}"
|
||||
android:textColor="@color/gray_main2_600"
|
||||
android:textSize="12sp"
|
||||
android:maxLines="1"
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onLongClick="@{onLongClickListener}"
|
||||
android:visibility="@{model.filesList.size() >= 2 ? View.VISIBLE : View.GONE, default=gone}"
|
||||
android:visibility="@{model.filesList.size() >= 2 || (model.filesList.size() >= 1 && model.firstImage.path.length() == 0) ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:alignItems="center"
|
||||
app:flexWrap="wrap"
|
||||
app:justifyContent="@{model.outgoing ? JustifyContent.FLEX_END : JustifyContent.FLEX_START}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue