Commit 7129b223 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

controller component injection in a new way

parent 8cee5e74
...@@ -31,6 +31,10 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon ...@@ -31,6 +31,10 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon
constructor(args: Bundle):super(args) constructor(args: Bundle):super(args)
val inject by lazy { injectDependencies() }
protected abstract fun injectDependencies()
protected val detachDisposable = CompositeDisposable() protected val detachDisposable = CompositeDisposable()
abstract override fun createPresenter(): P abstract override fun createPresenter(): P
...@@ -59,20 +63,20 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon ...@@ -59,20 +63,20 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon
// } // }
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View { override fun onContextAvailable(context: Context) {
super.onContextAvailable(context)
inject
}
// if (isInjected.not()) { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
// ConductorInjection.inject(this)
// isInjected = true
// }
val view = inflater.inflate(getLayoutId(), container, false) val view = inflater.inflate(getLayoutId(), container, false)
// instantiate the view // instantiate the view
ButterKnife.bind(this, view) ButterKnife.bind(this, view)
Timber.d(" ACTIVITY IS : ${activity?.localClassName} / ${activity?.localClassName}")
(activity as RoomParkMainActivity).let{ (activity as RoomParkMainActivity).let{
snackbar = ActivityModule.provideSnackBar(it) snackbar = ActivityModule.provideSnackBar(it)
toolBar = it toolBar = it
snackbar.bindRootView(toolBar.coordinatorLayout)
} }
return view return view
} }
......
...@@ -4,6 +4,7 @@ import android.app.Activity ...@@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context import android.content.Context
import android.content.res.Resources import android.content.res.Resources
import com.biganto.visual.roompark.base.BaseRoomParkActivity import com.biganto.visual.roompark.base.BaseRoomParkActivity
import com.biganto.visual.roompark.base.ICollapsingToolBar
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.view_utils.snackbar.ISnackBarProvider import com.biganto.visual.roompark.view_utils.snackbar.ISnackBarProvider
import com.biganto.visual.roompark.view_utils.snackbar.SnackBarProvider import com.biganto.visual.roompark.view_utils.snackbar.SnackBarProvider
...@@ -43,14 +44,17 @@ abstract class AppActivityModule { ...@@ -43,14 +44,17 @@ abstract class AppActivityModule {
@Module @Module
internal interface MainActivityModule { internal interface MainActivityModule {
@Binds @Binds
fun bindMainActivity(activity: RoomParkMainActivity): Activity fun bindMainActivity(activity: RoomParkMainActivity): BaseRoomParkActivity
}
@Binds
fun bindMainActivityToolbar(activity: RoomParkMainActivity): ICollapsingToolBar
}
@Module @Module
internal interface BaseActivityModule { internal interface BaseActivityModule {
@Binds @Binds
fun bindBaseActivity(activity: BaseRoomParkActivity): Activity fun bindBaseActivity(activity: BaseRoomParkActivity): BaseRoomParkActivity
} }
......
...@@ -5,10 +5,12 @@ import android.view.LayoutInflater ...@@ -5,10 +5,12 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.ICollapsingToolBar
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import javax.inject.Inject
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -20,26 +22,57 @@ class SplashScreenController : ...@@ -20,26 +22,57 @@ class SplashScreenController :
, SplashScreenPresenter>() , SplashScreenPresenter>()
, SplashScreen { , SplashScreen {
override fun injectDependencies() {
getComponent()
}
@Inject
lateinit var tb: ICollapsingToolBar
// @Inject
// lateinit var snacky:ISnackBarProvider
lateinit var rpActivity: RoomParkMainActivity lateinit var rpActivity: RoomParkMainActivity
fun getComponent() = DaggerSplashScreenComponent fun getComponent() = DaggerSplashScreenComponent
.factory() .factory()
.create(RoomParkApplication.component,this) .create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this)
// @Inject
// lateinit var ac: RoomParkMainActivity
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val v = super.onCreateView(inflater, container) val v = super.onCreateView(inflater, container)
rpActivity = activity as RoomParkMainActivity
snackbar.showSnackBar("AZZZA", Snackbar.LENGTH_LONG) snackbar.showSnackBar("AZZZA", Snackbar.LENGTH_LONG)
return v return v
} }
override fun render(viewState: SplashScreenViewState) { override fun render(viewState: SplashScreenViewState) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. when(viewState){
is SplashScreenViewState.Idle -> render(viewState)
is SplashScreenViewState.ToScreen -> render(viewState)
}
} }
override fun createPresenter(): SplashScreenPresenter = getComponent().presenter private fun render(viewState: SplashScreenViewState.Idle){
}
private fun render(viewState: SplashScreenViewState.ToScreen){
snackbar.showSnackBar(viewState.message, Snackbar.LENGTH_LONG)
tb.appBar.setBackgroundColor(resources?.getColor(R.color.colorAccentSecondary)?:R.color.colorAccent)
// snacky.showSnackBar("lul")
}
@Inject
lateinit var _p : SplashScreenPresenter
override fun createPresenter(): SplashScreenPresenter = _p
override fun getLayoutId(): Int = R.layout.splash_screen override fun getLayoutId(): Int = R.layout.splash_screen
......
import android.content.Context
import com.biganto.visual.roompark.base.ICollapsingToolBar
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.di.dagger.ActivityModule
import com.biganto.visual.roompark.di.dagger.AppActivityModule
import com.biganto.visual.roompark.di.dagger.AppComponent import com.biganto.visual.roompark.di.dagger.AppComponent
import com.biganto.visual.roompark.di.dagger.PerScreen import com.biganto.visual.roompark.di.dagger.PerScreen
import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenController import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenController
import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenPresenter import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenPresenter
import dagger.Binds
import dagger.BindsInstance import dagger.BindsInstance
import dagger.Component import dagger.Component
import dagger.Module
//package com.biganto.visual.roompark.presentation.screen.splash //package com.biganto.visual.roompark.presentation.screen.splash
// //
...@@ -26,8 +33,11 @@ import dagger.Component ...@@ -26,8 +33,11 @@ import dagger.Component
// //
//
@PerScreen @PerScreen
@Component( dependencies = [AppComponent::class]) @Component(
modules = [RoomParkActivityModule::class,ActivityModule::class, AppActivityModule::class ],
dependencies = [AppComponent::class])
interface SplashScreenComponent { interface SplashScreenComponent {
...@@ -36,25 +46,46 @@ interface SplashScreenComponent { ...@@ -36,25 +46,46 @@ interface SplashScreenComponent {
@Component.Factory @Component.Factory
interface Factory{ interface Factory{
fun create( fun create(
appComponent: AppComponent, appComponent: AppComponent
@BindsInstance splashView:SplashScreenController ,@BindsInstance activity: RoomParkMainActivity
):SplashScreenComponent ):SplashScreenComponent
} }
val presenter: SplashScreenPresenter val presenter: SplashScreenPresenter
fun inject(controller: SplashScreenController)
// val roomParkActivity: RoomParkMainActivity // val roomParkActivity: RoomParkMainActivity
// val snackBar : ISnackBarProvider // val snackBar : ISnackBarProvider
}
@Module
abstract class RoomParkActivityModule{
@PerScreen
@Binds
abstract fun provideContext(activity: RoomParkMainActivity): Context
}
//
//@Module
//abstract class SplashScreenModule{
//
//
// @PerScreen
// @Binds // @Binds
// abstract fun presenter(presenter:SplashScreenPresenter):SplashScreenPresenter // abstract fun provideContext(activity: Activity): Context
//
//// fun snack(activity:RoomParkMainActivity) : ISnackBarProvider
//} // @Binds
\ No newline at end of file // abstract fun provideSnack(snack:ISnackBarProvider) : ISnackBarProvider
@PerScreen
@Binds
abstract fun provideToolbar(activitiy: RoomParkMainActivity): ICollapsingToolBar
// @ContributesAndroidInjector(
// modules = [ActivityModule::class, AppActivityModule.MainActivityModule::class])
// abstract fun contributeMainActivityInjector(): RoomParkMainActivity
// @Binds
// abstract fun provideSnack(activitiy: RoomParkMainActivity):ISnackBarProvider
}
package com.biganto.visual.roompark.presentation.screen.splash package com.biganto.visual.roompark.presentation.screen.splash
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBasePresenter import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import io.reactivex.Observable
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -8,12 +10,18 @@ import javax.inject.Inject ...@@ -8,12 +10,18 @@ import javax.inject.Inject
*/ */
class SplashScreenPresenter @Inject constructor() class SplashScreenPresenter @Inject constructor(
var acitivityContext: RoomParkMainActivity
// ,var context:Context
)
: BigantoBasePresenter<SplashScreen, SplashScreenViewState>() { : BigantoBasePresenter<SplashScreen, SplashScreenViewState>() {
override fun bindIntents() { override fun bindIntents() {
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(Observable.just(SplashScreenViewState.ToScreen(acitivityContext.javaClass.toString())))
subscribeViewState(state.cast(SplashScreenViewState::class.java), SplashScreen::render) subscribeViewState(state.cast(SplashScreenViewState::class.java), SplashScreen::render)
} }
......
...@@ -9,4 +9,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState ...@@ -9,4 +9,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class SplashScreenViewState : BigantoBaseViewState() { sealed class SplashScreenViewState : BigantoBaseViewState() {
class Idle : SplashScreenViewState() class Idle : SplashScreenViewState()
class ToScreen(val message:String) : SplashScreenViewState()
} }
\ 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