From 0980a41752377b68a3c2ea8551fc38986f49071f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 2 Jul 2019 14:59:44 +0200 Subject: [PATCH] use file name with extension --- .../java/im/vector/riotredesign/core/intent/Filename.kt | 4 ++-- .../features/home/room/detail/RoomDetailViewModel.kt | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/core/intent/Filename.kt b/vector/src/main/java/im/vector/riotredesign/core/intent/Filename.kt index eba9d01b..78a04716 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/intent/Filename.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/intent/Filename.kt @@ -21,9 +21,9 @@ import android.database.Cursor import android.net.Uri import android.provider.OpenableColumns -fun getFilenameFromUri(context: Context, uri: Uri): String? { +fun getFilenameFromUri(context: Context?, uri: Uri): String? { var result: String? = null - if (uri.scheme == "content") { + if (context != null && uri.scheme == "content") { val cursor: Cursor? = context.contentResolver.query(uri, null, null, null, null) try { if (cursor != null && cursor.moveToFirst()) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewModel.kt index 8d23ac0f..805843c6 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewModel.kt @@ -16,6 +16,7 @@ package im.vector.riotredesign.features.home.room.detail +import android.net.Uri import android.text.TextUtils import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -36,6 +37,7 @@ import im.vector.matrix.android.api.session.room.model.message.MessageType import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.matrix.rx.rx import im.vector.riotredesign.R +import im.vector.riotredesign.core.intent.getFilenameFromUri import im.vector.riotredesign.core.platform.VectorViewModel import im.vector.riotredesign.core.resources.UserPreferencesProvider import im.vector.riotredesign.core.utils.LiveEvent @@ -360,13 +362,15 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro private fun handleSendMedia(action: RoomDetailActions.SendMedia) { val attachments = action.mediaFiles.map { + val nameWithExtension = getFilenameFromUri(null, Uri.parse(it.path)) + ContentAttachmentData( size = it.size, duration = it.duration, date = it.date, height = it.height, width = it.width, - name = it.name, + name = nameWithExtension ?: it.name, path = it.path, mimeType = it.mimeType, type = ContentAttachmentData.Type.values()[it.mediaType]