Create matrixui module and remove dependency to coil in the matrix module. Move MatrixUser there.
This commit is contained in:
parent
4431f037ab
commit
c5c05e3867
17 changed files with 106 additions and 24 deletions
|
|
@ -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 ->
|
||||
|
|
|
|||
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* 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.media
|
||||
|
||||
import coil.ImageLoader
|
||||
import coil.fetch.FetchResult
|
||||
import coil.fetch.Fetcher
|
||||
import coil.request.Options
|
||||
import io.element.android.x.matrix.MatrixClient
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
internal class MediaFetcher(
|
||||
private val mediaResolver: MediaResolver?,
|
||||
private val meta: MediaResolver.Meta,
|
||||
private val options: Options,
|
||||
private val imageLoader: ImageLoader
|
||||
) : Fetcher {
|
||||
|
||||
override suspend fun fetch(): FetchResult? {
|
||||
val byteArray = mediaResolver?.resolve(meta) ?: return null
|
||||
val byteBuffer = ByteBuffer.wrap(byteArray)
|
||||
return imageLoader.components.newFetcher(byteBuffer, options, imageLoader)?.first?.fetch()
|
||||
}
|
||||
|
||||
class Factory(private val activeClientProvider: () -> MatrixClient?) :
|
||||
Fetcher.Factory<MediaResolver.Meta> {
|
||||
override fun create(
|
||||
data: MediaResolver.Meta,
|
||||
options: Options,
|
||||
imageLoader: ImageLoader
|
||||
): Fetcher {
|
||||
val activeClient = activeClientProvider()
|
||||
return MediaFetcher(
|
||||
mediaResolver = activeClient?.mediaResolver(),
|
||||
meta = data,
|
||||
options = options,
|
||||
imageLoader = imageLoader
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* 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.media
|
||||
|
||||
import coil.key.Keyer
|
||||
import coil.request.Options
|
||||
|
||||
internal class MediaKeyer : Keyer<MediaResolver.Meta> {
|
||||
override fun key(data: MediaResolver.Meta, options: Options): String? {
|
||||
return "${data.source.url()}_${data.kind}"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue