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
constructor(args: Bundle):super(args)
val inject by lazy { injectDependencies() }
protected abstract fun injectDependencies()
protected val detachDisposable = CompositeDisposable()
abstract override fun createPresenter(): P
......@@ -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()) {
// ConductorInjection.inject(this)
// isInjected = true
// }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val view = inflater.inflate(getLayoutId(), container, false)
// instantiate the view
ButterKnife.bind(this, view)
Timber.d(" ACTIVITY IS : ${activity?.localClassName} / ${activity?.localClassName}")
(activity as RoomParkMainActivity).let{
snackbar = ActivityModule.provideSnackBar(it)
toolBar = it
snackbar.bindRootView(toolBar.coordinatorLayout)
}
return view
}
......
......@@ -4,6 +4,7 @@ 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.ICollapsingToolBar
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
......@@ -43,14 +44,17 @@ abstract class AppActivityModule {
@Module
internal interface MainActivityModule {
@Binds
fun bindMainActivity(activity: RoomParkMainActivity): Activity
}
fun bindMainActivity(activity: RoomParkMainActivity): BaseRoomParkActivity
@Binds
fun bindMainActivityToolbar(activity: RoomParkMainActivity): ICollapsingToolBar
}
@Module
internal interface BaseActivityModule {
@Binds
fun bindBaseActivity(activity: BaseRoomParkActivity): Activity
fun bindBaseActivity(activity: BaseRoomParkActivity): BaseRoomParkActivity
}
......
......@@ -5,10 +5,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
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.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.google.android.material.snackbar.Snackbar
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -20,26 +22,57 @@ class SplashScreenController :
, SplashScreenPresenter>()
, SplashScreen {
override fun injectDependencies() {
getComponent()
}
@Inject
lateinit var tb: ICollapsingToolBar
// @Inject
// lateinit var snacky:ISnackBarProvider
lateinit var rpActivity: RoomParkMainActivity
fun getComponent() = DaggerSplashScreenComponent
.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 {
val v = super.onCreateView(inflater, container)
rpActivity = activity as RoomParkMainActivity
snackbar.showSnackBar("AZZZA", Snackbar.LENGTH_LONG)
return v
}
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
......
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.PerScreen
import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenController
import com.biganto.visual.roompark.presentation.screen.splash.SplashScreenPresenter
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
import dagger.Module
//package com.biganto.visual.roompark.presentation.screen.splash
//
......@@ -26,8 +33,11 @@ import dagger.Component
//
//
@PerScreen
@Component( dependencies = [AppComponent::class])
@Component(
modules = [RoomParkActivityModule::class,ActivityModule::class, AppActivityModule::class ],
dependencies = [AppComponent::class])
interface SplashScreenComponent {
......@@ -36,25 +46,46 @@ interface SplashScreenComponent {
@Component.Factory
interface Factory{
fun create(
appComponent: AppComponent,
@BindsInstance splashView:SplashScreenController
appComponent: AppComponent
,@BindsInstance activity: RoomParkMainActivity
):SplashScreenComponent
}
val presenter: SplashScreenPresenter
fun inject(controller: SplashScreenController)
// val roomParkActivity: RoomParkMainActivity
// val snackBar : ISnackBarProvider
}
@Module
abstract class RoomParkActivityModule{
@PerScreen
@Binds
abstract fun provideContext(activity: RoomParkMainActivity): Context
}
//
//@Module
//abstract class SplashScreenModule{
//
//
// @PerScreen
// @Binds
// abstract fun presenter(presenter:SplashScreenPresenter):SplashScreenPresenter
//
//// fun snack(activity:RoomParkMainActivity) : ISnackBarProvider
//}
\ No newline at end of file
// abstract fun provideContext(activity: Activity): Context
// @Binds
// 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
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import io.reactivex.Observable
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>() {
override fun bindIntents() {
val state = restoreStateObservable
.mergeWith(Observable.just(SplashScreenViewState.ToScreen(acitivityContext.javaClass.toString())))
subscribeViewState(state.cast(SplashScreenViewState::class.java), SplashScreen::render)
}
......
......@@ -9,4 +9,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class SplashScreenViewState : BigantoBaseViewState() {
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