use file name with extension

This commit is contained in:
Benoit Marty 2019-07-02 14:59:44 +02:00
parent 18a821f3f6
commit 0980a41752
2 changed files with 7 additions and 3 deletions

View File

@ -21,9 +21,9 @@ import android.database.Cursor
import android.net.Uri import android.net.Uri
import android.provider.OpenableColumns import android.provider.OpenableColumns


fun getFilenameFromUri(context: Context, uri: Uri): String? { fun getFilenameFromUri(context: Context?, uri: Uri): String? {
var result: String? = null 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) val cursor: Cursor? = context.contentResolver.query(uri, null, null, null, null)
try { try {
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {

View File

@ -16,6 +16,7 @@


package im.vector.riotredesign.features.home.room.detail package im.vector.riotredesign.features.home.room.detail


import android.net.Uri
import android.text.TextUtils import android.text.TextUtils
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData 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.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.rx.rx import im.vector.matrix.rx.rx
import im.vector.riotredesign.R import im.vector.riotredesign.R
import im.vector.riotredesign.core.intent.getFilenameFromUri
import im.vector.riotredesign.core.platform.VectorViewModel import im.vector.riotredesign.core.platform.VectorViewModel
import im.vector.riotredesign.core.resources.UserPreferencesProvider import im.vector.riotredesign.core.resources.UserPreferencesProvider
import im.vector.riotredesign.core.utils.LiveEvent import im.vector.riotredesign.core.utils.LiveEvent
@ -360,13 +362,15 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro


private fun handleSendMedia(action: RoomDetailActions.SendMedia) { private fun handleSendMedia(action: RoomDetailActions.SendMedia) {
val attachments = action.mediaFiles.map { val attachments = action.mediaFiles.map {
val nameWithExtension = getFilenameFromUri(null, Uri.parse(it.path))

ContentAttachmentData( ContentAttachmentData(
size = it.size, size = it.size,
duration = it.duration, duration = it.duration,
date = it.date, date = it.date,
height = it.height, height = it.height,
width = it.width, width = it.width,
name = it.name, name = nameWithExtension ?: it.name,
path = it.path, path = it.path,
mimeType = it.mimeType, mimeType = it.mimeType,
type = ContentAttachmentData.Type.values()[it.mediaType] type = ContentAttachmentData.Type.values()[it.mediaType]