Skip to content

Commit

Permalink
Use singleton ImageLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Oct 7, 2024
1 parent 8122d32 commit ae3db67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 4 additions & 0 deletions WordPress/src/main/java/org/wordpress/android/WordPress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import android.content.Context
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.decode.VideoFrameDecoder
import com.android.volley.RequestQueue
import dagger.hilt.EntryPoints
import org.wordpress.android.fluxc.tools.FluxCImageLoader
Expand All @@ -25,6 +26,9 @@ abstract class WordPress : Application(), ImageLoaderFactory {
override fun newImageLoader(): ImageLoader {
return ImageLoader.Builder(this)
.crossfade(true)
.components {
add(VideoFrameDecoder.Factory())
}
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.ImageLoader
import coil.compose.AsyncImage
import coil.decode.VideoFrameDecoder
import coil.imageLoader
import coil.request.ImageRequest
import org.wordpress.android.R

Expand Down Expand Up @@ -81,18 +80,13 @@ private fun MediaUriImage(uri: Uri) {
val context = LocalContext.current
val mimeType = context.contentResolver.getType(uri)
if (mimeType?.startsWith("video/") == true) {
val imageLoader = ImageLoader.Builder(LocalContext.current)
.components {
add(VideoFrameDecoder.Factory())
}
.build()
Box {
AsyncImage(
model = ImageRequest.Builder(context)
.data(uri)
.crossfade(true)
.build(),
imageLoader = imageLoader,
imageLoader = context.imageLoader,
contentScale = ContentScale.Crop,
contentDescription = null,
modifier = Modifier
Expand Down

0 comments on commit ae3db67

Please sign in to comment.