Twelve: Use Coil for thumbnails
Change-Id: Iee86907e0a2ebb8d9c2f21d331ad6c4a4ba5eaaf
diff --git a/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt
index ffbbd9b..0193b0f 100644
--- a/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt
+++ b/app/src/main/java/org/lineageos/twelve/fragments/AlbumFragment.kt
@@ -5,7 +5,6 @@
package org.lineageos.twelve.fragments
-import android.graphics.ImageDecoder
import android.net.Uri
import android.os.Bundle
import android.util.Log
@@ -26,6 +25,7 @@
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController
import androidx.recyclerview.widget.RecyclerView
+import coil3.load
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.progressindicator.LinearProgressIndicator
import kotlinx.coroutines.flow.collectLatest
@@ -178,16 +178,9 @@
albumTitleTextView.text = album.title
album.thumbnail?.uri?.also { uri ->
- ImageDecoder.createSource(
- requireContext().contentResolver,
- uri
- ).let { source ->
- ImageDecoder.decodeBitmap(source)
- }.also { bitmap ->
- thumbnailImageView.setImageBitmap(bitmap)
- }
+ thumbnailImageView.load(uri)
} ?: album.thumbnail?.bitmap?.also { bitmap ->
- thumbnailImageView.setImageBitmap(bitmap)
+ thumbnailImageView.load(bitmap)
} ?: thumbnailImageView.setImageResource(R.drawable.ic_album)
artistNameTextView.text = album.artistName
diff --git a/app/src/main/java/org/lineageos/twelve/fragments/ArtistFragment.kt b/app/src/main/java/org/lineageos/twelve/fragments/ArtistFragment.kt
index a0e1364..5c3d0ca 100644
--- a/app/src/main/java/org/lineageos/twelve/fragments/ArtistFragment.kt
+++ b/app/src/main/java/org/lineageos/twelve/fragments/ArtistFragment.kt
@@ -5,7 +5,6 @@
package org.lineageos.twelve.fragments
-import android.graphics.ImageDecoder
import android.net.Uri
import android.os.Bundle
import android.util.Log
@@ -26,6 +25,7 @@
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController
import androidx.recyclerview.widget.RecyclerView
+import coil3.load
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.progressindicator.LinearProgressIndicator
import kotlinx.coroutines.flow.collectLatest
@@ -83,16 +83,9 @@
override fun ViewHolder.onBindView(item: Album) {
item.thumbnail?.uri?.also { uri ->
- ImageDecoder.createSource(
- requireContext().contentResolver,
- uri
- ).let { source ->
- ImageDecoder.decodeBitmap(source)
- }.also { bitmap ->
- view.setThumbnailImage(bitmap)
- }
+ view.loadThumbnailImage(uri)
} ?: item.thumbnail?.bitmap?.also { bitmap ->
- view.setThumbnailImage(bitmap)
+ view.loadThumbnailImage(bitmap)
} ?: view.setThumbnailImage(R.drawable.ic_album)
view.headlineText = item.title
@@ -197,16 +190,9 @@
toolbar.title = artist.name
artist.thumbnail?.uri?.also { uri ->
- ImageDecoder.createSource(
- requireContext().contentResolver,
- uri
- ).let { source ->
- ImageDecoder.decodeBitmap(source)
- }.also { bitmap ->
- thumbnailImageView.setImageBitmap(bitmap)
- }
+ thumbnailImageView.load(uri)
} ?: artist.thumbnail?.bitmap?.also { bitmap ->
- thumbnailImageView.setImageBitmap(bitmap)
+ thumbnailImageView.load(bitmap)
} ?: thumbnailImageView.setImageResource(R.drawable.ic_person)
albumsAdapter.submitList(artistWorks.albums)
diff --git a/app/src/main/java/org/lineageos/twelve/ui/views/HorizontalListItem.kt b/app/src/main/java/org/lineageos/twelve/ui/views/HorizontalListItem.kt
index 096e378..0762dc4 100644
--- a/app/src/main/java/org/lineageos/twelve/ui/views/HorizontalListItem.kt
+++ b/app/src/main/java/org/lineageos/twelve/ui/views/HorizontalListItem.kt
@@ -16,6 +16,8 @@
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.view.isVisible
+import coil3.load
+import coil3.request.ImageRequest
import org.lineageos.twelve.R
/**
@@ -50,6 +52,10 @@
inflate(context, R.layout.horizontal_list_item, this)
}
+ fun loadThumbnailImage(
+ data: Any?, builder: ImageRequest.Builder.() -> Unit = {}
+ ) = thumbnailImageView.load(data, builder = builder)
+
fun setThumbnailImage(bm: Bitmap) = thumbnailImageView.setImageBitmap(bm)
fun setThumbnailImage(icon: Icon) = thumbnailImageView.setImageIcon(icon)
fun setThumbnailImage(@DrawableRes resId: Int) = thumbnailImageView.setImageResource(resId)