Create matrixui module and remove dependency to coil in the matrix module. Move MatrixUser there.

This commit is contained in:
Benoit Marty 2022-12-22 15:31:55 +01:00
parent 4431f037ab
commit c5c05e3867
17 changed files with 106 additions and 24 deletions

View file

@ -33,7 +33,6 @@ dependencies {
implementation(project(":libraries:di"))
implementation(project(":libraries:core"))
implementation("net.java.dev.jna:jna:5.12.1@aar")
implementation(libs.coil.compose)
implementation(libs.androidx.datastore.preferences)
implementation(libs.serialization.json)
}

View file

@ -17,13 +17,10 @@
package io.element.android.x.matrix
import android.content.Context
import coil.ComponentRegistry
import io.element.android.x.core.coroutine.CoroutineDispatchers
import io.element.android.x.di.AppScope
import io.element.android.x.di.ApplicationContext
import io.element.android.x.di.SingleIn
import io.element.android.x.matrix.media.MediaFetcher
import io.element.android.x.matrix.media.MediaKeyer
import io.element.android.x.matrix.session.SessionStore
import io.element.android.x.matrix.util.logError
import java.io.File
@ -58,14 +55,6 @@ class Matrix @Inject constructor(
return sessionStore.isLoggedIn()
}
fun registerCoilComponents(
builder: ComponentRegistry.Builder,
activeClientProvider: () -> MatrixClient?
) {
builder.add(MediaKeyer())
builder.add(MediaFetcher.Factory(activeClientProvider))
}
suspend fun restoreSession() = withContext(coroutineDispatchers.io) {
sessionStore.getLatestSession()
?.let { session ->

View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 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.
*/
plugins {
id("io.element.android-compose-library")
alias(libs.plugins.anvil)
}
android {
namespace = "io.element.android.x.matrix.ui"
}
anvil {
generateDaggerFactories.set(true)
}
dependencies {
implementation(project(":libraries:matrix"))
implementation(project(":libraries:designsystem"))
implementation(project(":libraries:core"))
implementation(libs.coil.compose)
}

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2022 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.
-->
<manifest/>

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2022 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.x.matrix.ui
import coil.ComponentRegistry
import io.element.android.x.matrix.MatrixClient
import io.element.android.x.matrix.ui.media.MediaFetcher
import io.element.android.x.matrix.ui.media.MediaKeyer
import javax.inject.Inject
class MatrixUi @Inject constructor() {
fun registerCoilComponents(
builder: ComponentRegistry.Builder,
activeClientProvider: () -> MatrixClient?
) {
builder.add(MediaKeyer())
builder.add(MediaFetcher.Factory(activeClientProvider))
}
}

View file

@ -14,16 +14,17 @@
* limitations under the License.
*/
package io.element.android.x.matrix.media
package io.element.android.x.matrix.ui.media
import coil.ImageLoader
import coil.fetch.FetchResult
import coil.fetch.Fetcher
import coil.request.Options
import io.element.android.x.matrix.MatrixClient
import io.element.android.x.matrix.media.MediaResolver
import java.nio.ByteBuffer
internal class MediaFetcher(
class MediaFetcher(
private val mediaResolver: MediaResolver?,
private val meta: MediaResolver.Meta,
private val options: Options,

View file

@ -14,12 +14,13 @@
* limitations under the License.
*/
package io.element.android.x.matrix.media
package io.element.android.x.matrix.ui.media
import coil.key.Keyer
import coil.request.Options
import io.element.android.x.matrix.media.MediaResolver
internal class MediaKeyer : Keyer<MediaResolver.Meta> {
class MediaKeyer : Keyer<MediaResolver.Meta> {
override fun key(data: MediaResolver.Meta, options: Options): String? {
return "${data.source.url()}_${data.kind}"
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2022 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.x.matrix.ui.model
import androidx.compose.runtime.Stable
import io.element.android.x.designsystem.components.avatar.AvatarData
@Stable
data class MatrixUser(
val username: String? = null,
val avatarUrl: String? = null,
val avatarData: AvatarData = AvatarData(),
)