mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-04-21 03:38:29 +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.AppUtils
|
||||||
import org.linphone.utils.AudioRouteUtils
|
import org.linphone.utils.AudioRouteUtils
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
import org.linphone.utils.FileUtils
|
|
||||||
import org.linphone.utils.LinphoneUtils
|
import org.linphone.utils.LinphoneUtils
|
||||||
import org.linphone.utils.PatternClickableSpan
|
import org.linphone.utils.PatternClickableSpan
|
||||||
import org.linphone.utils.SpannableClickedListener
|
import org.linphone.utils.SpannableClickedListener
|
||||||
|
|
@ -199,7 +198,7 @@ class ChatMessageModel @WorkerThread constructor(
|
||||||
)
|
)
|
||||||
when (content.type) {
|
when (content.type) {
|
||||||
"image", "video" -> {
|
"image", "video" -> {
|
||||||
val fileModel = FileModel(path, "") { file ->
|
val fileModel = FileModel(path, content.fileSize.toLong()) { file ->
|
||||||
onContentClicked?.invoke(file)
|
onContentClicked?.invoke(file)
|
||||||
}
|
}
|
||||||
filesPath.add(fileModel)
|
filesPath.add(fileModel)
|
||||||
|
|
@ -223,10 +222,7 @@ class ChatMessageModel @WorkerThread constructor(
|
||||||
displayableContentFound = true
|
displayableContentFound = true
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val size = FileUtils.bytesToDisplayableSize(
|
val fileModel = FileModel(path, content.fileSize.toLong()) { file ->
|
||||||
content.fileSize.toLong()
|
|
||||||
)
|
|
||||||
val fileModel = FileModel(path, size) { file ->
|
|
||||||
onContentClicked?.invoke(file)
|
onContentClicked?.invoke(file)
|
||||||
}
|
}
|
||||||
filesPath.add(fileModel)
|
filesPath.add(fileModel)
|
||||||
|
|
@ -235,8 +231,19 @@ class ChatMessageModel @WorkerThread constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.i("$TAG Content path is empty : have to download it first")
|
Log.e("$TAG No path found for File Content!")
|
||||||
// TODO: download it
|
}
|
||||||
|
} 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 {
|
} else {
|
||||||
Log.i("$TAG Content is not a File")
|
Log.i("$TAG Content is not a File")
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ import org.linphone.utils.FileUtils
|
||||||
|
|
||||||
class FileModel @AnyThread constructor(
|
class FileModel @AnyThread constructor(
|
||||||
val file: String,
|
val file: String,
|
||||||
val fileSize: String,
|
fileSize: Long,
|
||||||
|
val isWaitingToBeDownloaded: Boolean = false,
|
||||||
private val onClicked: ((file: String) -> Unit)? = null
|
private val onClicked: ((file: String) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -18,6 +19,8 @@ class FileModel @AnyThread constructor(
|
||||||
|
|
||||||
val fileName: String = FileUtils.getNameFromFilePath(file)
|
val fileName: String = FileUtils.getNameFromFilePath(file)
|
||||||
|
|
||||||
|
val formattedFileSize = MutableLiveData<String>()
|
||||||
|
|
||||||
val path = MutableLiveData<String>()
|
val path = MutableLiveData<String>()
|
||||||
|
|
||||||
val mimeType: FileUtils.MimeType
|
val mimeType: FileUtils.MimeType
|
||||||
|
|
@ -30,7 +33,9 @@ class FileModel @AnyThread constructor(
|
||||||
|
|
||||||
init {
|
init {
|
||||||
path.postValue(file)
|
path.postValue(file)
|
||||||
|
formattedFileSize.postValue(FileUtils.bytesToDisplayableSize(fileSize))
|
||||||
|
|
||||||
|
if (!isWaitingToBeDownloaded) {
|
||||||
val extension = FileUtils.getExtensionFromFileName(file)
|
val extension = FileUtils.getExtensionFromFileName(file)
|
||||||
isPdf = extension == "pdf"
|
isPdf = extension == "pdf"
|
||||||
|
|
||||||
|
|
@ -38,6 +43,12 @@ class FileModel @AnyThread constructor(
|
||||||
mimeType = FileUtils.getMimeType(mime)
|
mimeType = FileUtils.getMimeType(mime)
|
||||||
isImage = mimeType == FileUtils.MimeType.Image
|
isImage = mimeType == FileUtils.MimeType.Image
|
||||||
isVideoPreview = mimeType == FileUtils.MimeType.Video
|
isVideoPreview = mimeType == FileUtils.MimeType.Video
|
||||||
|
} else {
|
||||||
|
mimeType = FileUtils.MimeType.Unknown
|
||||||
|
isPdf = false
|
||||||
|
isImage = false
|
||||||
|
isVideoPreview = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@ class SendMessageInConversationViewModel @UiThread constructor() : ViewModel() {
|
||||||
fun addAttachment(file: String) {
|
fun addAttachment(file: String) {
|
||||||
val list = arrayListOf<FileModel>()
|
val list = arrayListOf<FileModel>()
|
||||||
list.addAll(attachments.value.orEmpty())
|
list.addAll(attachments.value.orEmpty())
|
||||||
val model = FileModel(file, "") { file ->
|
val model = FileModel(file, 0) { file ->
|
||||||
removeAttachment(file)
|
removeAttachment(file)
|
||||||
}
|
}
|
||||||
list.add(model)
|
list.add(model)
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
android:layout_height="@dimen/chat_bubble_grid_image_size"
|
android:layout_height="@dimen/chat_bubble_grid_image_size"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:padding="18dp"
|
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"
|
android:background="@drawable/shape_squircle_main2_200_left"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
|
@ -93,7 +93,7 @@
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp"
|
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:textColor="@color/gray_main2_600"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:onLongClick="@{onLongClickListener}"
|
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:alignItems="center"
|
||||||
app:flexWrap="wrap"
|
app:flexWrap="wrap"
|
||||||
app:justifyContent="@{model.outgoing ? JustifyContent.FLEX_END : JustifyContent.FLEX_START}"
|
app:justifyContent="@{model.outgoing ? JustifyContent.FLEX_END : JustifyContent.FLEX_START}"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue