Commit 93891452 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

successfully move to dagger 2

remove koin dependencies
parent d4de5bcd
......@@ -67,14 +67,6 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'androidx.core:core-ktx:1.1.0'
//Koin
implementation "org.koin:koin-core:$koinVersion"
implementation "org.koin:koin-core-ext:$koinVersion"
implementation "org.koin:koin-android:$koinVersion"
implementation "org.koin:koin-android-scope:$koinVersion"
implementation "org.koin:koin-androidx-scope:$koinVersion"
//Material
implementation "com.google.android.material:material:$materialVersion"
......@@ -108,6 +100,16 @@ dependencies {
implementation "com.jakewharton:butterknife:$butterKnifeVersion"
kapt "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
//Dagger2
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"
//Tests
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
......
package com.biganto.visual.roompark.base
import android.os.Bundle
import android.os.PersistableBundle
import dagger.android.support.DaggerAppCompatActivity
import io.reactivex.disposables.CompositeDisposable
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
abstract class BaseRoomParkActivity : DaggerAppCompatActivity(){
protected val disposable = CompositeDisposable()
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
}
override fun onDestroy() {
super.onDestroy()
disposable.clear()
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
}
}
\ No newline at end of file
package com.biganto.visual.roompark.base
import android.app.Application
import android.util.Log
import com.biganto.visual.roompark.BuildConfig
import com.biganto.visual.roompark.di.koin.initDI
import com.biganto.visual.roompark.di.dagger.DaggerAppComponent
import com.crashlytics.android.Crashlytics
import com.squareup.picasso.Picasso
import dagger.android.AndroidInjector
import dagger.android.DaggerApplication
import timber.log.Timber
/**
* Created by Vladislav Bogdashkin on 03.09.2019.
*/
class RoomParkApplication : Application() {
class RoomParkApplication : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerAppComponent.builder()
.context(this)
.build()
}
override fun onCreate() {
super.onCreate()
initDI()
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
else Timber.plant(CrashlyticsTree())
......
......@@ -3,10 +3,10 @@ package com.biganto.visual.roompark.base
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import butterknife.BindView
import butterknife.ButterKnife
import com.biganto.visual.roompark.BuildConfig
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.view_utils.app_bar.DragControlAppBarLayoutBehaviour
......@@ -18,15 +18,16 @@ import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.CollapsingToolbarLayout
import com.google.android.material.bottomnavigation.BottomNavigationView
import io.fabric.sdk.android.Fabric
import org.koin.android.scope.currentScope
import javax.inject.Inject
class RoomParkMainActivity(
) : AppCompatActivity()
) : BaseRoomParkActivity()
,ICollapsingToolBar
,IConductorActivity
,IBottomNavigation{
private val snackbarProvider: ISnackBarProvider by currentScope.inject()
@Inject
lateinit var snackbarProvider: ISnackBarProvider
private lateinit var router: Router
......@@ -45,6 +46,8 @@ class RoomParkMainActivity(
setContentView(R.layout.activity_main)
ButterKnife.bind(this)
setSupportActionBar(topAppBar)
router = Conductor.attachRouter(this, conductorContainer, savedInstanceState)
......
package com.biganto.visual.roompark.di.dagger
import android.app.Activity
import android.content.Context
import android.content.res.Resources
import com.biganto.visual.roompark.base.BaseRoomParkActivity
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.view_utils.snackbar.ISnackBarProvider
import com.biganto.visual.roompark.view_utils.snackbar.SnackBarProvider
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.android.ContributesAndroidInjector
/**
* Created by Vladislav Bogdashkin on 31.07.2019.
*/
@Module
abstract class ActivityModule {
@Binds
abstract fun providesContext(activity: Activity):Context
@Module
companion object{
@JvmStatic
@Provides
fun provideResources(activity: Activity) : Resources = activity.resources
@JvmStatic
@Provides
fun provideSnackBar(activity: Activity): ISnackBarProvider{
return SnackBarProvider(activity)
}
}
}
@Module
abstract class AppActivityModule {
@Module
internal interface MainActivityModule {
@Binds
fun bindMainActivity(activity: RoomParkMainActivity): Activity
}
@Module
internal interface BaseActivityModule {
@Binds
fun bindBaseActivity(activity: BaseRoomParkActivity): Activity
}
@ContributesAndroidInjector(
modules = [ActivityModule::class, MainActivityModule::class])
abstract fun contributeMainActivityInjector(): RoomParkMainActivity
@ContributesAndroidInjector(
modules = [ActivityModule::class, BaseActivityModule::class])
abstract fun contributeBaseActivityInjector(): BaseRoomParkActivity
}
package com.biganto.visual.roompark.di.dagger
import android.app.Application
import com.biganto.visual.roompark.base.RoomParkApplication
import dagger.BindsInstance
import dagger.Component
import dagger.android.AndroidInjectionModule
import dagger.android.AndroidInjector
import dagger.android.support.AndroidSupportInjectionModule
import javax.inject.Singleton
/**
* Created by Vladislav Bogdashkin on 13.06.2018.
*/
@Singleton
@Component(modules =
[ AppModule::class,
DataModule::class,
// RetrofitModule::class,
// AppVersionModule::class,
AndroidInjectionModule::class,
AndroidSupportInjectionModule::class,
// MappingProvider::class,
ActivityModule::class,
AppActivityModule ::class])
interface AppComponent : AndroidInjector<RoomParkApplication>{
@Component.Builder
interface Builder{
@BindsInstance
fun context(application: Application): Builder
// @BindsInstance
// fun retrofitModule(retrofit: RetrofitModule):Builder
// @BindsInstance
// @Named("retrofit")
// fun retrofit(
// retorfitModule: RetrofitModule):Builder
fun build(): AppComponent
}
// fun cache(): ICachedStore
// fun context(): Context
// fun db(): IDb
// fun api(): IApi
// fun roomApi(): IRoomParkApi
// fun fileModule(): FilesModule
//// fun appLifeCycle(): AppLifecycleListener
// fun networkMonitor(): INetworkMonitor
// fun versionMonitor(): IAppVersionControl
// fun versionNotifier(): IAppVersionNotifier
//
// fun estateRepo() : IEstateRepository
// fun tourRepo() : ITourRepository
// fun userRepo() : IUserRepository
}
\ No newline at end of file
package com.biganto.visual.roompark.di.dagger
import dagger.Module
import dagger.Provides
/**
* Created by Vladislav Bogdashkin on 13.06.2018.
*/
const val USER_CACHE_LIMIT_SIZE = 3
const val USER_CACHE_LIMIT_SECONDS_INACTIVE = 30L
const val TOURS_CACHE_LIMIT_SIZE = 500
const val TOURS_CACHE_LIMIT_SECONDS_INACTIVE = 200L
const val ESTATES_CACHE_LIMIT_SIZE = 100
const val ESTATES_CACHE_LIMIT_SECONDS_INACTIVE = 200L
const val FILES_CACHE_LIMIT_SIZE = 10000
const val FILES_CACHE_LIMIT_SECONDS_INACTIVE = 60L
const val DATABASE_VERSION = 6
@Module
class AppModule() {
}
@Module()
class DataModule() {
/*
@Provides
@Singleton
fun provieApi(@Named("bigantoApi") retorfit:Retrofit): IApi {
return RetrofitRepository(retorfit)
}
@Provides
@Singleton
fun provieRoomParkApi(@Named("roomParkApi") retorfit:Retrofit): IRoomParkApi {
return RoomParkRetrofitRepository(retorfit)
}
@Provides
@Singleton
fun provideDb(context:Application): IDb {
return RequeryRepository(getRequeryDataStore(context))
}
@Provides
@Singleton
fun provideFileModule(context:Application): FilesModule {
return FilesModule(context)
}
@Provides
@Singleton
fun providesNetworkListener(context:Application): INetworkMonitor {
return LiveNetworkMonitor(context)
}
@Provides
@Singleton
fun getRequeryDataStore(context:Application): KotlinReactiveEntityStore<Persistable> {
Timber.d("Kotlin store creating..")
val source = DatabaseSource(context, Models.DEFAULT, "BigantoPerfect", DATABASE_VERSION)
source.setLoggingEnabled(false)
// if ( BuildConfig.DEBUG) {
// // use this in development mode to drop and recreate the tables on every upgrade
// source.setTableCreationMode(TableCreationMode.DROP_CREATE)
// }
val store = KotlinEntityDataStore<Persistable>(source.configuration)
Timber.d("Kotlin store %s",source)
return KotlinReactiveEntityStore(store)
// // override onUpgrade to handle migrating to a new version
// val configuration = source.configuration
// return ReactiveSupport.toReactiveStore(
// EntityDataStore<Persistable>(configuration))
}
*/
}
//
//@Singleton // <-- YES
//class MyServiceImpl @Inject // <-- YES
//constructor(private val apiService: ApiService)// <-- YES
// : MyService
\ No newline at end of file
package com.biganto.visual.roompark.di.dagger
import javax.inject.Scope
/**
* Created by Vladislav Bogdashkin on 14.06.2018.
*/
/**
* Custom Scope for each Screen
*/
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class PerScreen
\ No newline at end of file
package com.biganto.visual.roompark.di.koin
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.domain.contract.AuthContract
import com.biganto.visual.roompark.domain.model.AuthInfoModel
import com.biganto.visual.roompark.view_utils.snackbar.SnackBarProvider
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Observable
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.qualifier.named
import org.koin.dsl.module
/**
* Created by Vladislav Bogdashkin on 03.09.2019.
*/
fun RoomParkApplication.initDI(){
startKoin {
androidLogger()
androidContext(this@initDI)
modules(listOf(
appModule
,scopesModule
))
}
}
val appModule = module{
}
val dataModule = module {
single<AuthContract>{ object :AuthContract{
override fun signIn(email: String, password: String): Observable<AuthInfoModel> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun signOut(): Completable {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}}
}
val scopesModule = module {
scope(named<RoomParkMainActivity>()){
scoped { SnackBarProvider(get()) }
}
}
val presenterScope = module {
scope(named<RoomParkMainActivity>()){ //<- Presenter?
scoped { StartUpData("ja pesik!") }
}
}
data class StartUpData(val helloText:String)
package com.biganto.visual.roompark.domain.use_case
import com.biganto.visual.roompark.di.dagger.PerScreen
import com.biganto.visual.roompark.domain.contract.AuthContract
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
@PerScreen
class AuthUseCase(
val auth: AuthContract by currentScope.get<>
val authContract: AuthContract
){
}
\ No newline at end of file
......@@ -21,4 +21,5 @@ ext {
rxJavaVersion = '3.0.0-RC3'
mosbyMviConductorVersion = '3.1.0'
butterKnifeVersion = '10.2.0'
daggerVersion = '2.24'
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment