Skip to content

Instantly share code, notes, and snippets.

View sanogueralorenzo's full-sized avatar
👋
Hello everyone!

Mario sanogueralorenzo

👋
Hello everyone!
View GitHub Profile
apply plugin: 'kotlin'
dependencies {
implementation Libraries.kotlin
}
apply plugin: 'com.android.dynamic-feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion Versions.compileSdk
defaultConfig {
minSdkVersion Versions.minSdk
targetSdkVersion Versions.targetSdk
val repositoryModule: Module = module {
single { PostRepositoryImpl(cache = get(), remote = get()) as PostRepository }
}
class App : Application() {
override fun onCreate() {
super.onCreate()
startKoin { androidContext(this@App) }
}
}
private val loadFeature by lazy { Posts.init() }
private fun injectFeature() = loadFeature
class PostListActivity : AppCompatActivity() {
private val vm: PostListViewModel by viewModel()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_post_list)
object PostsNavigation : DynamicFeature {
override fun start(c: Context): Intent? =
loadClassOrNull<Activity>("com.sanogueralorenzo.posts.presentation.postlist.PostListActivity")
?.let { Intent(c, it) }
}
private val classMap = mutableMapOf<String, Class<*>>()
private inline fun <reified T : Any> Any.castOrNull() = this as? T
internal fun <T> loadClassOrNull(className: String): Class<out T>? {
return classMap.getOrPut(className) {
try {
Class.forName(className)
} catch (e: ClassNotFoundException) {
return null
object PostsNavigation : DynamicFeature {
override val dynamicIntent: Intent?
get() = loadIntentOrNull("com.sanogueralorenzo.posts.PostListActivity")
}
private const val PACKAGE_NAME = "com.sanogueralorenzo.namingishard"
private fun intentTo(className: String): Intent =
Intent(Intent.ACTION_VIEW).setClassName(PACKAGE_NAME, className)
internal fun loadIntentOrNull(className: String): Intent? =
try {
Class.forName(className).run { intentTo(className) }
} catch (e: ClassNotFoundException) {
null
buildscript {
repositories {
jcenter()
}
}
plugins {
id "io.gitlab.arturbosch.detekt" version "1.0.0-RC10"
}