Merge pull request #1936 from vector-im/feature/bma/testAndroidLocalMediaActions
Test android local media actions and other classes
This commit is contained in:
commit
f15469b9d3
13 changed files with 374 additions and 6 deletions
|
|
@ -136,7 +136,7 @@ class VectorFileLogger(
|
||||||
*
|
*
|
||||||
* @return The list of files with logs.
|
* @return The list of files with logs.
|
||||||
*/
|
*/
|
||||||
fun getLogFiles(): List<File> {
|
private fun getLogFiles(): List<File> {
|
||||||
return tryOrNull(
|
return tryOrNull(
|
||||||
onError = { Timber.e(it, "## getLogFiles() failed") }
|
onError = { Timber.e(it, "## getLogFiles() failed") }
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.rageshake.impl.logs
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.libraries.matrix.test.A_THROWABLE
|
||||||
|
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||||
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.RuntimeEnvironment
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
class VectorFileLoggerTest {
|
||||||
|
@Test
|
||||||
|
fun `init VectorFileLogger log debug`() = runTest {
|
||||||
|
val sut = createVectorFileLogger()
|
||||||
|
sut.d("A debug log")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `init VectorFileLogger log error`() = runTest {
|
||||||
|
val sut = createVectorFileLogger()
|
||||||
|
sut.e(A_THROWABLE, "A debug log")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `reset VectorFileLogger`() = runTest {
|
||||||
|
val sut = createVectorFileLogger()
|
||||||
|
sut.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check getFromTimber`() {
|
||||||
|
assertThat(VectorFileLogger.getFromTimber()).isNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun TestScope.createVectorFileLogger() = VectorFileLogger(
|
||||||
|
context = RuntimeEnvironment.getApplication(),
|
||||||
|
dispatcher = testCoroutineDispatchers().io,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 New Vector Ltd
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
*
|
*
|
||||||
|
|
@ -33,6 +32,7 @@ dependencies {
|
||||||
implementation(projects.libraries.di)
|
implementation(projects.libraries.di)
|
||||||
|
|
||||||
implementation(projects.libraries.core)
|
implementation(projects.libraries.core)
|
||||||
|
implementation(projects.services.toolbox.api)
|
||||||
implementation(libs.dagger)
|
implementation(libs.dagger)
|
||||||
implementation(libs.timber)
|
implementation(libs.timber)
|
||||||
implementation(libs.androidx.corektx)
|
implementation(libs.androidx.corektx)
|
||||||
|
|
@ -41,4 +41,12 @@ dependencies {
|
||||||
implementation(libs.androidx.exifinterface)
|
implementation(libs.androidx.exifinterface)
|
||||||
implementation(libs.androidx.security.crypto)
|
implementation(libs.androidx.security.crypto)
|
||||||
api(libs.androidx.browser)
|
api(libs.androidx.browser)
|
||||||
|
|
||||||
|
testImplementation(projects.tests.testutils)
|
||||||
|
testImplementation(libs.test.junit)
|
||||||
|
testImplementation(libs.test.truth)
|
||||||
|
testImplementation(libs.test.robolectric)
|
||||||
|
testImplementation(libs.coroutines.core)
|
||||||
|
testImplementation(libs.coroutines.test)
|
||||||
|
testImplementation(projects.services.toolbox.test)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,18 @@ import android.text.format.Formatter
|
||||||
import com.squareup.anvil.annotations.ContributesBinding
|
import com.squareup.anvil.annotations.ContributesBinding
|
||||||
import io.element.android.libraries.di.AppScope
|
import io.element.android.libraries.di.AppScope
|
||||||
import io.element.android.libraries.di.ApplicationContext
|
import io.element.android.libraries.di.ApplicationContext
|
||||||
|
import io.element.android.services.toolbox.api.sdk.BuildVersionSdkIntProvider
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
@ContributesBinding(AppScope::class)
|
||||||
class AndroidFileSizeFormatter @Inject constructor(
|
class AndroidFileSizeFormatter @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
) : FileSizeFormatter {
|
private val sdkIntProvider: BuildVersionSdkIntProvider,
|
||||||
|
) : FileSizeFormatter {
|
||||||
override fun format(fileSize: Long, useShortFormat: Boolean): String {
|
override fun format(fileSize: Long, useShortFormat: Boolean): String {
|
||||||
// Since Android O, the system considers that 1kB = 1000 bytes instead of 1024 bytes.
|
// Since Android O, the system considers that 1kB = 1000 bytes instead of 1024 bytes.
|
||||||
// We want to avoid that.
|
// We want to avoid that.
|
||||||
val normalizedSize = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
|
val normalizedSize = if (sdkIntProvider.get() <= Build.VERSION_CODES.N) {
|
||||||
fileSize
|
fileSize
|
||||||
} else {
|
} else {
|
||||||
// First convert the size
|
// First convert the size
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.androidutils.filesize
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.services.toolbox.test.sdk.FakeBuildVersionSdkIntProvider
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.RuntimeEnvironment
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
class AndroidFileSizeFormatterTest {
|
||||||
|
@Test
|
||||||
|
fun `test api 24 long format`() {
|
||||||
|
val sut = createAndroidFileSizeFormatter(sdkLevel = Build.VERSION_CODES.N)
|
||||||
|
assertThat(sut.format(1, useShortFormat = false)).isEqualTo("1.00B")
|
||||||
|
assertThat(sut.format(1000, useShortFormat = false)).isEqualTo("0.98KB")
|
||||||
|
assertThat(sut.format(1024, useShortFormat = false)).isEqualTo("1.00KB")
|
||||||
|
assertThat(sut.format(1024 * 1024, useShortFormat = false)).isEqualTo("1.00MB")
|
||||||
|
assertThat(sut.format(1024 * 1024 * 1024, useShortFormat = false)).isEqualTo("1.00GB")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test api 26 long format`() {
|
||||||
|
val sut = createAndroidFileSizeFormatter(sdkLevel = Build.VERSION_CODES.O)
|
||||||
|
assertThat(sut.format(1, useShortFormat = false)).isEqualTo("1.00B")
|
||||||
|
assertThat(sut.format(1000, useShortFormat = false)).isEqualTo("0.98KB")
|
||||||
|
assertThat(sut.format(1024 * 1024, useShortFormat = false)).isEqualTo("0.95MB")
|
||||||
|
assertThat(sut.format(1024 * 1024 * 1024, useShortFormat = false)).isEqualTo("0.93GB")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test api 24 short format`() {
|
||||||
|
val sut = createAndroidFileSizeFormatter(sdkLevel = Build.VERSION_CODES.N)
|
||||||
|
assertThat(sut.format(1, useShortFormat = true)).isEqualTo("1.0B")
|
||||||
|
assertThat(sut.format(1000, useShortFormat = true)).isEqualTo("0.98KB")
|
||||||
|
assertThat(sut.format(1024, useShortFormat = true)).isEqualTo("1.0KB")
|
||||||
|
assertThat(sut.format(1024 * 1024, useShortFormat = true)).isEqualTo("1.0MB")
|
||||||
|
assertThat(sut.format(1024 * 1024 * 1024, useShortFormat = true)).isEqualTo("1.0GB")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test api 26 short format`() {
|
||||||
|
val sut = createAndroidFileSizeFormatter(sdkLevel = Build.VERSION_CODES.O)
|
||||||
|
assertThat(sut.format(1, useShortFormat = true)).isEqualTo("1.0B")
|
||||||
|
assertThat(sut.format(1000, useShortFormat = true)).isEqualTo("0.98KB")
|
||||||
|
assertThat(sut.format(1024 * 1024, useShortFormat = true)).isEqualTo("0.95MB")
|
||||||
|
assertThat(sut.format(1024 * 1024 * 1024, useShortFormat = true)).isEqualTo("0.93GB")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createAndroidFileSizeFormatter(sdkLevel: Int) = AndroidFileSizeFormatter(
|
||||||
|
context = RuntimeEnvironment.getApplication(),
|
||||||
|
sdkIntProvider = FakeBuildVersionSdkIntProvider(sdkInt = sdkLevel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -55,6 +55,7 @@ dependencies {
|
||||||
testImplementation(libs.test.junit)
|
testImplementation(libs.test.junit)
|
||||||
testImplementation(libs.test.truth)
|
testImplementation(libs.test.truth)
|
||||||
testImplementation(libs.test.mockk)
|
testImplementation(libs.test.mockk)
|
||||||
|
testImplementation(libs.test.robolectric)
|
||||||
testImplementation(libs.test.turbine)
|
testImplementation(libs.test.turbine)
|
||||||
testImplementation(libs.coroutines.core)
|
testImplementation(libs.coroutines.core)
|
||||||
testImplementation(libs.coroutines.test)
|
testImplementation(libs.coroutines.test)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.mediaviewer.api.util
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
class FileExtensionExtractorTest {
|
||||||
|
@Test
|
||||||
|
fun `test FileExtensionExtractor with validation OK`() {
|
||||||
|
val sut = FileExtensionExtractorWithValidation()
|
||||||
|
// The result should be txt, but with Robolectric,
|
||||||
|
// MimeTypeMap.getSingleton().hasExtension() always returns false
|
||||||
|
assertThat(sut.extractFromName("test.txt")).isEqualTo("bin")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test FileExtensionExtractor with validation ERROR`() {
|
||||||
|
val sut = FileExtensionExtractorWithValidation()
|
||||||
|
assertThat(sut.extractFromName("test.bla")).isEqualTo("bin")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test FileExtensionExtractor no validation`() {
|
||||||
|
val sut = FileExtensionExtractorWithoutValidation()
|
||||||
|
assertThat(sut.extractFromName("test.png")).isEqualTo("png")
|
||||||
|
assertThat(sut.extractFromName("test.bla")).isEqualTo("bla")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -46,6 +46,9 @@ dependencies {
|
||||||
testImplementation(libs.test.junit)
|
testImplementation(libs.test.junit)
|
||||||
testImplementation(libs.test.truth)
|
testImplementation(libs.test.truth)
|
||||||
testImplementation(libs.test.mockk)
|
testImplementation(libs.test.mockk)
|
||||||
|
testImplementation(libs.molecule.runtime)
|
||||||
|
testImplementation(libs.test.turbine)
|
||||||
|
testImplementation(libs.test.robolectric)
|
||||||
testImplementation(libs.test.turbine)
|
testImplementation(libs.test.turbine)
|
||||||
testImplementation(libs.coroutines.core)
|
testImplementation(libs.coroutines.core)
|
||||||
testImplementation(libs.coroutines.test)
|
testImplementation(libs.coroutines.test)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.libraries.mediaviewer.local
|
package io.element.android.libraries.mediaviewer.impl.local
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.libraries.mediaviewer.local
|
package io.element.android.libraries.mediaviewer.impl.local
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.mediaviewer.impl.local
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.activity.compose.LocalActivityResultRegistryOwner
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import app.cash.molecule.RecompositionMode
|
||||||
|
import app.cash.molecule.moleculeFlow
|
||||||
|
import app.cash.turbine.test
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||||
|
import io.element.android.libraries.mediaviewer.test.viewer.aLocalMedia
|
||||||
|
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||||
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.RuntimeEnvironment
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
class AndroidLocalMediaActionsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - AndroidLocalMediaAction configure`() = runTest {
|
||||||
|
val sut = createAndroidLocalMediaActions()
|
||||||
|
moleculeFlow(RecompositionMode.Immediate) {
|
||||||
|
CompositionLocalProvider(
|
||||||
|
LocalContext provides RuntimeEnvironment.getApplication(),
|
||||||
|
LocalActivityResultRegistryOwner provides NoOpActivityResultRegistryOwner()
|
||||||
|
) {
|
||||||
|
sut.Configure()
|
||||||
|
}
|
||||||
|
}.test {
|
||||||
|
awaitItem()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test AndroidLocalMediaAction share`() = runTest {
|
||||||
|
val sut = createAndroidLocalMediaActions()
|
||||||
|
val result = sut.share(aLocalMedia(Uri.parse("file://afile")))
|
||||||
|
assertThat(result.exceptionOrNull()).isNotNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test AndroidLocalMediaAction open`() = runTest {
|
||||||
|
val sut = createAndroidLocalMediaActions()
|
||||||
|
val result = sut.open(aLocalMedia(Uri.parse("file://afile")))
|
||||||
|
assertThat(result.exceptionOrNull()).isNotNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test AndroidLocalMediaAction save on disk`() = runTest {
|
||||||
|
val sut = createAndroidLocalMediaActions()
|
||||||
|
val result = sut.saveOnDisk(aLocalMedia(Uri.parse("file://afile")))
|
||||||
|
assertThat(result.exceptionOrNull()).isNotNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun TestScope.createAndroidLocalMediaActions() = AndroidLocalMediaActions(
|
||||||
|
RuntimeEnvironment.getApplication(),
|
||||||
|
testCoroutineDispatchers(),
|
||||||
|
aBuildMeta()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.mediaviewer.impl.local
|
||||||
|
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.libraries.androidutils.filesize.FakeFileSizeFormatter
|
||||||
|
import io.element.android.libraries.core.mimetype.MimeTypes
|
||||||
|
import io.element.android.libraries.matrix.api.media.MediaFile
|
||||||
|
import io.element.android.libraries.matrix.test.media.FakeMediaFile
|
||||||
|
import io.element.android.libraries.mediaviewer.api.local.LocalMedia
|
||||||
|
import io.element.android.libraries.mediaviewer.api.local.MediaInfo
|
||||||
|
import io.element.android.libraries.mediaviewer.api.local.anImageInfo
|
||||||
|
import io.element.android.libraries.mediaviewer.api.util.FileExtensionExtractorWithoutValidation
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.robolectric.RobolectricTestRunner
|
||||||
|
import org.robolectric.RuntimeEnvironment
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner::class)
|
||||||
|
class AndroidLocalMediaFactoryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test AndroidLocalMediaFactory`() {
|
||||||
|
val sut = createAndroidLocalMediaFactory()
|
||||||
|
val result = sut.createFromMediaFile(aMediaFile(), anImageInfo())
|
||||||
|
assertThat(result.uri.toString()).endsWith("aPath")
|
||||||
|
assertThat(result.info).isEqualTo(
|
||||||
|
MediaInfo(
|
||||||
|
name = "an image file.jpg",
|
||||||
|
mimeType = MimeTypes.Jpeg,
|
||||||
|
formattedFileSize = "4MB",
|
||||||
|
fileExtension = "jpg",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun aMediaFile(): MediaFile {
|
||||||
|
return FakeMediaFile("aPath")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createAndroidLocalMediaFactory(): AndroidLocalMediaFactory {
|
||||||
|
return AndroidLocalMediaFactory(
|
||||||
|
RuntimeEnvironment.getApplication(),
|
||||||
|
FakeFileSizeFormatter(),
|
||||||
|
FileExtensionExtractorWithoutValidation()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.libraries.mediaviewer.impl.local
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResultRegistry
|
||||||
|
import androidx.activity.result.ActivityResultRegistryOwner
|
||||||
|
import androidx.activity.result.contract.ActivityResultContract
|
||||||
|
import androidx.core.app.ActivityOptionsCompat
|
||||||
|
|
||||||
|
class NoOpActivityResultRegistryOwner : ActivityResultRegistryOwner {
|
||||||
|
override val activityResultRegistry: ActivityResultRegistry
|
||||||
|
get() = NoOpActivityResultRegistry()
|
||||||
|
}
|
||||||
|
|
||||||
|
class NoOpActivityResultRegistry : ActivityResultRegistry() {
|
||||||
|
override fun <I : Any?, O : Any?> onLaunch(
|
||||||
|
requestCode: Int,
|
||||||
|
contract: ActivityResultContract<I, O>,
|
||||||
|
input: I,
|
||||||
|
options: ActivityOptionsCompat?,
|
||||||
|
) = Unit
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue