Naming convention and use MatrixMediaLoader instead of MatrixClient for Coil factories.
This commit is contained in:
parent
e0dffa4a46
commit
cef55121cc
11 changed files with 26 additions and 26 deletions
|
|
@ -57,7 +57,7 @@ interface MatrixClient {
|
||||||
val encryptionService: EncryptionService
|
val encryptionService: EncryptionService
|
||||||
val roomDirectoryService: RoomDirectoryService
|
val roomDirectoryService: RoomDirectoryService
|
||||||
val mediaPreviewService: MediaPreviewService
|
val mediaPreviewService: MediaPreviewService
|
||||||
val mediaLoader: MatrixMediaLoader
|
val matrixMediaLoader: MatrixMediaLoader
|
||||||
val sessionCoroutineScope: CoroutineScope
|
val sessionCoroutineScope: CoroutineScope
|
||||||
val ignoredUsersFlow: StateFlow<ImmutableList<UserId>>
|
val ignoredUsersFlow: StateFlow<ImmutableList<UserId>>
|
||||||
val roomMembershipObserver: RoomMembershipObserver
|
val roomMembershipObserver: RoomMembershipObserver
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ class RustMatrixClient(
|
||||||
featureFlagService = featureFlagService,
|
featureFlagService = featureFlagService,
|
||||||
)
|
)
|
||||||
|
|
||||||
override val mediaLoader: MatrixMediaLoader = RustMediaLoader(
|
override val matrixMediaLoader: MatrixMediaLoader = RustMediaLoader(
|
||||||
baseCacheDirectory = baseCacheDirectory,
|
baseCacheDirectory = baseCacheDirectory,
|
||||||
dispatchers = dispatchers,
|
dispatchers = dispatchers,
|
||||||
innerClient = innerClient,
|
innerClient = innerClient,
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ object SessionMatrixModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun providesMatrixMediaLoader(matrixClient: MatrixClient): MatrixMediaLoader {
|
fun providesMatrixMediaLoader(matrixClient: MatrixClient): MatrixMediaLoader {
|
||||||
return matrixClient.mediaLoader
|
return matrixClient.matrixMediaLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
@SessionCoroutineScope
|
@SessionCoroutineScope
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class FakeMatrixClient(
|
||||||
private val userAvatarUrl: String? = AN_AVATAR_URL,
|
private val userAvatarUrl: String? = AN_AVATAR_URL,
|
||||||
override val roomListService: RoomListService = FakeRoomListService(),
|
override val roomListService: RoomListService = FakeRoomListService(),
|
||||||
override val spaceService: SpaceService = FakeSpaceService(),
|
override val spaceService: SpaceService = FakeSpaceService(),
|
||||||
override val mediaLoader: MatrixMediaLoader = FakeMatrixMediaLoader(),
|
override val matrixMediaLoader: MatrixMediaLoader = FakeMatrixMediaLoader(),
|
||||||
override val sessionVerificationService: FakeSessionVerificationService = FakeSessionVerificationService(),
|
override val sessionVerificationService: FakeSessionVerificationService = FakeSessionVerificationService(),
|
||||||
override val pushersService: FakePushersService = FakePushersService(),
|
override val pushersService: FakePushersService = FakePushersService(),
|
||||||
override val notificationService: FakeNotificationService = FakeNotificationService(),
|
override val notificationService: FakeNotificationService = FakeNotificationService(),
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ import coil3.ImageLoader
|
||||||
import coil3.fetch.Fetcher
|
import coil3.fetch.Fetcher
|
||||||
import coil3.request.Options
|
import coil3.request.Options
|
||||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
|
||||||
|
|
||||||
internal class AvatarDataFetcherFactory(
|
internal class AvatarDataFetcherFactory(
|
||||||
private val client: MatrixClient
|
private val matrixMediaLoader: MatrixMediaLoader
|
||||||
) : Fetcher.Factory<AvatarData> {
|
) : Fetcher.Factory<AvatarData> {
|
||||||
override fun create(
|
override fun create(
|
||||||
data: AvatarData,
|
data: AvatarData,
|
||||||
|
|
@ -22,7 +22,7 @@ internal class AvatarDataFetcherFactory(
|
||||||
imageLoader: ImageLoader
|
imageLoader: ImageLoader
|
||||||
): Fetcher {
|
): Fetcher {
|
||||||
return CoilMediaFetcher(
|
return CoilMediaFetcher(
|
||||||
mediaLoader = client.mediaLoader,
|
mediaLoader = matrixMediaLoader,
|
||||||
mediaData = data.toMediaRequestData(),
|
mediaData = data.toMediaRequestData(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ import dev.zacsweers.metro.ContributesBinding
|
||||||
import dev.zacsweers.metro.Inject
|
import dev.zacsweers.metro.Inject
|
||||||
import dev.zacsweers.metro.Provider
|
import dev.zacsweers.metro.Provider
|
||||||
import io.element.android.libraries.di.annotations.ApplicationContext
|
import io.element.android.libraries.di.annotations.ApplicationContext
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
|
||||||
interface LoggedInImageLoaderFactory {
|
interface LoggedInImageLoaderFactory {
|
||||||
fun newImageLoader(matrixClient: MatrixClient): ImageLoader
|
fun newImageLoader(matrixMediaLoader: MatrixMediaLoader): ImageLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
@ContributesBinding(AppScope::class)
|
||||||
|
|
@ -31,7 +31,7 @@ class DefaultLoggedInImageLoaderFactory(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
private val okHttpClient: Provider<OkHttpClient>,
|
private val okHttpClient: Provider<OkHttpClient>,
|
||||||
) : LoggedInImageLoaderFactory {
|
) : LoggedInImageLoaderFactory {
|
||||||
override fun newImageLoader(matrixClient: MatrixClient): ImageLoader {
|
override fun newImageLoader(matrixMediaLoader: MatrixMediaLoader): ImageLoader {
|
||||||
return ImageLoader.Builder(context)
|
return ImageLoader.Builder(context)
|
||||||
.components {
|
.components {
|
||||||
add(
|
add(
|
||||||
|
|
@ -50,8 +50,8 @@ class DefaultLoggedInImageLoaderFactory(
|
||||||
}
|
}
|
||||||
add(AvatarDataKeyer())
|
add(AvatarDataKeyer())
|
||||||
add(MediaRequestDataKeyer())
|
add(MediaRequestDataKeyer())
|
||||||
add(AvatarDataFetcherFactory(matrixClient))
|
add(AvatarDataFetcherFactory(matrixMediaLoader))
|
||||||
add(MediaRequestDataFetcherFactory(matrixClient))
|
add(MediaRequestDataFetcherFactory(matrixMediaLoader))
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class DefaultImageLoaderHolder(
|
||||||
return synchronized(map) {
|
return synchronized(map) {
|
||||||
map.getOrPut(client.sessionId) {
|
map.getOrPut(client.sessionId) {
|
||||||
loggedInImageLoaderFactory
|
loggedInImageLoaderFactory
|
||||||
.newImageLoader(client)
|
.newImageLoader(client.matrixMediaLoader)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ package io.element.android.libraries.matrix.ui.media
|
||||||
import coil3.ImageLoader
|
import coil3.ImageLoader
|
||||||
import coil3.fetch.Fetcher
|
import coil3.fetch.Fetcher
|
||||||
import coil3.request.Options
|
import coil3.request.Options
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
|
||||||
|
|
||||||
internal class MediaRequestDataFetcherFactory(
|
internal class MediaRequestDataFetcherFactory(
|
||||||
private val client: MatrixClient
|
private val matrixMediaLoader: MatrixMediaLoader,
|
||||||
) : Fetcher.Factory<MediaRequestData> {
|
) : Fetcher.Factory<MediaRequestData> {
|
||||||
override fun create(
|
override fun create(
|
||||||
data: MediaRequestData,
|
data: MediaRequestData,
|
||||||
|
|
@ -21,7 +21,7 @@ internal class MediaRequestDataFetcherFactory(
|
||||||
imageLoader: ImageLoader
|
imageLoader: ImageLoader
|
||||||
): Fetcher {
|
): Fetcher {
|
||||||
return CoilMediaFetcher(
|
return CoilMediaFetcher(
|
||||||
mediaLoader = client.mediaLoader,
|
mediaLoader = matrixMediaLoader,
|
||||||
mediaData = data,
|
mediaData = data,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ package io.element.android.libraries.matrix.ui.media
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import coil3.ImageLoader
|
import coil3.ImageLoader
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
|
||||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||||
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
import io.element.android.libraries.sessionstorage.test.observer.FakeSessionObserver
|
import io.element.android.libraries.sessionstorage.test.observer.FakeSessionObserver
|
||||||
|
|
@ -27,7 +27,7 @@ class DefaultImageLoaderHolderTest {
|
||||||
@Test
|
@Test
|
||||||
fun `get - returns the same ImageLoader for the same client`() {
|
fun `get - returns the same ImageLoader for the same client`() {
|
||||||
val context = InstrumentationRegistry.getInstrumentation().context
|
val context = InstrumentationRegistry.getInstrumentation().context
|
||||||
val lambda = lambdaRecorder<MatrixClient, ImageLoader> { ImageLoader.Builder(context).build() }
|
val lambda = lambdaRecorder<MatrixMediaLoader, ImageLoader> { ImageLoader.Builder(context).build() }
|
||||||
|
|
||||||
val holder = DefaultImageLoaderHolder(
|
val holder = DefaultImageLoaderHolder(
|
||||||
loggedInImageLoaderFactory = FakeLoggedInImageLoaderFactory(lambda),
|
loggedInImageLoaderFactory = FakeLoggedInImageLoaderFactory(lambda),
|
||||||
|
|
@ -39,14 +39,14 @@ class DefaultImageLoaderHolderTest {
|
||||||
assert(imageLoader1 === imageLoader2)
|
assert(imageLoader1 === imageLoader2)
|
||||||
lambda.assertions()
|
lambda.assertions()
|
||||||
.isCalledOnce()
|
.isCalledOnce()
|
||||||
.with(value(client))
|
.with(value(client.matrixMediaLoader))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `when session is deleted, the image loader is deleted`() = runTest {
|
fun `when session is deleted, the image loader is deleted`() = runTest {
|
||||||
val context = InstrumentationRegistry.getInstrumentation().context
|
val context = InstrumentationRegistry.getInstrumentation().context
|
||||||
val lambda =
|
val lambda =
|
||||||
lambdaRecorder<MatrixClient, ImageLoader> { ImageLoader.Builder(context).build() }
|
lambdaRecorder<MatrixMediaLoader, ImageLoader> { ImageLoader.Builder(context).build() }
|
||||||
val sessionObserver = FakeSessionObserver()
|
val sessionObserver = FakeSessionObserver()
|
||||||
val holder = DefaultImageLoaderHolder(
|
val holder = DefaultImageLoaderHolder(
|
||||||
loggedInImageLoaderFactory = FakeLoggedInImageLoaderFactory(lambda),
|
loggedInImageLoaderFactory = FakeLoggedInImageLoaderFactory(lambda),
|
||||||
|
|
@ -65,7 +65,7 @@ class DefaultImageLoaderHolderTest {
|
||||||
fun `when session is created, nothing happen`() = runTest {
|
fun `when session is created, nothing happen`() = runTest {
|
||||||
val context = InstrumentationRegistry.getInstrumentation().context
|
val context = InstrumentationRegistry.getInstrumentation().context
|
||||||
val lambda =
|
val lambda =
|
||||||
lambdaRecorder<MatrixClient, ImageLoader> { ImageLoader.Builder(context).build() }
|
lambdaRecorder<MatrixMediaLoader, ImageLoader> { ImageLoader.Builder(context).build() }
|
||||||
val sessionObserver = FakeSessionObserver()
|
val sessionObserver = FakeSessionObserver()
|
||||||
DefaultImageLoaderHolder(
|
DefaultImageLoaderHolder(
|
||||||
loggedInImageLoaderFactory = FakeLoggedInImageLoaderFactory(lambda),
|
loggedInImageLoaderFactory = FakeLoggedInImageLoaderFactory(lambda),
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@
|
||||||
package io.element.android.libraries.matrix.ui.media
|
package io.element.android.libraries.matrix.ui.media
|
||||||
|
|
||||||
import coil3.ImageLoader
|
import coil3.ImageLoader
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.media.MatrixMediaLoader
|
||||||
|
|
||||||
class FakeLoggedInImageLoaderFactory(
|
class FakeLoggedInImageLoaderFactory(
|
||||||
private val newImageLoaderLambda: (MatrixClient) -> ImageLoader
|
private val newImageLoaderLambda: (MatrixMediaLoader) -> ImageLoader
|
||||||
) : LoggedInImageLoaderFactory {
|
) : LoggedInImageLoaderFactory {
|
||||||
override fun newImageLoader(matrixClient: MatrixClient): ImageLoader {
|
override fun newImageLoader(matrixMediaLoader: MatrixMediaLoader): ImageLoader {
|
||||||
return newImageLoaderLambda(matrixClient)
|
return newImageLoaderLambda(matrixMediaLoader)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ class DefaultNotificationMediaRepo(
|
||||||
): DefaultNotificationMediaRepo
|
): DefaultNotificationMediaRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
private val matrixMediaLoader = client.mediaLoader
|
private val matrixMediaLoader = client.matrixMediaLoader
|
||||||
|
|
||||||
override suspend fun getMediaFile(
|
override suspend fun getMediaFile(
|
||||||
mediaSource: MediaSource,
|
mediaSource: MediaSource,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue