feat: switch to glide from coil
caching happens quite a bit more aggressively with glide and scrolling through a channel is a breeze now
This commit is contained in:
parent
1ef7d6610b
commit
efdc035406
|
|
@ -92,11 +92,9 @@ dependencies {
|
|||
implementation "androidx.hilt:hilt-navigation-compose:1.1.0-alpha01"
|
||||
kapt "com.google.dagger:hilt-compiler:$hilt_version"
|
||||
|
||||
// Coil - Image Loading
|
||||
implementation "io.coil-kt:coil:$coil_version"
|
||||
implementation "io.coil-kt:coil-compose:$coil_version"
|
||||
implementation "io.coil-kt:coil-svg:$coil_version"
|
||||
implementation "io.coil-kt:coil-gif:$coil_version"
|
||||
// Glide - Image Loading
|
||||
implementation "com.github.bumptech.glide:glide:$glide_version"
|
||||
implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"
|
||||
|
||||
// AboutLibraries - automated OSS library attribution
|
||||
implementation "com.mikepenz:aboutlibraries-compose:$aboutlibraries_version"
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ fun Message(
|
|||
modifier = Modifier
|
||||
.size(50.dp)
|
||||
.clip(CircleShape),
|
||||
crossfade = false,
|
||||
description = "Avatar for ${author.username}"
|
||||
)
|
||||
} else {
|
||||
|
|
@ -69,7 +68,6 @@ fun Message(
|
|||
modifier = Modifier
|
||||
.size(50.dp)
|
||||
.clip(CircleShape),
|
||||
crossfade = false,
|
||||
description = "Avatar for ${author.username}"
|
||||
)
|
||||
}
|
||||
|
|
@ -114,7 +112,6 @@ fun Message(
|
|||
width = attachment.metadata.width?.toInt() ?: 0,
|
||||
height = attachment.metadata.height?.toInt() ?: 0,
|
||||
contentScale = ContentScale.Fit,
|
||||
crossfade = true,
|
||||
description = "Attached image ${attachment.filename}"
|
||||
)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
package chat.revolt.components.generic
|
||||
|
||||
import android.os.Build
|
||||
import android.util.DisplayMetrics
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import chat.revolt.BuildConfig
|
||||
import coil.ImageLoader
|
||||
import coil.compose.AsyncImage
|
||||
import coil.decode.GifDecoder
|
||||
import coil.decode.ImageDecoderDecoder
|
||||
import coil.decode.SvgDecoder
|
||||
import coil.memory.MemoryCache
|
||||
import coil.request.ImageRequest
|
||||
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
|
||||
import com.bumptech.glide.integration.compose.GlideImage
|
||||
|
||||
@OptIn(ExperimentalGlideComposeApi::class)
|
||||
@Composable
|
||||
fun RemoteImage(
|
||||
url: String,
|
||||
|
|
@ -22,42 +22,21 @@ fun RemoteImage(
|
|||
contentScale: ContentScale = ContentScale.Crop,
|
||||
width: Int = 0,
|
||||
height: Int = 0,
|
||||
crossfade: Boolean = true,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
fun imageRequest() = run {
|
||||
val builder = ImageRequest.Builder(context)
|
||||
.crossfade(crossfade)
|
||||
.data(url)
|
||||
|
||||
if (width != 0 && height != 0) {
|
||||
builder.size(width, height)
|
||||
}
|
||||
|
||||
builder.build()
|
||||
fun pxAsDp(px: Int): Dp {
|
||||
return (px / (context.resources
|
||||
.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT)).dp
|
||||
}
|
||||
|
||||
AsyncImage(
|
||||
model = imageRequest(),
|
||||
imageLoader = ImageLoader.Builder(context)
|
||||
.components {
|
||||
if (Build.VERSION.SDK_INT >= 28) {
|
||||
add(ImageDecoderDecoder.Factory())
|
||||
} else {
|
||||
add(GifDecoder.Factory())
|
||||
}
|
||||
add(SvgDecoder.Factory())
|
||||
}
|
||||
.memoryCache {
|
||||
MemoryCache.Builder(context)
|
||||
.maxSizePercent(.25)
|
||||
.build()
|
||||
}
|
||||
.build(),
|
||||
GlideImage(
|
||||
model = url,
|
||||
contentDescription = description,
|
||||
contentScale = contentScale,
|
||||
modifier = modifier,
|
||||
modifier = modifier
|
||||
.width(pxAsDp(width))
|
||||
.height(pxAsDp(height)),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -212,8 +212,8 @@ class ChannelScreenViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
fun sendPendingMessage() {
|
||||
|
||||
setSendingMessage(true)
|
||||
|
||||
viewModelScope.launch {
|
||||
val attachmentIds = arrayListOf<String>()
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ buildscript {
|
|||
nav_version = '2.5.3'
|
||||
hilt_version = '2.44'
|
||||
coil_version = '2.2.2'
|
||||
glide_version = '4.14.2'
|
||||
ktor_version = '2.1.3'
|
||||
aboutlibraries_version = '10.5.2'
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue