Commit 210b239d authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Add app router for open screen chain on launch.

parent 649ebfd4
package ru.terrakok.gitlabclient.model.system.flow
import ru.terrakok.cicerone.Router
import ru.terrakok.cicerone.commands.BackTo
import ru.terrakok.cicerone.commands.Forward
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 27.09.18.
*/
open class AppRouter : Router() {
fun navigateTo(vararg screens: Pair<String, Any?>) {
executeCommands(
*screens
.map { (screenKey, data) -> Forward(screenKey, data) }
.toTypedArray()
)
}
fun newRootScreens(vararg screens: Pair<String, Any?>) {
val commands =
listOf(BackTo(null))
.plus(screens.map { (screenKey, data) -> Forward(screenKey, data) })
executeCommands(*commands.toTypedArray())
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.model.system.flow
import ru.terrakok.cicerone.Router
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 19.12.17.
*/
class FlowRouter(private val appRouter: Router) : Router() {
class FlowRouter(private val appRouter: AppRouter) : AppRouter() {
fun startFlow(screenKey: String, data: Any? = null) {
appRouter.navigateTo(screenKey, data)
......
......@@ -2,30 +2,34 @@ package ru.terrakok.gitlabclient.presentation
import com.arellomobile.mvp.MvpPresenter
import com.arellomobile.mvp.MvpView
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.model.interactor.auth.AuthInteractor
import ru.terrakok.gitlabclient.model.interactor.launch.LaunchInteractor
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import javax.inject.Inject
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 03.09.18.
*/
class AppPresenter @Inject constructor(
private val router: Router,
private val router: AppRouter,
private val authInteractor: AuthInteractor,
private val launchInteractor: LaunchInteractor
) : MvpPresenter<MvpView>() {
fun coldStart() {
if (authInteractor.isSignedIn()) {
router.newRootScreen(Screens.DRAWER_FLOW)
} else {
router.newRootScreen(Screens.AUTH_FLOW)
}
val rootScreen =
if (authInteractor.isSignedIn()) Screens.DRAWER_FLOW
else Screens.AUTH_FLOW
if (launchInteractor.isFirstLaunch) {
router.navigateTo(Screens.PRIVACY_POLICY_FLOW)
router.navigateTo(
Pair(rootScreen, null),
Pair(Screens.PRIVACY_POLICY_FLOW, null)
)
} else {
router.newRootScreen(rootScreen)
}
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ import ru.terrakok.gitlabclient.model.repository.tools.Base64Tools
import ru.terrakok.gitlabclient.model.system.AppSchedulers
import ru.terrakok.gitlabclient.model.system.ResourceManager
import ru.terrakok.gitlabclient.model.system.SchedulersProvider
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.gitlabclient.model.system.message.SystemMessageNotifier
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
import ru.terrakok.gitlabclient.toothpick.qualifier.DefaultPageSize
......@@ -39,8 +40,9 @@ class AppModule(context: Context) : Module() {
bind(SystemMessageNotifier::class.java).toInstance(SystemMessageNotifier())
//Navigation
val cicerone = Cicerone.create()
val cicerone = Cicerone.create(AppRouter())
bind(Router::class.java).toInstance(cicerone.router)
bind(AppRouter::class.java).toInstance(cicerone.router)
bind(NavigatorHolder::class.java).toInstance(cicerone.navigatorHolder)
//Auth
......
......@@ -2,14 +2,14 @@ package ru.terrakok.gitlabclient.toothpick.module
import ru.terrakok.cicerone.Cicerone
import ru.terrakok.cicerone.NavigatorHolder
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import toothpick.config.Module
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 03.09.18.
*/
class FlowNavigationModule(globalRouter: Router) : Module() {
class FlowNavigationModule(globalRouter: AppRouter) : Module() {
init {
val cicerone = Cicerone.create(FlowRouter(globalRouter))
bind(FlowRouter::class.java).toInstance(cicerone.router)
......
......@@ -4,9 +4,9 @@ import android.os.Bundle
import com.arellomobile.mvp.MvpView
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.setLaunchScreen
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.gitlabclient.presentation.auth.AuthFlowPresenter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.toothpick.module.FlowNavigationModule
......@@ -37,7 +37,7 @@ class AuthFlowFragment : FlowFragment(), MvpView {
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.AUTH_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(Router::class.java))
FlowNavigationModule(scope.getInstance(AppRouter::class.java))
)
Toothpick.inject(this, scope)
}
......
......@@ -11,12 +11,12 @@ import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.drawer_flow_fragment.*
import ru.terrakok.cicerone.Navigator
import ru.terrakok.cicerone.NavigatorHolder
import ru.terrakok.cicerone.Router
import ru.terrakok.cicerone.android.SupportFragmentNavigator
import ru.terrakok.cicerone.commands.Command
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.setLaunchScreen
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.gitlabclient.presentation.drawer.NavigationDrawerView
import ru.terrakok.gitlabclient.presentation.global.GlobalMenuController
import ru.terrakok.gitlabclient.presentation.launch.DrawerFlowPresenter
......@@ -103,7 +103,7 @@ class DrawerFlowFragment : BaseFragment(), MvpView {
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.DRAWER_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(Router::class.java)),
FlowNavigationModule(scope.getInstance(AppRouter::class.java)),
GlobalMenuModule()
)
Toothpick.inject(this@DrawerFlowFragment, scope)
......
......@@ -4,10 +4,10 @@ import android.os.Bundle
import com.arellomobile.mvp.MvpView
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.extension.setLaunchScreen
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.gitlabclient.presentation.issue.IssueFlowPresenter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
......@@ -45,7 +45,7 @@ class IssueFlowFragment : FlowFragment(), MvpView {
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.ISSUE_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(Router::class.java)),
FlowNavigationModule(scope.getInstance(AppRouter::class.java)),
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
......
......@@ -4,10 +4,10 @@ import android.os.Bundle
import com.arellomobile.mvp.MvpView
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.extension.setLaunchScreen
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.gitlabclient.presentation.mergerequest.MergeRequestFlowPresenter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
......@@ -45,7 +45,7 @@ class MergeRequestFlowFragment : FlowFragment(), MvpView {
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.MERGE_REQUEST_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(Router::class.java)),
FlowNavigationModule(scope.getInstance(AppRouter::class.java)),
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
......
......@@ -4,10 +4,10 @@ import android.os.Bundle
import com.arellomobile.mvp.MvpView
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.extension.setLaunchScreen
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.gitlabclient.presentation.project.ProjectFlowPresenter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
......@@ -43,7 +43,7 @@ class ProjectFlowFragment : FlowFragment(), MvpView {
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.PROJECT_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(Router::class.java)),
FlowNavigationModule(scope.getInstance(AppRouter::class.java)),
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
......
......@@ -4,10 +4,10 @@ import android.os.Bundle
import com.arellomobile.mvp.MvpView
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.extension.setLaunchScreen
import ru.terrakok.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.gitlabclient.presentation.user.UserFlowPresenter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
......@@ -43,7 +43,7 @@ class UserFlowFragment : FlowFragment(), MvpView {
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.USER_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(Router::class.java)),
FlowNavigationModule(scope.getInstance(AppRouter::class.java)),
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
......
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