Skip to content

Instantly share code, notes, and snippets.

Ege Kuzubasioglu egek92

Block or report user

Report or block egek92

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View MainActivity.kt
override fun onStop() {
super.onStop()
unregisterReceiver(broadcastReceiver)
killService(locationListener)
}
View ComponentKoin.kt
val appComponent: List<Module> = listOf(dataBaseModule, networkModule, activityModule)
View ComponentDagger.kt
@Singleton
@Component(
modules = [
DataBaseModule::class,
NetworkModule::class,
ActivityModule::class]
)
interface AppComponent {
@Component.Builder
interface Builder {
View ModuleKoin.kt
val dataBaseModule = module {
single {
Room.databaseBuilder(androidContext(), AppDatabase::class.java, BuildConfig.APPLICATION_ID)
.fallbackToDestructiveMigration()
.build()
}
single { (get() as AppDatabase).hotelsDao() }
single { (get() as AppDatabase).visitors() }
View ModuleDagger.kt
@Module
class DataBaseModule {
@Provides
@Singleton
fun provideRoom(app: Application): AppDatabase = Room
.databaseBuilder(app, AppDatabase::class.java, BuildConfig.APPLICATION_ID)
.build()
@Provides
@Singleton
View ViewModelInjectionDagger.kt
@Singleton
class ViewModelFactory @Inject constructor(private val viewModels: MutableMap<Class<out ViewModel>, Provider<ViewModel>>) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T = viewModels[modelClass]?.get() as T
}
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
@MapKey
View gist:ce5f1b2bae85f0f18b202773c65003d3
@Singleton
class ViewModelFactory @Inject constructor(private val viewModels: MutableMap<Class<out ViewModel>, Provider<ViewModel>>) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T = viewModels[modelClass]?.get() as T
}
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
@MapKey
View ScopeKoin.kt
// define scope in your module
module {
scope("scope_id") { Presenter() }
}
// use scope in your activity
class SomeActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ... other required stuff
View koin.groovy
implementation "org.koin:koin-android:${koinVersion}"
implementation "org.koin:koin-androidx-scope:${koinVersion}" // optional
implementation "org.koin:koin-androidx-viewmodel:${koinVersion}" // optional
View dagger.groovy
implementation "com.google.dagger:dagger:${daggerVersion}"
kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
implementation "com.google.dagger:dagger-android:${daggerVersion}"
implementation "com.google.dagger:dagger-android-support:${daggerVersion}"
kapt "com.google.dagger:dagger-android-processor:${daggerVersion}"
You can’t perform that action at this time.