From 6cbd6b1abca296fb5e70252b597094364ed6d513 Mon Sep 17 00:00:00 2001
From: Mohamed Metwalli <mohamed.metwalli@sap.com>
Date: Tue, 12 Jan 2021 09:47:56 +0100
Subject: [PATCH] Use view context instead of appContext

---
 .../de/rki/coronawarnapp/util/DataBindingAdapters.kt  |  6 +++---
 .../rki/coronawarnapp/util/DataBindingAdaptersTest.kt | 11 ++++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/DataBindingAdapters.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/DataBindingAdapters.kt
index 470055bbe..66e55ff3c 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/DataBindingAdapters.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/DataBindingAdapters.kt
@@ -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
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/DataBindingAdaptersTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/DataBindingAdaptersTest.kt
index 456f008a6..3612eb9a3 100644
--- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/DataBindingAdaptersTest.kt
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/DataBindingAdaptersTest.kt
@@ -1,6 +1,7 @@
 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
             }
         }
 
-- 
GitLab