Skip to content

Commit

Permalink
Migrated from Glide to Coil - tests needed for detecting possible issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Jul 1, 2020
1 parent 1c7e697 commit 7884aa7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -40,7 +40,7 @@ android {
applicationId "com.javinator9889.handwashingreminder"
minSdkVersion 17
targetSdkVersion 29
versionCode 133
versionCode 134
versionName "1.2.0-${gitCommitHash}"
multiDexEnabled true
resConfigs "en", "es"
Expand Down
Expand Up @@ -84,7 +84,7 @@ class NewsFragment : BaseFragmentView(), LayoutVisibilityChange {
imageUrl = it.elements?.url,
website = it.website?.name,
websiteImageUrl = it.website?.iconURL,
lifecycleScope = this@NewsFragment.lifecycleScope
lifecycleOwner = this@NewsFragment
)
newsAdapter.add(newsObject)
loading.visibility = View.INVISIBLE
Expand Down
Expand Up @@ -22,10 +22,11 @@ import android.annotation.SuppressLint
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import coil.Coil
import coil.api.load
import coil.request.GetRequest
import coil.size.Scale
import com.airbnb.lottie.LottieAnimationView
import com.google.android.material.card.MaterialCardView
import com.javinator9889.handwashingreminder.R
Expand All @@ -45,7 +46,7 @@ data class News(
val imageUrl: String?,
val website: String?,
val websiteImageUrl: String?,
val lifecycleScope: LifecycleCoroutineScope,
val lifecycleOwner: LifecycleOwner,
override val layoutRes: Int = R.layout.news_card_view,
override val type: Int = 1
) : AbstractItem<News.ViewHolder>() {
Expand All @@ -68,29 +69,45 @@ data class News(
val formatter = DateFormat.getDateTimeInstance()
val context = view.context
imageHeader.setAnimation(R.raw.downloading)
item.lifecycleScope.launch(context = Dispatchers.Main) {
item.lifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
title.text = item.title
description.text = item.short
val imageLoader = Coil.imageLoader(view.context)
if (item.imageUrl != null) {
val request = GetRequest.Builder(view.context)
imageHeader.load(item.imageUrl) {
scale(Scale.FILL)
lifecycle(item.lifecycleOwner)
allowHardware(true)
}
/*val request = GetRequest.Builder(view.context)
.data(item.imageUrl)
.size(imageHeader.width, imageHeader.height)
.allowHardware(true)
.scale(Scale.FILL)
.build()
launch(Dispatchers.IO) {
imageHeader.load(imageLoader.execute(request).drawable)
}
val drawable = imageLoader.execute(request).drawable
withContext(Dispatchers.Main) {
imageHeader.setImageDrawable(drawable)
}
}*/
} else imageHeader.visibility = View.GONE
if (item.websiteImageUrl != null) {
val request = GetRequest.Builder(view.context)
websiteLogo.load(item.websiteImageUrl) {
scale(Scale.FILL)
lifecycle(item.lifecycleOwner)
allowHardware(true)
}
/*val request = GetRequest.Builder(view.context)
.data(item.websiteImageUrl)
.size(websiteLogo.width, websiteLogo.height)
.allowHardware(true)
.scale(Scale.FILL)
.build()
launch(Dispatchers.IO) {
websiteLogo.load(imageLoader.execute(request).drawable)
}
val drawable = imageLoader.execute(request).drawable
withContext(Dispatchers.Main) {
websiteLogo.setImageDrawable(drawable)
}
}*/
} else websiteLogo.visibility = View.GONE
websiteName.text = item.website
?: context.getString(R.string.no_website)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/news_card_view.xml
Expand Up @@ -29,8 +29,9 @@

<com.javinator9889.handwashingreminder.graphics.LottieAdaptedPerformanceAnimationView
android:id="@+id/imageHeader"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="150dp"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down

0 comments on commit 7884aa7

Please sign in to comment.