Skip to content
Snippets Groups Projects
Commit 6cbd6b1a authored by Mohamed Metwalli's avatar Mohamed Metwalli
Browse files

Use view context instead of appContext

parent 0317165d
No related branches found
No related tags found
No related merge requests found
......@@ -24,11 +24,11 @@ fun setChecked(switch: Switch, status: Boolean?) {
@BindingAdapter("animation")
fun setAnimation(view: LottieAnimationView, animation: Int?) {
if (animation != null) {
val appContext = view.context.applicationContext
val type = appContext.resources.getResourceTypeName(animation)
val context = view.context
val type = context.resources.getResourceTypeName(animation)
if (type == DRAWABLE_TYPE) {
view.setImageDrawable(appContext.getDrawable(animation))
view.setImageDrawable(context.getDrawable(animation))
} else {
view.setAnimation(animation)
view.repeatCount = LottieDrawable.INFINITE
......
package de.rki.coronawarnapp.util
import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.widget.Switch
import com.airbnb.lottie.LottieAnimationView
......@@ -67,8 +68,8 @@ class DataBindingAdaptersTest {
private fun setAnimation(animation: Int?) {
val animationView = mockk<LottieAnimationView>(relaxUnitFun = true).apply {
every { context } returns mockk<Context>().apply {
every { applicationContext } returns mockk<Context>().apply {
every { resources.getResourceTypeName(any()) } returns "raw"
every { resources } returns mockk<Resources>().apply {
every { getResourceTypeName(any()) } returns "raw"
}
}
}
......@@ -110,10 +111,10 @@ class DataBindingAdaptersTest {
private fun setDrawable(drawableId: Int?) {
val animationView = mockk<LottieAnimationView>(relaxUnitFun = true).apply {
every { context } returns mockk<Context>().apply {
every { applicationContext } returns mockk<Context>().apply {
every { resources.getResourceTypeName(any()) } returns DRAWABLE_TYPE
every { getDrawable(any()) } returns this@DataBindingAdaptersTest.drawable
every { resources } returns mockk<Resources>().apply {
every { getResourceTypeName(any()) } returns DRAWABLE_TYPE
}
every { getDrawable(any()) } returns this@DataBindingAdaptersTest.drawable
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment