Code review

This commit is contained in:
Valere 2020-09-03 14:53:13 +02:00
parent 8340d5e71f
commit 7c638798c7
5 changed files with 9 additions and 11 deletions

View file

@ -34,7 +34,7 @@ interface VideoLoaderTarget {
fun onVideoFileLoading(uid: String)
fun onVideoFileLoadFailed(uid: String)
fun onVideoURLReady(uid: String, file: File)
fun onVideoFileReady(uid: String, file: File)
fun onVideoURLReady(uid: String, path: String)
}
@ -67,16 +67,16 @@ internal class DefaultVideoLoaderTarget(val holder: VideoViewHolder, private val
holder.videoFileLoadError()
}
override fun onVideoURLReady(uid: String, file: File) {
override fun onVideoFileReady(uid: String, file: File) {
if (holder.boundResourceUid != uid) return
arrangeForVideoReady()
holder.videoReady(file)
}
override fun onVideoURLReady(uid: String, contentPath: String) {
override fun onVideoURLReady(uid: String, path: String) {
if (holder.boundResourceUid != uid) return
arrangeForVideoReady()
holder.videoReady(contentPath)
holder.videoReady(path)
}
private fun arrangeForVideoReady() {

View file

@ -21,7 +21,6 @@ import android.util.Base64
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull
import org.junit.FixMethodOrder
import org.junit.Test
import org.junit.runner.RunWith

View file

@ -992,7 +992,7 @@ class RoomDetailViewModel @AssistedInject constructor(
private fun handleOpenOrDownloadFile(action: RoomDetailAction.DownloadOrOpen) {
val mxcUrl = action.messageFileContent.getFileUrl()
val isLocalSendingFile = action.senderId == session.myUserId
&& action.messageFileContent.getFileUrl()?.startsWith("content://") ?: false
&& mxcUrl?.startsWith("content://") ?: false
val isDownloaded = mxcUrl?.let { session.fileService().isFileInCache(it, action.messageFileContent.mimeType) } ?: false
if (isLocalSendingFile) {
tryThis { Uri.parse(mxcUrl) }?.let {

View file

@ -27,7 +27,6 @@ import im.vector.lib.attachmentviewer.AttachmentSourceProvider
import im.vector.lib.attachmentviewer.ImageLoaderTarget
import im.vector.lib.attachmentviewer.VideoLoaderTarget
import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.file.FileService
import java.io.File
@ -117,8 +116,8 @@ abstract class BaseAttachmentProvider(val imageContentRenderer: ImageContentRend
}
})
if (data.url?.startsWith("content://").orFalse() && data.allowNonMxcUrls) {
target.onVideoURLReady(info.uid, data.url!!)
if (data.url?.startsWith("content://") == true && data.allowNonMxcUrls) {
target.onVideoURLReady(info.uid, data.url)
} else {
target.onVideoFileLoading(info.uid)
fileService.downloadFile(
@ -130,7 +129,7 @@ abstract class BaseAttachmentProvider(val imageContentRenderer: ImageContentRend
url = data.url,
callback = object : MatrixCallback<File> {
override fun onSuccess(data: File) {
target.onVideoURLReady(info.uid, data)
target.onVideoFileReady(info.uid, data)
}
override fun onFailure(failure: Throwable) {

View file

@ -51,7 +51,7 @@ interface AttachmentData : Parcelable {
val mimeType: String?
val url: String?
val elementToDecrypt: ElementToDecrypt?
// If true will load non mxc url, be careful to set it only for images sent by you
// If true will load non mxc url, be careful to set it only for attachments sent by you
val allowNonMxcUrls: Boolean
}