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

View file

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

View file

@ -992,7 +992,7 @@ class RoomDetailViewModel @AssistedInject constructor(
private fun handleOpenOrDownloadFile(action: RoomDetailAction.DownloadOrOpen) { private fun handleOpenOrDownloadFile(action: RoomDetailAction.DownloadOrOpen) {
val mxcUrl = action.messageFileContent.getFileUrl() val mxcUrl = action.messageFileContent.getFileUrl()
val isLocalSendingFile = action.senderId == session.myUserId 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 val isDownloaded = mxcUrl?.let { session.fileService().isFileInCache(it, action.messageFileContent.mimeType) } ?: false
if (isLocalSendingFile) { if (isLocalSendingFile) {
tryThis { Uri.parse(mxcUrl) }?.let { 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.ImageLoaderTarget
import im.vector.lib.attachmentviewer.VideoLoaderTarget import im.vector.lib.attachmentviewer.VideoLoaderTarget
import org.matrix.android.sdk.api.MatrixCallback 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 org.matrix.android.sdk.api.session.file.FileService
import java.io.File import java.io.File
@ -117,8 +116,8 @@ abstract class BaseAttachmentProvider(val imageContentRenderer: ImageContentRend
} }
}) })
if (data.url?.startsWith("content://").orFalse() && data.allowNonMxcUrls) { if (data.url?.startsWith("content://") == true && data.allowNonMxcUrls) {
target.onVideoURLReady(info.uid, data.url!!) target.onVideoURLReady(info.uid, data.url)
} else { } else {
target.onVideoFileLoading(info.uid) target.onVideoFileLoading(info.uid)
fileService.downloadFile( fileService.downloadFile(
@ -130,7 +129,7 @@ abstract class BaseAttachmentProvider(val imageContentRenderer: ImageContentRend
url = data.url, url = data.url,
callback = object : MatrixCallback<File> { callback = object : MatrixCallback<File> {
override fun onSuccess(data: File) { override fun onSuccess(data: File) {
target.onVideoURLReady(info.uid, data) target.onVideoFileReady(info.uid, data)
} }
override fun onFailure(failure: Throwable) { override fun onFailure(failure: Throwable) {

View file

@ -51,7 +51,7 @@ interface AttachmentData : Parcelable {
val mimeType: String? val mimeType: String?
val url: String? val url: String?
val elementToDecrypt: ElementToDecrypt? 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 val allowNonMxcUrls: Boolean
} }