Commit 2c4f431a authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Merge branch 'feature/migrate_cicerone' into develop

parents d0dbab57 c342a509
......@@ -7,7 +7,7 @@ apply from: '../ci.gradle'
android {
compileSdkVersion 28
buildToolsVersion '28.0.2'
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.gitlab.terrakok.gitfox"
......@@ -90,7 +90,7 @@ dependencies {
kapt "com.arello-mobile:moxy-compiler:$moxyVersion"
implementation "com.arello-mobile:moxy-app-compat:$moxyVersion"
//Cicerone Navigation
implementation "ru.terrakok.cicerone:cicerone:3.0.0"
implementation "ru.terrakok.cicerone:cicerone:4.0.2"
//DI
implementation "com.github.stephanenicolas.toothpick:toothpick-runtime:$toothpickVersion"
kapt "com.github.stephanenicolas.toothpick:toothpick-compiler:$toothpickVersion"
......
......@@ -19,6 +19,7 @@ import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import ru.terrakok.cicerone.Navigator
import ru.terrakok.cicerone.android.support.SupportAppScreen
import ru.terrakok.cicerone.commands.BackTo
import ru.terrakok.cicerone.commands.Replace
import ru.terrakok.gitlabclient.R
......@@ -31,11 +32,11 @@ import timber.log.Timber
/**
* @author Konstantin Tskhovrebov (aka terrakok). Date: 03.03.17
*/
fun Navigator.setLaunchScreen(screenKey: String, data: Any? = null) {
fun Navigator.setLaunchScreen(screen: SupportAppScreen) {
applyCommands(
arrayOf(
BackTo(null),
Replace(screenKey, data)
Replace(screen)
)
)
}
......@@ -138,32 +139,26 @@ fun ImageView.loadRoundedImage(
fun TargetHeader.Public.openInfo(router: FlowRouter) {
when (target) {
AppTarget.PROJECT -> {
router.startFlow(Screens.PROJECT_FLOW, targetId)
router.startFlow(Screens.ProjectFlow(targetId))
}
AppTarget.USER -> {
router.startFlow(Screens.USER_FLOW, targetId)
router.startFlow(Screens.UserFlow(targetId))
}
AppTarget.MERGE_REQUEST -> {
internal?.let { targetInternal ->
router.startFlow(
Screens.MR_FLOW,
Pair(targetInternal.projectId, targetInternal.targetIid)
)
router.startFlow(Screens.MergeRequestFlow(targetInternal.projectId, targetInternal.targetIid))
}
}
AppTarget.ISSUE -> {
internal?.let { targetInternal ->
router.startFlow(
Screens.ISSUE_FLOW,
Pair(targetInternal.projectId, targetInternal.targetIid)
)
router.startFlow(Screens.IssueFlow(targetInternal.projectId, targetInternal.targetIid))
}
}
else -> {
internal?.let { targetInternal ->
Timber.i("Temporary open project flow")
//todo
router.startFlow(Screens.PROJECT_FLOW, targetInternal.projectId)
router.startFlow(Screens.ProjectFlow(targetInternal.projectId))
}
}
}
......@@ -176,4 +171,6 @@ fun Fragment.showSnackMessage(message: String) {
messageTextView.setTextColor(Color.WHITE)
snackbar.show()
}
}
\ No newline at end of file
}
fun Any.objectScopeName() = "${javaClass.simpleName}_${hashCode()}"
\ No newline at end of file
package ru.terrakok.gitlabclient.model.system.flow
import ru.terrakok.cicerone.Router
import ru.terrakok.cicerone.commands.BackTo
import ru.terrakok.cicerone.commands.Forward
import ru.terrakok.cicerone.commands.Replace
/**
* 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.mapIndexed { index, (screenKey, data) ->
if (index == 0) Replace(screenKey, data)
else Forward(screenKey, data)
})
executeCommands(*commands.toTypedArray())
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.model.system.flow
import ru.terrakok.cicerone.Router
import ru.terrakok.cicerone.android.support.SupportAppScreen
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 19.12.17.
*/
class FlowRouter(private val appRouter: AppRouter) : AppRouter() {
class FlowRouter(private val appRouter: Router) : Router() {
fun startFlow(screenKey: String, data: Any? = null) {
appRouter.navigateTo(screenKey, data)
fun startFlow(screen: SupportAppScreen) {
appRouter.navigateTo(screen)
}
fun newRootFlow(screenKey: String, data: Any? = null) {
appRouter.newRootScreen(screenKey, data)
fun newRootFlow(screen: SupportAppScreen) {
appRouter.newRootScreen(screen)
}
fun finishFlow() {
......
......@@ -2,31 +2,28 @@ 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: AppRouter,
private val router: Router,
private val authInteractor: AuthInteractor,
private val launchInteractor: LaunchInteractor
) : MvpPresenter<MvpView>() {
fun coldStart() {
val rootScreen =
if (authInteractor.isSignedIn()) Screens.DRAWER_FLOW
else Screens.AUTH_FLOW
if (authInteractor.isSignedIn()) Screens.DrawerFlow
else Screens.AuthFlow
if (launchInteractor.isFirstLaunch) {
router.newRootScreens(
Pair(rootScreen, null),
Pair(Screens.PRIVACY_POLICY_FLOW, null)
)
router.newRootChain(rootScreen, Screens.PrivacyPolicy)
} else {
router.newRootScreen(rootScreen)
}
......
......@@ -38,11 +38,11 @@ class AboutPresenter @Inject constructor(
.connect()
}
fun onShowLibrariesClicked() = router.startFlow(Screens.APP_LIBRARIES_FLOW)
fun onShowLibrariesClicked() = router.startFlow(Screens.Libraries)
fun onPrivacyPolicyClicked() = router.startFlow(Screens.PRIVACY_POLICY_FLOW)
fun onPrivacyPolicyClicked() = router.startFlow(Screens.PrivacyPolicy)
fun onDeveloperClicked(id: Long) = router.startFlow(Screens.USER_FLOW, id)
fun onDeveloperClicked(id: Long) = router.startFlow(Screens.UserFlow(id))
fun onMenuPressed() = menuController.open()
fun onBackPressed() = router.exit()
......
......@@ -33,7 +33,7 @@ class AuthPresenter @Inject constructor(
.doOnSubscribe { viewState.showProgress(true) }
.doAfterTerminate { viewState.showProgress(false) }
.subscribe(
{ router.newRootFlow(Screens.DRAWER_FLOW) },
{ router.newRootFlow(Screens.DrawerFlow) },
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
).connect()
}
......@@ -55,7 +55,7 @@ class AuthPresenter @Inject constructor(
fun loginOnCustomServer(url: String, token: String) {
authInteractor.login(url, token)
.subscribe(
{ router.newRootFlow(Screens.DRAWER_FLOW) },
{ router.newRootFlow(Screens.DrawerFlow) },
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
).connect()
}
......
......@@ -47,9 +47,9 @@ class NavigationDrawerPresenter @Inject constructor(
menuController.close()
if (item != currentSelectedItem) {
when (item) {
ACTIVITY -> router.newRootScreen(Screens.MAIN_FLOW)
PROJECTS -> router.newRootScreen(Screens.PROJECTS_CONTAINER_SCREEN)
ABOUT -> router.newRootScreen(Screens.ABOUT_SCREEN)
ACTIVITY -> router.newRootScreen(Screens.MainFlow)
PROJECTS -> router.newRootScreen(Screens.ProjectsContainer)
ABOUT -> router.newRootScreen(Screens.About)
}
}
}
......@@ -57,11 +57,11 @@ class NavigationDrawerPresenter @Inject constructor(
fun onLogoutClick() {
menuController.close()
authInteractor.logout()
router.newRootFlow(Screens.AUTH_FLOW)
router.newRootFlow(Screens.AuthFlow)
}
fun onUserClick(id: Long) {
menuController.close()
router.startFlow(Screens.USER_FLOW, id)
router.startFlow(Screens.UserFlow(id))
}
}
\ No newline at end of file
......@@ -50,6 +50,6 @@ class ErrorHandler @Inject constructor(
private fun logout() {
authInteractor.logout()
router.newRootScreen(Screens.AUTH_FLOW)
router.newRootScreen(Screens.AuthFlow)
}
}
......@@ -81,7 +81,7 @@ class MyEventsPresenter @Inject constructor(
fun onMenuClick() = menuController.open()
fun onItemClick(item: TargetHeader.Public) = item.openInfo(router)
fun onUserClick(userId: Long) = router.startFlow(Screens.USER_FLOW, userId)
fun onUserClick(userId: Long) = router.startFlow(Screens.UserFlow(userId))
fun refreshEvents() = paginator.refresh()
fun loadNextEventsPage() = paginator.loadNewPage()
fun onBackPressed() = router.exit()
......
......@@ -93,7 +93,7 @@ class MyIssuesPresenter @Inject constructor(
}
fun onIssueClick(item: TargetHeader.Public) = item.openInfo(router)
fun onUserClick(userId: Long) = router.startFlow(Screens.USER_FLOW, userId)
fun onUserClick(userId: Long) = router.startFlow(Screens.UserFlow(userId))
fun refreshIssues() = paginator.refresh()
fun loadNextIssuesPage() = paginator.loadNewPage()
......
......@@ -90,7 +90,7 @@ class MyMergeRequestsPresenter @Inject constructor(
}
fun onMergeRequestClick(item: TargetHeader.Public) = item.openInfo(router)
fun onUserClick(userId: Long) = router.startFlow(Screens.USER_FLOW, userId)
fun onUserClick(userId: Long) = router.startFlow(Screens.UserFlow(userId))
fun refreshMergeRequests() = paginator.refresh()
fun loadNextMergeRequestsPage() = paginator.loadNewPage()
......
......@@ -87,7 +87,7 @@ class MyTodosPresenter @Inject constructor(
)
fun onTodoClick(item: TargetHeader.Public) = item.openInfo(router)
fun onUserClick(userId: Long) = router.startFlow(Screens.USER_FLOW, userId)
fun onUserClick(userId: Long) = router.startFlow(Screens.UserFlow(userId))
fun refreshTodos() = paginator.refresh()
fun loadNextTodosPage() = paginator.loadNewPage()
......
......@@ -87,7 +87,7 @@ class ProjectEventsPresenter @Inject constructor(
)
fun onItemClick(item: TargetHeader.Public) = item.openInfo(router)
fun onUserClick(userId: Long) = router.startFlow(Screens.USER_FLOW, userId)
fun onUserClick(userId: Long) = router.startFlow(Screens.UserFlow(userId))
fun refreshEvents() = paginator.refresh()
fun loadNextEventsPage() = paginator.loadNewPage()
fun onBackPressed() = router.exit()
......
......@@ -89,7 +89,7 @@ class ProjectIssuesPresenter @Inject constructor(
)
fun onIssueClick(item: TargetHeader.Public) = item.openInfo(router)
fun onUserClick(userId: Long) = router.startFlow(Screens.USER_FLOW, userId)
fun onUserClick(userId: Long) = router.startFlow(Screens.UserFlow(userId))
fun refreshIssues() = paginator.refresh()
fun loadNextIssuesPage() = paginator.loadNewPage()
......
......@@ -89,7 +89,7 @@ class ProjectMergeRequestsPresenter @Inject constructor(
)
fun onMergeRequestClick(item: TargetHeader.Public) = item.openInfo(router)
fun onUserClick(userId: Long) = router.startFlow(Screens.USER_FLOW, userId)
fun onUserClick(userId: Long) = router.startFlow(Screens.UserFlow(userId))
fun refreshMergeRequests() = paginator.refresh()
fun loadNextMergeRequestsPage() = paginator.loadNewPage()
......
......@@ -89,6 +89,6 @@ class ProjectsListPresenter @Inject constructor(
fun refreshProjects() = paginator.refresh()
fun loadNextProjectsPage() = paginator.loadNewPage()
fun onProjectClicked(id: Long) = router.startFlow(Screens.PROJECT_FLOW, id)
fun onProjectClicked(id: Long) = router.startFlow(Screens.ProjectFlow(id))
fun onBackPressed() = router.exit()
}
\ No newline at end of file
......@@ -16,7 +16,6 @@ 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
......@@ -40,9 +39,8 @@ class AppModule(context: Context) : Module() {
bind(SystemMessageNotifier::class.java).toInstance(SystemMessageNotifier())
//Navigation
val cicerone = Cicerone.create(AppRouter())
val cicerone = Cicerone.create()
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.gitlabclient.model.system.flow.AppRouter
import ru.terrakok.cicerone.Router
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: AppRouter) : Module() {
class FlowNavigationModule(globalRouter: Router) : Module() {
init {
val cicerone = Cicerone.create(FlowRouter(globalRouter))
bind(FlowRouter::class.java).toInstance(cicerone.router)
......
package ru.terrakok.gitlabclient.ui
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentTransaction
......@@ -13,10 +11,9 @@ import com.arellomobile.mvp.presenter.ProvidePresenter
import io.reactivex.disposables.Disposable
import ru.terrakok.cicerone.Navigator
import ru.terrakok.cicerone.NavigatorHolder
import ru.terrakok.cicerone.android.SupportAppNavigator
import ru.terrakok.cicerone.android.support.SupportAppNavigator
import ru.terrakok.cicerone.commands.Command
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.model.system.message.SystemMessageNotifier
import ru.terrakok.gitlabclient.model.system.message.SystemMessageType
import ru.terrakok.gitlabclient.presentation.AppPresenter
......@@ -52,20 +49,7 @@ class AppActivity : MvpAppCompatActivity(), MvpView {
private val navigator: Navigator =
object : SupportAppNavigator(this, supportFragmentManager, R.id.container) {
override fun createActivityIntent(
context: Context,
screenKey: String,
data: Any?
): Intent? = Screens.createIntent(screenKey, data)
override fun exit() {
finish()
}
override fun createFragment(screenKey: String, data: Any?) =
Screens.createFragment(screenKey, data)
override fun setupFragmentTransactionAnimation(
override fun setupFragmentTransaction(
command: Command?,
currentFragment: Fragment?,
nextFragment: Fragment?,
......
......@@ -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
......@@ -30,14 +30,14 @@ class AuthFlowFragment : FlowFragment(), MvpView {
initScope()
super.onCreate(savedInstanceState)
if (childFragmentManager.fragments.isEmpty()) {
navigator.setLaunchScreen(Screens.AUTH_SCREEN, null)
navigator.setLaunchScreen(Screens.Auth)
}
}
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.AUTH_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(AppRouter::class.java))
FlowNavigationModule(scope.getInstance(Router::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.android.SupportFragmentNavigator
import ru.terrakok.cicerone.Router
import ru.terrakok.cicerone.android.support.SupportAppNavigator
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
......@@ -58,23 +58,18 @@ class DrawerFlowFragment : BaseFragment(), MvpView {
}
private val navigator: Navigator by lazy {
object : SupportFragmentNavigator(childFragmentManager, R.id.mainContainer) {
object : SupportAppNavigator(this.activity, childFragmentManager, R.id.mainContainer) {
override fun applyCommands(commands: Array<out Command>?) {
super.applyCommands(commands)
updateNavDrawer()
}
override fun exit() {
override fun activityBack() {
presenter.onExit()
}
override fun createFragment(screenKey: String, data: Any?): Fragment? =
Screens.createFragment(screenKey, data)
override fun showSystemMessage(message: String?) {}
override fun setupFragmentTransactionAnimation(
override fun setupFragmentTransaction(
command: Command?,
currentFragment: Fragment?,
nextFragment: Fragment?,
......@@ -96,14 +91,14 @@ class DrawerFlowFragment : BaseFragment(), MvpView {
.replace(R.id.navDrawerContainer, NavigationDrawerFragment())
.commitNow()
navigator.setLaunchScreen(Screens.MAIN_FLOW)
navigator.setLaunchScreen(Screens.MainFlow)
}
}
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.DRAWER_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(AppRouter::class.java)),
FlowNavigationModule(scope.getInstance(Router::class.java)),
GlobalMenuModule()
)
Toothpick.inject(this@DrawerFlowFragment, scope)
......
......@@ -4,10 +4,9 @@ import android.support.v4.app.Fragment
import android.support.v4.app.FragmentTransaction
import ru.terrakok.cicerone.Navigator
import ru.terrakok.cicerone.NavigatorHolder
import ru.terrakok.cicerone.android.SupportFragmentNavigator
import ru.terrakok.cicerone.android.support.SupportAppNavigator
import ru.terrakok.cicerone.commands.Command
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import javax.inject.Inject
/**
......@@ -23,17 +22,12 @@ abstract class FlowFragment : BaseFragment() {
lateinit var navigatorHolder: NavigatorHolder
protected val navigator: Navigator by lazy {
object : SupportFragmentNavigator(childFragmentManager, R.id.container) {
override fun exit() {
object : SupportAppNavigator(this.activity, childFragmentManager, R.id.container) {
override fun activityBack() {
onExit()
}
override fun createFragment(screenKey: String, data: Any?): Fragment? =
Screens.createFragment(screenKey, data)
override fun showSystemMessage(message: String?) {}
override fun setupFragmentTransactionAnimation(
override fun setupFragmentTransaction(
command: Command?,
currentFragment: Fragment?,
nextFragment: Fragment?,
......
......@@ -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
......@@ -38,14 +38,14 @@ class IssueFlowFragment : FlowFragment(), MvpView {
initScope()
super.onCreate(savedInstanceState)
if (childFragmentManager.fragments.isEmpty()) {
navigator.setLaunchScreen(Screens.ISSUE_SCREEN, null)
navigator.setLaunchScreen(Screens.Issue)
}
}
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.ISSUE_FLOW_SCOPE)
scope.installModules(
FlowNavigationModule(scope.getInstance(AppRouter::class.java)),
FlowNavigationModule(scope.getInstance(Router::class.java)),
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
......
......@@ -46,8 +46,8 @@ class IssueFragment : BaseFragment(), IssueInfoFragment.IssueInfoToolbar {
private inner class IssuePagesAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int): BaseFragment? = when (position) {
0 -> Screens.createFragment(Screens.ISSUE_INFO_SCREEN)
1 -> Screens.createFragment(Screens.ISSUE_NOTES_SCREEN)
0 -> Screens.IssueInfo.fragment
1 -> Screens.IssueNotes.fragment
else -> null
}
......
......@@ -3,6 +3,7 @@ package ru.terrakok.gitlabclient.ui.main
import android.os.Bundle
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter
import kotlinx.android.synthetic.main.fragment_main.*
import ru.terrakok.cicerone.android.support.SupportAppScreen
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.color
......@@ -30,27 +31,35 @@ class MainFlowFragment : BaseFragment() {
setOnTabSelectedListener { position, wasSelected ->
if (!wasSelected) selectTab(
when (position) {
0 -> Screens.MY_EVENTS_SCREEN
1 -> Screens.MY_ISSUES_CONTAINER_SCREEN
2 -> Screens.MY_MR_CONTAINER_SCREEN
else -> Screens.MY_TODOS_CONTAINER_SCREEN
0 -> eventsTab
1 -> issuesTab
2 -> mrsTab
else -> todosTab
}
)
true
}
}
selectTab(currentTabFragment?.tag ?: Screens.MY_EVENTS_SCREEN)
selectTab(
when (currentTabFragment?.tag) {
eventsTab.screenKey -> eventsTab
issuesTab.screenKey -> eventsTab
mrsTab.screenKey -> eventsTab
todosTab.screenKey -> eventsTab
else -> eventsTab
}
)
}
private fun selectTab(tab: String) {
private fun selectTab(tab: SupportAppScreen) {
val currentFragment = currentTabFragment
val newFragment = childFragmentManager.findFragmentByTag(tab)
val newFragment = childFragmentManager.findFragmentByTag(tab.screenKey)
if (currentFragment != null && newFragment != null && currentFragment == newFragment) return
childFragmentManager.beginTransaction().apply {
if (newFragment == null) add(R.id.mainScreenContainer, createTabFragment(tab), tab)
if (newFragment == null) add(R.id.mainScreenContainer, createTabFragment(tab), tab.screenKey)
currentFragment?.let {
hide(it)
......@@ -63,10 +72,16 @@ class MainFlowFragment : BaseFragment() {
}.commitNow()
}
private fun createTabFragment(tab: String) =
Screens.createFragment(tab) ?: throw RuntimeException("Unknown tab $tab")
private fun createTabFragment(tab: SupportAppScreen) = tab.fragment
override fun onBackPressed() {
currentTabFragment?.onBackPressed()
}
companion object {
private val eventsTab = Screens.MyEvents
private val issuesTab = Screens.MyIssuesContainer
private val mrsTab = Screens.MyMrContainer
private val todosTab = Screens.MyTodosContainer
}
}
\ No newline at end of file
......@@ -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
......@@ -38,14 +38,14 @@ class MergeRequestFlowFragment : FlowFragment(), MvpView {
initScope()
super.onCreate(savedInstanceState)
if (childFragmentManager.fragments.isEmpty()) {
navigator.setLaunchScreen(Screens.MR_SCREEN, null)
navigator.setLaunchScreen(Screens.MergeRequest)
}