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