Skip to content

Commit

Permalink
Remove Glide in favor of Coil
Browse files Browse the repository at this point in the history
  • Loading branch information
mardous committed Nov 16, 2024
1 parent b6f172d commit 0c7b81c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ dependencies {
implementation(libs.koin.core)
implementation(libs.koin.android)

implementation(libs.coil)
implementation(libs.coil.video)

implementation(libs.photoview)
implementation(libs.insetter)
implementation(libs.retrofit)
implementation(libs.retrofit.converter.gson)
implementation(libs.okhttp3.logging)
implementation(libs.gson)
implementation(libs.glide)
implementation(libs.versioncompare)
implementation(libs.libphonenumber)
implementation(libs.prettytime)
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/com/simplified/wsstatussaver/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ package com.simplified.wsstatussaver

import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import coil3.ImageLoader
import coil3.PlatformContext
import coil3.SingletonImageLoader
import coil3.request.crossfade
import coil3.video.VideoFrameDecoder
import com.simplified.wsstatussaver.extensions.getDefaultDayNightMode
import com.simplified.wsstatussaver.extensions.isAnalyticsEnabled
import com.simplified.wsstatussaver.extensions.migratePreferences
Expand All @@ -28,7 +33,7 @@ fun getApp(): App = App.instance
/**
* @author Christians Martínez Alvarado (mardous)
*/
class App : Application() {
class App : Application(), SingletonImageLoader.Factory {

override fun onCreate() {
super.onCreate()
Expand All @@ -47,6 +52,15 @@ class App : Application() {
AppCompatDelegate.setDefaultNightMode(preferences().getDefaultDayNightMode())
}

override fun newImageLoader(context: PlatformContext): ImageLoader {
return ImageLoader.Builder(context)
.crossfade(true)
.components {
add(VideoFrameDecoder.Factory())
}
.build()
}

val versionName: String
get() = packageManager.packageInfo().versionName ?: "0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import androidx.appcompat.view.ActionMode
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.engine.DiskCacheStrategy
import coil3.load
import coil3.video.VideoFrameDecoder
import com.google.android.material.card.MaterialCardView
import com.simplified.wsstatussaver.R
import com.simplified.wsstatussaver.adapter.base.AbsMultiSelectionAdapter
Expand All @@ -39,6 +39,7 @@ import com.simplified.wsstatussaver.extensions.getClientIfInstalled
import com.simplified.wsstatussaver.extensions.getState
import com.simplified.wsstatussaver.interfaces.IStatusCallback
import com.simplified.wsstatussaver.model.Status
import com.simplified.wsstatussaver.model.StatusType
import kotlin.properties.Delegates
import kotlin.reflect.KProperty

Expand All @@ -48,7 +49,6 @@ import kotlin.reflect.KProperty
@SuppressLint("NotifyDataSetChanged")
open class StatusAdapter(
protected val activity: FragmentActivity,
private val requestManager: RequestManager,
private val callback: IStatusCallback,
private var isSaveEnabled: Boolean,
private var isDeleteEnabled: Boolean,
Expand Down Expand Up @@ -78,11 +78,12 @@ open class StatusAdapter(
holder.itemView.isActivated = isItemSelected(status)
}

if (holder.image != null) {
requestManager.load(status.fileUri)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop()
.into(holder.image)
if (status.type == StatusType.VIDEO) {
holder.image?.load(status.fileUri) {
decoderFactory { result, options, _ -> VideoFrameDecoder(result.source, options) }
}
} else {
holder.image?.load(status.fileUri)
}

if (holder.state != null && holder.state.isVisible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package com.simplified.wsstatussaver.fragments.playback.image
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import coil3.load
import com.google.android.material.button.MaterialButton
import com.simplified.wsstatussaver.R
import com.simplified.wsstatussaver.databinding.FragmentImageBinding
Expand Down Expand Up @@ -44,10 +44,7 @@ class ImageFragment : PlaybackChildFragment(R.layout.fragment_image) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
_binding = FragmentImageBinding.bind(view)
Glide.with(this)
.asBitmap()
.load(status.fileUri)
.into(imageView)
imageView.load(status.fileUri)
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package com.simplified.wsstatussaver.fragments.statuses
import android.content.SharedPreferences
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import com.simplified.wsstatussaver.adapter.StatusAdapter
import com.simplified.wsstatussaver.extensions.PREFERENCE_DEFAULT_CLIENT
import com.simplified.wsstatussaver.extensions.PREFERENCE_EXCLUDE_SAVED_STATUSES
Expand Down Expand Up @@ -49,7 +48,6 @@ class HomeStatusesFragment : StatusesFragment(), SharedPreferences.OnSharedPrefe
override fun onCreateAdapter(): StatusAdapter {
return StatusAdapter(
requireActivity(),
Glide.with(this),
this,
isSaveEnabled = true,
isDeleteEnabled = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package com.simplified.wsstatussaver.fragments.statuses

import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import com.simplified.wsstatussaver.adapter.StatusAdapter
import com.simplified.wsstatussaver.model.StatusQueryResult
import com.simplified.wsstatussaver.model.StatusType
Expand All @@ -41,7 +40,6 @@ class SavedStatusesFragment : StatusesFragment() {
override fun onCreateAdapter(): StatusAdapter =
StatusAdapter(
requireActivity(),
Glide.with(this),
this,
isSaveEnabled = false,
isDeleteEnabled = true,
Expand Down
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ roomVersion = "2.6.1"
koinVersion = "4.0.0"
swiperefreshlayout = "1.1.0"
advrecyclerview = "1.0.0"
glideVersion = "4.16.0"
coilVersion = "3.0.2"
versioncompare = "1.5.0"
viewpager2 = "1.1.0"
markdown = "4.6.2"
Expand Down Expand Up @@ -80,7 +80,9 @@ room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomVersion" }
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koinVersion" }
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koinVersion" }

glide = { module = "com.github.bumptech.glide:glide", version.ref = "glideVersion" }
coil = { module = "io.coil-kt.coil3:coil", version.ref = "coilVersion" }
coil-video = { module = "io.coil-kt.coil3:coil-video", version.ref = "coilVersion" }

advrecyclerview = { module = "com.h6ah4i.android.widget.advrecyclerview:advrecyclerview", version.ref = "advrecyclerview" }
libphonenumber = { module = "io.michaelrocks:libphonenumber-android", version.ref = "libphonenumberAndroid" }
prettytime = { module = "org.ocpsoft.prettytime:prettytime", version.ref = "prettytime" }
Expand Down

0 comments on commit 0c7b81c

Please sign in to comment.