Improve images on timeline
This commit is contained in:
@@ -5,7 +5,6 @@ import coil.ImageLoader
|
||||
import coil.ImageLoaderFactory
|
||||
import com.airbnb.mvrx.Mavericks
|
||||
import io.element.android.x.matrix.MatrixInstance
|
||||
import io.element.android.x.matrix.media.MediaFetcher
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.plus
|
||||
@@ -26,7 +25,7 @@ class ElementXApplication : Application(), ImageLoaderFactory {
|
||||
return ImageLoader
|
||||
.Builder(this)
|
||||
.components {
|
||||
add(MediaFetcher.Factory(MatrixInstance.getInstance()))
|
||||
MatrixInstance.getInstance().registerComponents(this)
|
||||
}
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
@file:OptIn(ExperimentalFoundationApi::class)
|
||||
|
||||
package io.element.android.x.features.messages.components
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
@@ -12,12 +16,13 @@ fun MessagesTimelineItemImageView(
|
||||
content: MessagesTimelineItemImageContent,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Box(modifier) {
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
AsyncImage(
|
||||
model = content.imageMeta,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = modifier
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ fun MessagesTimelineItemInformativeView(
|
||||
Text(
|
||||
fontStyle = FontStyle.Italic,
|
||||
color = MaterialTheme.colorScheme.secondary,
|
||||
fontSize = 12.sp,
|
||||
fontSize = 14.sp,
|
||||
text = text
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,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.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 kotlinx.coroutines.CoroutineScope
|
||||
@@ -55,6 +58,11 @@ class Matrix(
|
||||
return matrixClient.value.get()
|
||||
}
|
||||
|
||||
fun registerComponents(builder: ComponentRegistry.Builder) {
|
||||
builder.add(MediaKeyer())
|
||||
builder.add(MediaFetcher.Factory(this))
|
||||
}
|
||||
|
||||
suspend fun restoreSession() = withContext(coroutineDispatchers.io) {
|
||||
sessionStore.getLatestSession()
|
||||
?.let { session ->
|
||||
@@ -88,8 +96,8 @@ class Matrix(
|
||||
withContext(coroutineDispatchers.io) {
|
||||
val client = try {
|
||||
authService.login(username, password, "ElementX", null)
|
||||
}catch (failure:Throwable){
|
||||
Timber.e(failure,"Fail login")
|
||||
} catch (failure: Throwable) {
|
||||
Timber.e(failure, "Fail login")
|
||||
throw failure
|
||||
}
|
||||
sessionStore.storeData(client.session())
|
||||
|
||||
@@ -7,7 +7,7 @@ import coil.request.Options
|
||||
import io.element.android.x.matrix.Matrix
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class MediaFetcher(
|
||||
internal class MediaFetcher(
|
||||
private val mediaResolver: MediaResolver,
|
||||
private val meta: MediaResolver.Meta,
|
||||
private val options: Options,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
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}"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user