Create matrixui module and remove dependency to coil in the matrix module. Move MatrixUser there.
This commit is contained in:
parent
b19c9a86e9
commit
9024510f39
17 changed files with 106 additions and 24 deletions
|
|
@ -151,6 +151,7 @@ knit {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":libraries:designsystem"))
|
implementation(project(":libraries:designsystem"))
|
||||||
implementation(project(":libraries:matrix"))
|
implementation(project(":libraries:matrix"))
|
||||||
|
implementation(project(":libraries:matrixui"))
|
||||||
implementation(project(":libraries:core"))
|
implementation(project(":libraries:core"))
|
||||||
implementation(project(":features:onboarding"))
|
implementation(project(":features:onboarding"))
|
||||||
implementation(project(":features:login"))
|
implementation(project(":features:login"))
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@ package io.element.android.x.di
|
||||||
|
|
||||||
import com.squareup.anvil.annotations.ContributesTo
|
import com.squareup.anvil.annotations.ContributesTo
|
||||||
import io.element.android.x.matrix.Matrix
|
import io.element.android.x.matrix.Matrix
|
||||||
|
import io.element.android.x.matrix.ui.MatrixUi
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
|
||||||
@ContributesTo(AppScope::class)
|
@ContributesTo(AppScope::class)
|
||||||
interface AppBindings {
|
interface AppBindings {
|
||||||
fun coroutineScope(): CoroutineScope
|
fun coroutineScope(): CoroutineScope
|
||||||
fun matrix(): Matrix
|
fun matrix(): Matrix
|
||||||
|
fun matrixUi(): MatrixUi
|
||||||
fun sessionComponentsOwner(): SessionComponentsOwner
|
fun sessionComponentsOwner(): SessionComponentsOwner
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,18 @@ class CoilInitializer : Initializer<Unit> {
|
||||||
|
|
||||||
private class ElementImageLoaderFactory(
|
private class ElementImageLoaderFactory(
|
||||||
private val context: Context
|
private val context: Context
|
||||||
) :
|
) : ImageLoaderFactory {
|
||||||
ImageLoaderFactory {
|
|
||||||
override fun newImageLoader(): ImageLoader {
|
override fun newImageLoader(): ImageLoader {
|
||||||
return ImageLoader
|
return ImageLoader
|
||||||
.Builder(context)
|
.Builder(context)
|
||||||
.components {
|
.components {
|
||||||
val appBindings = context.bindings<AppBindings>()
|
val appBindings = context.bindings<AppBindings>()
|
||||||
val matrix = appBindings.matrix()
|
val matrixUi = appBindings.matrixUi()
|
||||||
val matrixClientProvider = {
|
val matrixClientProvider = {
|
||||||
appBindings
|
appBindings
|
||||||
.sessionComponentsOwner().activeSessionComponent?.matrixClient()
|
.sessionComponentsOwner().activeSessionComponent?.matrixClient()
|
||||||
}
|
}
|
||||||
matrix.registerCoilComponents(this, matrixClientProvider)
|
matrixUi.registerCoilComponents(this, matrixClientProvider)
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ dependencies {
|
||||||
implementation(project(":libraries:di"))
|
implementation(project(":libraries:di"))
|
||||||
implementation(project(":libraries:core"))
|
implementation(project(":libraries:core"))
|
||||||
implementation(project(":libraries:matrix"))
|
implementation(project(":libraries:matrix"))
|
||||||
|
implementation(project(":libraries:matrixui"))
|
||||||
implementation(project(":libraries:designsystem"))
|
implementation(project(":libraries:designsystem"))
|
||||||
implementation(project(":libraries:elementresources"))
|
implementation(project(":libraries:elementresources"))
|
||||||
implementation(libs.mavericks.compose)
|
implementation(libs.mavericks.compose)
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,11 @@ import io.element.android.x.designsystem.ElementXTheme
|
||||||
import io.element.android.x.designsystem.components.avatar.AvatarData
|
import io.element.android.x.designsystem.components.avatar.AvatarData
|
||||||
import io.element.android.x.features.roomlist.components.RoomListTopBar
|
import io.element.android.x.features.roomlist.components.RoomListTopBar
|
||||||
import io.element.android.x.features.roomlist.components.RoomSummaryRow
|
import io.element.android.x.features.roomlist.components.RoomSummaryRow
|
||||||
import io.element.android.x.features.roomlist.model.MatrixUser
|
|
||||||
import io.element.android.x.features.roomlist.model.RoomListRoomSummary
|
import io.element.android.x.features.roomlist.model.RoomListRoomSummary
|
||||||
import io.element.android.x.features.roomlist.model.RoomListViewState
|
import io.element.android.x.features.roomlist.model.RoomListViewState
|
||||||
import io.element.android.x.features.roomlist.model.stubbedRoomSummaries
|
import io.element.android.x.features.roomlist.model.stubbedRoomSummaries
|
||||||
import io.element.android.x.matrix.core.RoomId
|
import io.element.android.x.matrix.core.RoomId
|
||||||
|
import io.element.android.x.matrix.ui.model.MatrixUser
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,13 @@ import io.element.android.x.core.di.daggerMavericksViewModelFactory
|
||||||
import io.element.android.x.designsystem.components.avatar.AvatarData
|
import io.element.android.x.designsystem.components.avatar.AvatarData
|
||||||
import io.element.android.x.designsystem.components.avatar.AvatarSize
|
import io.element.android.x.designsystem.components.avatar.AvatarSize
|
||||||
import io.element.android.x.di.SessionScope
|
import io.element.android.x.di.SessionScope
|
||||||
import io.element.android.x.features.roomlist.model.MatrixUser
|
|
||||||
import io.element.android.x.features.roomlist.model.RoomListRoomSummary
|
import io.element.android.x.features.roomlist.model.RoomListRoomSummary
|
||||||
import io.element.android.x.features.roomlist.model.RoomListRoomSummaryPlaceholders
|
import io.element.android.x.features.roomlist.model.RoomListRoomSummaryPlaceholders
|
||||||
import io.element.android.x.features.roomlist.model.RoomListViewState
|
import io.element.android.x.features.roomlist.model.RoomListViewState
|
||||||
import io.element.android.x.matrix.MatrixClient
|
import io.element.android.x.matrix.MatrixClient
|
||||||
import io.element.android.x.matrix.media.MediaResolver
|
import io.element.android.x.matrix.media.MediaResolver
|
||||||
import io.element.android.x.matrix.room.RoomSummary
|
import io.element.android.x.matrix.room.RoomSummary
|
||||||
|
import io.element.android.x.matrix.ui.model.MatrixUser
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ import androidx.compose.ui.unit.sp
|
||||||
import io.element.android.x.core.compose.LogCompositions
|
import io.element.android.x.core.compose.LogCompositions
|
||||||
import io.element.android.x.core.compose.textFieldState
|
import io.element.android.x.core.compose.textFieldState
|
||||||
import io.element.android.x.designsystem.components.avatar.Avatar
|
import io.element.android.x.designsystem.components.avatar.Avatar
|
||||||
import io.element.android.x.features.roomlist.model.MatrixUser
|
import io.element.android.x.matrix.ui.model.MatrixUser
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RoomListTopBar(
|
fun RoomListTopBar(
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.MavericksState
|
import com.airbnb.mvrx.MavericksState
|
||||||
import com.airbnb.mvrx.Uninitialized
|
import com.airbnb.mvrx.Uninitialized
|
||||||
import io.element.android.x.matrix.core.RoomId
|
import io.element.android.x.matrix.core.RoomId
|
||||||
|
import io.element.android.x.matrix.ui.model.MatrixUser
|
||||||
|
|
||||||
data class RoomListViewState(
|
data class RoomListViewState(
|
||||||
val user: Async<MatrixUser> = Uninitialized,
|
val user: Async<MatrixUser> = Uninitialized,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ dependencies {
|
||||||
implementation(project(":libraries:di"))
|
implementation(project(":libraries:di"))
|
||||||
implementation(project(":libraries:core"))
|
implementation(project(":libraries:core"))
|
||||||
implementation("net.java.dev.jna:jna:5.12.1@aar")
|
implementation("net.java.dev.jna:jna:5.12.1@aar")
|
||||||
implementation(libs.coil.compose)
|
|
||||||
implementation(libs.androidx.datastore.preferences)
|
implementation(libs.androidx.datastore.preferences)
|
||||||
implementation(libs.serialization.json)
|
implementation(libs.serialization.json)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,10 @@
|
||||||
package io.element.android.x.matrix
|
package io.element.android.x.matrix
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import coil.ComponentRegistry
|
|
||||||
import io.element.android.x.core.coroutine.CoroutineDispatchers
|
import io.element.android.x.core.coroutine.CoroutineDispatchers
|
||||||
import io.element.android.x.di.AppScope
|
import io.element.android.x.di.AppScope
|
||||||
import io.element.android.x.di.ApplicationContext
|
import io.element.android.x.di.ApplicationContext
|
||||||
import io.element.android.x.di.SingleIn
|
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.session.SessionStore
|
||||||
import io.element.android.x.matrix.util.logError
|
import io.element.android.x.matrix.util.logError
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
@ -58,14 +55,6 @@ class Matrix @Inject constructor(
|
||||||
return sessionStore.isLoggedIn()
|
return sessionStore.isLoggedIn()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerCoilComponents(
|
|
||||||
builder: ComponentRegistry.Builder,
|
|
||||||
activeClientProvider: () -> MatrixClient?
|
|
||||||
) {
|
|
||||||
builder.add(MediaKeyer())
|
|
||||||
builder.add(MediaFetcher.Factory(activeClientProvider))
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun restoreSession() = withContext(coroutineDispatchers.io) {
|
suspend fun restoreSession() = withContext(coroutineDispatchers.io) {
|
||||||
sessionStore.getLatestSession()
|
sessionStore.getLatestSession()
|
||||||
?.let { session ->
|
?.let { session ->
|
||||||
|
|
|
||||||
35
libraries/matrixui/build.gradle.kts
Normal file
35
libraries/matrixui/build.gradle.kts
Normal 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)
|
||||||
|
}
|
||||||
18
libraries/matrixui/src/main/AndroidManifest.xml
Normal file
18
libraries/matrixui/src/main/AndroidManifest.xml
Normal 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/>
|
||||||
|
|
@ -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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,16 +14,17 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.x.matrix.media
|
package io.element.android.x.matrix.ui.media
|
||||||
|
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.fetch.FetchResult
|
import coil.fetch.FetchResult
|
||||||
import coil.fetch.Fetcher
|
import coil.fetch.Fetcher
|
||||||
import coil.request.Options
|
import coil.request.Options
|
||||||
import io.element.android.x.matrix.MatrixClient
|
import io.element.android.x.matrix.MatrixClient
|
||||||
|
import io.element.android.x.matrix.media.MediaResolver
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
internal class MediaFetcher(
|
class MediaFetcher(
|
||||||
private val mediaResolver: MediaResolver?,
|
private val mediaResolver: MediaResolver?,
|
||||||
private val meta: MediaResolver.Meta,
|
private val meta: MediaResolver.Meta,
|
||||||
private val options: Options,
|
private val options: Options,
|
||||||
|
|
@ -14,12 +14,13 @@
|
||||||
* limitations under the License.
|
* 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.key.Keyer
|
||||||
import coil.request.Options
|
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? {
|
override fun key(data: MediaResolver.Meta, options: Options): String? {
|
||||||
return "${data.source.url()}_${data.kind}"
|
return "${data.source.url()}_${data.kind}"
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.x.features.roomlist.model
|
package io.element.android.x.matrix.ui.model
|
||||||
|
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import io.element.android.x.designsystem.components.avatar.AvatarData
|
import io.element.android.x.designsystem.components.avatar.AvatarData
|
||||||
|
|
@ -37,6 +37,7 @@ include(":app")
|
||||||
include(":libraries:core")
|
include(":libraries:core")
|
||||||
include(":libraries:rustsdk")
|
include(":libraries:rustsdk")
|
||||||
include(":libraries:matrix")
|
include(":libraries:matrix")
|
||||||
|
include(":libraries:matrixui")
|
||||||
include(":libraries:textcomposer")
|
include(":libraries:textcomposer")
|
||||||
include(":libraries:elementresources")
|
include(":libraries:elementresources")
|
||||||
include(":features:onboarding")
|
include(":features:onboarding")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue