Last active
November 12, 2019 06:48
-
-
Save kirich1409/8b519d41cce1ed5773dff481fe397cb7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class InjectFragmentFactory( | |
private val providers: Map<String, Provider<Fragment>> | |
) : FragmentFactory() { | |
override fun instantiate(classLoader: ClassLoader, className: String): Fragment { | |
return providers[className]?.get() ?: super.instantiate(classLoader, className) | |
} | |
companion object { | |
operator fun invoke( | |
providers: Map<Class<out Fragment>, Provider<Fragment>> | |
) : InjectFragmentFactory { | |
return InjectFragmentFactory( | |
providers.mapKeys { (fragmentClass, _) -> fragmentClass.name } | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment