Skip to content

Commit

Permalink
# implemented activity context injection for Beans injected by Views
Browse files Browse the repository at this point in the history
  • Loading branch information
sbra0902 committed Jun 2, 2020
1 parent 45ff6f0 commit 670c78f
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.schwarz.kokain.di
import android.app.Activity
import android.app.Application
import android.content.Context
import android.view.View
import androidx.activity.ComponentActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleObserver
Expand Down Expand Up @@ -35,6 +36,9 @@ class ActivityContextGuard(applicationContext: Application) : LifecycleObserver
if (thisRef is Activity) {
return thisRef?.equals(currentRef?.get()?.toString())
}
if(thisRef is View){
return thisRef?.context?.equals(currentRef?.get()?.toString()) ?: false
}
return false
}

Expand All @@ -48,6 +52,9 @@ class ActivityContextGuard(applicationContext: Application) : LifecycleObserver
if (thisRef is Activity) {
bean.activityRef = thisRef?.toString()
}
if(thisRef is View){
bean.activityRef = thisRef?.context?.toString()
}
}


Expand Down

0 comments on commit 670c78f

Please sign in to comment.