Last active
January 9, 2018 11:08
-
-
Save makovkastar/a58ae3a4de689da1446ea31b8625ec4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Injector { | |
fun init(application: MvvmTestingApplication) { | |
application.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks { | |
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { | |
if (activity is HasSupportFragmentInjector && activity is Injectable) { | |
AndroidInjection.inject(activity) | |
} | |
if (activity is FragmentActivity) { | |
activity.supportFragmentManager.registerFragmentLifecycleCallbacks( | |
object : FragmentManager.FragmentLifecycleCallbacks() { | |
override fun onFragmentPreAttached(fm: FragmentManager, f: Fragment, context: Context) { | |
if (f is Injectable) { | |
AndroidSupportInjection.inject(f) | |
} | |
} | |
}, true) | |
} | |
} | |
override fun onActivityStarted(activity: Activity) { | |
} | |
override fun onActivityResumed(activity: Activity) { | |
} | |
override fun onActivityPaused(activity: Activity) { | |
} | |
override fun onActivityStopped(activity: Activity) { | |
} | |
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { | |
} | |
override fun onActivityDestroyed(activity: Activity) { | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment