Commit 8ca6bb27 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Move all fragment creation to Screens class. Optimize bottom bar tabs.

parent 8c86be74
......@@ -2,20 +2,33 @@ package ru.terrakok.gitlabclient
import android.content.Intent
import android.net.Uri
import android.support.v4.app.Fragment
import ru.terrakok.gitlabclient.ui.about.AboutFragment
import ru.terrakok.gitlabclient.ui.auth.AuthFlowFragment
import ru.terrakok.gitlabclient.ui.auth.AuthFragment
import ru.terrakok.gitlabclient.ui.drawer.DrawerFlowFragment
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.issue.IssueFlowFragment
import ru.terrakok.gitlabclient.ui.issue.IssueFragment
import ru.terrakok.gitlabclient.ui.launch.DrawerFlowFragment
import ru.terrakok.gitlabclient.ui.issue.IssueInfoFragment
import ru.terrakok.gitlabclient.ui.issue.IssueNotesFragment
import ru.terrakok.gitlabclient.ui.libraries.LibrariesFragment
import ru.terrakok.gitlabclient.ui.main.MainFragment
import ru.terrakok.gitlabclient.ui.main.MainFlowFragment
import ru.terrakok.gitlabclient.ui.mergerequest.MergeRequestFlowFragment
import ru.terrakok.gitlabclient.ui.mergerequest.MergeRequestFragment
import ru.terrakok.gitlabclient.ui.mergerequest.MergeRequestInfoFragment
import ru.terrakok.gitlabclient.ui.mergerequest.MergeRequestNotesFragment
import ru.terrakok.gitlabclient.ui.my.activity.MyEventsFragment
import ru.terrakok.gitlabclient.ui.my.issues.MyIssuesContainerFragment
import ru.terrakok.gitlabclient.ui.my.issues.MyIssuesFragment
import ru.terrakok.gitlabclient.ui.my.mergerequests.MyMergeRequestsContainerFragment
import ru.terrakok.gitlabclient.ui.my.mergerequests.MyMergeRequestsFragment
import ru.terrakok.gitlabclient.ui.my.todos.MyTodosContainerFragment
import ru.terrakok.gitlabclient.ui.my.todos.MyTodosFragment
import ru.terrakok.gitlabclient.ui.project.ProjectFlowFragment
import ru.terrakok.gitlabclient.ui.project.ProjectFragment
import ru.terrakok.gitlabclient.ui.project.ProjectMainFlowFragment
import ru.terrakok.gitlabclient.ui.project.info.ProjectInfoFragment
import ru.terrakok.gitlabclient.ui.projects.ProjectsContainerFragment
import ru.terrakok.gitlabclient.ui.projects.ProjectsListFragment
import ru.terrakok.gitlabclient.ui.user.UserFlowFragment
import ru.terrakok.gitlabclient.ui.user.info.UserInfoFragment
......@@ -24,8 +37,22 @@ import ru.terrakok.gitlabclient.ui.user.info.UserInfoFragment
*/
object Screens {
const val DRAWER_FLOW = "drawer flow"
const val MAIN_SCREEN = "main screen"
const val MAIN_FLOW = "main flow"
const val MY_EVENTS_SCREEN = "my events screen"
const val MY_ISSUES_CONTAINER_SCREEN = "my issues container screen"
const val MY_ISSUES_SCREEN = "my issues screen"
const val MY_MR_CONTAINER_SCREEN = "my mr container screen"
const val MY_MR_SCREEN = "my mr screen"
const val MY_TODOS_CONTAINER_SCREEN = "my todo container screen"
const val MY_TODOS_SCREEN = "my todo screen"
const val PROJECTS_CONTAINER_SCREEN = "projects container screen"
const val PROJECTS_SCREEN = "projects screen"
const val ABOUT_SCREEN = "about screen"
const val APP_LIBRARIES_FLOW = "app libraries flow"
......@@ -34,20 +61,27 @@ object Screens {
const val AUTH_SCREEN = "auth screen"
const val PROJECT_FLOW = "project flow"
const val PROJECT_SCREEN = "project screen"
const val PROJECT_MAIN_FLOW = "project main flow"
const val PROJECT_INFO_SCREEN = "project info screen"
const val PROJECT_ISSUES_SCREEN = "project issues screen"
const val PROJECT_MR_SCREEN = "project mr screen"
const val USER_FLOW = "user flow"
const val USER_INFO_SCREEN = "user info screen"
const val MR_FLOW = "mr flow"
const val MR_SCREEN = "mr screen"
const val MR_INFO_SCREEN = "mr info screen"
const val MR_NOTES_SCREEN = "mr notes screen"
const val ISSUE_FLOW = "issue flow"
const val ISSUE_SCREEN = "issue screen"
const val ISSUE_INFO_SCREEN = "issue info screen"
const val ISSUE_NOTES_SCREEN = "issue notes screen"
const val EXTERNAL_BROWSER_FLOW = "external_browser_flow"
const val SHARE_FLOW = "share_flow"
const val CALL_FLOW = "call_flow"
const val EXTERNAL_BROWSER_FLOW = "external browser flow"
const val SHARE_FLOW = "share flow"
const val CALL_FLOW = "call flow"
fun createIntent(flowKey: String, data: Any?) = when (flowKey) {
Screens.EXTERNAL_BROWSER_FLOW -> Intent(Intent.ACTION_VIEW, Uri.parse(data as String))
......@@ -62,11 +96,31 @@ object Screens {
else -> null
}
fun createFragment(screenKey: String, data: Any? = null): Fragment? =
fun createFragment(screenKey: String, data: Any? = null): BaseFragment? =
when (screenKey) {
Screens.DRAWER_FLOW -> DrawerFlowFragment()
Screens.MAIN_SCREEN -> MainFragment()
Screens.PROJECTS_SCREEN -> ProjectsContainerFragment()
Screens.MAIN_FLOW -> MainFlowFragment()
Screens.MY_EVENTS_SCREEN -> MyEventsFragment()
Screens.MY_ISSUES_CONTAINER_SCREEN -> MyIssuesContainerFragment()
Screens.MY_ISSUES_SCREEN -> {
val (createdByMe, onlyOpened) = data as Pair<Boolean, Boolean>
MyIssuesFragment.create(createdByMe, onlyOpened)
}
Screens.MY_MR_CONTAINER_SCREEN -> MyMergeRequestsContainerFragment()
Screens.MY_MR_SCREEN -> {
val (createdByMe, onlyOpened) = data as Pair<Boolean, Boolean>
MyMergeRequestsFragment.create(createdByMe, onlyOpened)
}
Screens.MY_TODOS_CONTAINER_SCREEN -> MyTodosContainerFragment()
Screens.MY_TODOS_SCREEN -> MyTodosFragment.create(data as Boolean)
Screens.PROJECTS_CONTAINER_SCREEN -> ProjectsContainerFragment()
Screens.PROJECTS_SCREEN -> ProjectsListFragment.create(data as Int)
Screens.ABOUT_SCREEN -> AboutFragment()
Screens.APP_LIBRARIES_FLOW -> LibrariesFragment()
......@@ -78,19 +132,24 @@ object Screens {
Screens.USER_INFO_SCREEN -> UserInfoFragment()
Screens.PROJECT_FLOW -> ProjectFlowFragment.create(data as Long)
Screens.PROJECT_SCREEN -> ProjectFragment()
Screens.PROJECT_MAIN_FLOW -> ProjectMainFlowFragment()
Screens.PROJECT_INFO_SCREEN -> ProjectInfoFragment()
Screens.MR_FLOW -> {
val (projectId, mrId) = data as Pair<Long, Long>
MergeRequestFlowFragment.create(projectId, mrId)
}
Screens.MR_SCREEN -> MergeRequestFragment()
Screens.MR_INFO_SCREEN -> MergeRequestInfoFragment()
Screens.MR_NOTES_SCREEN -> MergeRequestNotesFragment()
Screens.ISSUE_FLOW -> {
val (projectId, issueId) = data as Pair<Long, Long>
IssueFlowFragment.create(projectId, issueId)
}
Screens.ISSUE_SCREEN -> IssueFragment()
Screens.ISSUE_INFO_SCREEN -> IssueInfoFragment()
Screens.ISSUE_NOTES_SCREEN -> IssueNotesFragment()
else -> null
}
}
\ No newline at end of file
......@@ -47,8 +47,8 @@ class NavigationDrawerPresenter @Inject constructor(
menuController.close()
if (item != currentSelectedItem) {
when (item) {
ACTIVITY -> router.newRootScreen(Screens.MAIN_SCREEN)
PROJECTS -> router.newRootScreen(Screens.PROJECTS_SCREEN)
ACTIVITY -> router.newRootScreen(Screens.MAIN_FLOW)
PROJECTS -> router.newRootScreen(Screens.PROJECTS_CONTAINER_SCREEN)
ABOUT -> router.newRootScreen(Screens.ABOUT_SCREEN)
}
}
......
......@@ -79,6 +79,7 @@ class MyEventsPresenter @Inject constructor(
fun onUserClick(userId: Long) = router.startFlow(Screens.USER_FLOW, userId)
fun refreshEvents() = paginator.refresh()
fun loadNextEventsPage() = paginator.loadNewPage()
fun onBackPressed() = router.exit()
override fun onDestroy() {
super.onDestroy()
......
......@@ -71,7 +71,7 @@ class AppActivity : MvpAppCompatActivity(), MvpView {
nextFragment: Fragment?,
fragmentTransaction: FragmentTransaction
) {
//fix incorrect order lifecycle callback of MainFragment
//fix incorrect order lifecycle callback of MainFlowFragment
fragmentTransaction.setReorderingAllowed(true)
}
}
......
package ru.terrakok.gitlabclient.ui.launch
package ru.terrakok.gitlabclient.ui.drawer
import android.os.Bundle
import android.support.v4.app.Fragment
......@@ -24,9 +24,8 @@ import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.toothpick.module.FlowNavigationModule
import ru.terrakok.gitlabclient.toothpick.module.GlobalMenuModule
import ru.terrakok.gitlabclient.ui.about.AboutFragment
import ru.terrakok.gitlabclient.ui.drawer.NavigationDrawerFragment
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.main.MainFragment
import ru.terrakok.gitlabclient.ui.main.MainFlowFragment
import ru.terrakok.gitlabclient.ui.projects.ProjectsContainerFragment
import toothpick.Toothpick
import javax.inject.Inject
......@@ -81,7 +80,7 @@ class DrawerFlowFragment : BaseFragment(), MvpView {
nextFragment: Fragment?,
fragmentTransaction: FragmentTransaction
) {
//fix incorrect order lifecycle callback of MainFragment
//fix incorrect order lifecycle callback of MainFlowFragment
fragmentTransaction.setReorderingAllowed(true)
}
}
......@@ -97,7 +96,7 @@ class DrawerFlowFragment : BaseFragment(), MvpView {
.replace(R.id.navDrawerContainer, NavigationDrawerFragment())
.commitNow()
navigator.setLaunchScreen(Screens.MAIN_SCREEN)
navigator.setLaunchScreen(Screens.MAIN_FLOW)
}
}
......@@ -134,7 +133,7 @@ class DrawerFlowFragment : BaseFragment(), MvpView {
drawerFragment?.let { drawerFragment ->
currentFragment?.let {
when (it) {
is MainFragment -> drawerFragment.onScreenChanged(NavigationDrawerView.MenuItem.ACTIVITY)
is MainFlowFragment -> drawerFragment.onScreenChanged(NavigationDrawerView.MenuItem.ACTIVITY)
is ProjectsContainerFragment -> drawerFragment.onScreenChanged(NavigationDrawerView.MenuItem.PROJECTS)
is AboutFragment -> drawerFragment.onScreenChanged(NavigationDrawerView.MenuItem.ABOUT)
}
......
......@@ -39,7 +39,7 @@ abstract class FlowFragment : BaseFragment() {
nextFragment: Fragment?,
fragmentTransaction: FragmentTransaction
) {
//fix incorrect order lifecycle callback of MainFragment
//fix incorrect order lifecycle callback of MainFlowFragment
fragmentTransaction.setReorderingAllowed(true)
}
}
......
......@@ -4,6 +4,7 @@ import android.os.Bundle
import android.support.v4.app.FragmentPagerAdapter
import kotlinx.android.synthetic.main.fragment_mr.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
......@@ -45,8 +46,8 @@ class IssueFragment : BaseFragment(), IssueInfoFragment.ToolbarConfigurator {
private inner class IssuePagesAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int): BaseFragment? = when (position) {
0 -> IssueInfoFragment()
1 -> IssueNotesFragment()
0 -> Screens.createFragment(Screens.ISSUE_INFO_SCREEN)
1 -> Screens.createFragment(Screens.ISSUE_NOTES_SCREEN)
else -> null
}
......
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.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.color
import ru.terrakok.gitlabclient.ui.global.BaseFragment
/**
* @author Konstantin Tskhovrebov (aka terrakok). Date: 02.04.17
*/
class MainFlowFragment : BaseFragment() {
override val layoutRes = R.layout.fragment_main
private val currentTabFragment: BaseFragment?
get() = childFragmentManager.fragments.firstOrNull { !it.isHidden } as? BaseFragment
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
AHBottomNavigationAdapter(activity, R.menu.main_bottom_menu).apply {
setupWithBottomNavigation(bottomBar)
}
with(bottomBar) {
accentColor = context.color(R.color.colorPrimary)
inactiveColor = context.color(R.color.silver)
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
}
)
true
}
}
selectTab(currentTabFragment?.tag ?: Screens.MY_EVENTS_SCREEN)
}
private fun selectTab(tab: String) {
val currentFragment = currentTabFragment
val newFragment = childFragmentManager.findFragmentByTag(tab)
if (currentFragment != null && newFragment != null && currentFragment == newFragment) return
childFragmentManager.beginTransaction().apply {
if (newFragment == null) add(R.id.mainScreenContainer, createTabFragment(tab), tab)
currentFragment?.let {
hide(it)
it.userVisibleHint = false
}
newFragment?.let {
show(it)
it.userVisibleHint = true
}
}.commitNow()
}
private fun createTabFragment(tab: String) =
Screens.createFragment(tab) ?: throw RuntimeException("Unknown tab $tab")
override fun onBackPressed() {
currentTabFragment?.onBackPressed()
}
}
\ No newline at end of file
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.gitlabclient.R
import ru.terrakok.gitlabclient.extension.color
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.my.activity.MyEventsFragment
import ru.terrakok.gitlabclient.ui.my.issues.MyIssuesContainerFragment
import ru.terrakok.gitlabclient.ui.my.mergerequests.MyMergeRequestsContainerFragment
import ru.terrakok.gitlabclient.ui.my.todos.MyTodosContainerFragment
import javax.inject.Inject
/**
* @author Konstantin Tskhovrebov (aka terrakok). Date: 02.04.17
*/
class MainFragment : BaseFragment() {
override val layoutRes = R.layout.fragment_main
private lateinit var tabs: HashMap<String, BaseFragment>
private val tabKeys = listOf(
tabIdToFragmentTag(R.id.tab_activity),
tabIdToFragmentTag(R.id.tab_issue),
tabIdToFragmentTag(R.id.tab_merge),
tabIdToFragmentTag(R.id.tab_todo)
)
@Inject
lateinit var router: FlowRouter
private fun tabIdToFragmentTag(id: Int) = "tab_$id"
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
AHBottomNavigationAdapter(activity, R.menu.main_bottom_menu).apply {
setupWithBottomNavigation(bottomBar)
}
with(bottomBar) {
accentColor = context.color(R.color.colorPrimary)
inactiveColor = context.color(R.color.silver)
setOnTabSelectedListener { position, wasSelected ->
if (!wasSelected) showTab(position, currentItem)
true
}
}
if (savedInstanceState == null) {
tabs = createNewFragments()
childFragmentManager.beginTransaction()
.add(R.id.mainScreenContainer, tabs[tabKeys[0]], tabKeys[0])
.add(R.id.mainScreenContainer, tabs[tabKeys[1]], tabKeys[1])
.add(R.id.mainScreenContainer, tabs[tabKeys[2]], tabKeys[2])
.add(R.id.mainScreenContainer, tabs[tabKeys[3]], tabKeys[3])
.hide(tabs[tabKeys[1]])
.hide(tabs[tabKeys[2]])
.hide(tabs[tabKeys[3]])
.commitNow()
bottomBar.setCurrentItem(0, false)
} else {
tabs = findFragments()
}
}
private fun showTab(newItem: Int, oldItem: Int) {
childFragmentManager.beginTransaction()
.hide(tabs[tabKeys[oldItem]])
.show(tabs[tabKeys[newItem]])
.commit()
}
private fun createNewFragments(): HashMap<String, BaseFragment> = hashMapOf(
tabKeys[0] to MyEventsFragment(),
tabKeys[1] to MyIssuesContainerFragment(),
tabKeys[2] to MyMergeRequestsContainerFragment(),
tabKeys[3] to MyTodosContainerFragment()
)
private fun findFragments(): HashMap<String, BaseFragment> = hashMapOf(
tabKeys[0] to childFragmentManager.findFragmentByTag(tabKeys[0]) as BaseFragment,
tabKeys[1] to childFragmentManager.findFragmentByTag(tabKeys[1]) as BaseFragment,
tabKeys[2] to childFragmentManager.findFragmentByTag(tabKeys[2]) as BaseFragment,
tabKeys[3] to childFragmentManager.findFragmentByTag(tabKeys[3]) as BaseFragment
)
override fun onBackPressed() {
router.exit()
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import android.os.Bundle
import android.support.v4.app.FragmentPagerAdapter
import kotlinx.android.synthetic.main.fragment_mr.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
......@@ -45,8 +46,8 @@ class MergeRequestFragment : BaseFragment(), MergeRequestInfoFragment.ToolbarCon
private inner class MergeRequestPagesAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int): BaseFragment? = when (position) {
0 -> MergeRequestInfoFragment()
1 -> MergeRequestNotesFragment()
0 -> Screens.createFragment(Screens.MR_INFO_SCREEN)
1 -> Screens.createFragment(Screens.MR_NOTES_SCREEN)
else -> null
}
......
......@@ -91,4 +91,8 @@ class MyEventsFragment : BaseFragment(), MyEventsView {
override fun showMessage(message: String) {
showSnackMessage(message)
}
override fun onBackPressed() {
presenter.onBackPressed()
}
}
\ No newline at end of file
......@@ -4,6 +4,8 @@ import android.os.Bundle
import android.support.v4.app.FragmentPagerAdapter
import kotlinx.android.synthetic.main.fragment_my_issues_container.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.presentation.global.GlobalMenuController
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
......@@ -14,6 +16,10 @@ import javax.inject.Inject
* Created by Konstantin Tskhovrebov (aka @terrakok) on 16.07.17.
*/
class MyIssuesContainerFragment : BaseFragment() {
@Inject
lateinit var router: FlowRouter
@Inject
lateinit var menuController: GlobalMenuController
......@@ -59,10 +65,14 @@ class MyIssuesContainerFragment : BaseFragment() {
outState.putBoolean(STATE_ONLY_OPENED, showOnlyOpened)
}
override fun onBackPressed() {
router.exit()
}
private inner class MyIssuesPagesAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int) = when (position) {
0 -> MyIssuesFragment.newInstance(true, showOnlyOpened)
1 -> MyIssuesFragment.newInstance(false, showOnlyOpened)
0 -> Screens.createFragment(Screens.MY_ISSUES_SCREEN, Pair(true, showOnlyOpened))
1 -> Screens.createFragment(Screens.MY_ISSUES_SCREEN, Pair(false, showOnlyOpened))
else -> null
}
......
......@@ -24,19 +24,6 @@ import toothpick.config.Module
*/
class MyIssuesFragment : BaseFragment(), MyIssuesView {
companion object {
private val ARG_MODE_CREATED_BY_ME = "arg_mode_created_by_me"
private val ARG_MODE_ONLY_OPENED = "arg_mode_only opened"
fun newInstance(createdByMe: Boolean, onlyOpened: Boolean) =
MyIssuesFragment().apply {
arguments = Bundle().apply {
putBoolean(ARG_MODE_CREATED_BY_ME, createdByMe)
putBoolean(ARG_MODE_ONLY_OPENED, onlyOpened)
}
}
}
override val layoutRes = R.layout.fragment_my_issues
@InjectPresenter
......@@ -128,4 +115,17 @@ class MyIssuesFragment : BaseFragment(), MyIssuesView {
override fun showMessage(message: String) {
showSnackMessage(message)
}
companion object {
private const val ARG_MODE_CREATED_BY_ME = "arg_mode_created_by_me"
private const val ARG_MODE_ONLY_OPENED = "arg_mode_only opened"
fun create(createdByMe: Boolean, onlyOpened: Boolean) =
MyIssuesFragment().apply {
arguments = Bundle().apply {
putBoolean(ARG_MODE_CREATED_BY_ME, createdByMe)
putBoolean(ARG_MODE_ONLY_OPENED, onlyOpened)
}
}
}
}
\ No newline at end of file
......@@ -4,6 +4,8 @@ import android.os.Bundle
import android.support.v4.app.FragmentPagerAdapter
import kotlinx.android.synthetic.main.fragment_my_merge_requests_container.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.presentation.global.GlobalMenuController
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
......@@ -11,6 +13,10 @@ import toothpick.Toothpick
import javax.inject.Inject
class MyMergeRequestsContainerFragment : BaseFragment() {
@Inject
lateinit var router: FlowRouter
@Inject
lateinit var menuController: GlobalMenuController
......@@ -57,10 +63,14 @@ class MyMergeRequestsContainerFragment : BaseFragment() {
outState.putBoolean(STATE_ONLY_OPENED, showOnlyOpened)
}
override fun onBackPressed() {
router.exit()
}
private inner class MyMergeRequestsPagesAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int) = when (position) {
0 -> MyMergeRequestsFragment.newInstance(true, showOnlyOpened)
1 -> MyMergeRequestsFragment.newInstance(false, showOnlyOpened)
0 -> Screens.createFragment(Screens.MY_MR_SCREEN, Pair(true, showOnlyOpened))
1 -> Screens.createFragment(Screens.MY_MR_SCREEN, Pair(false, showOnlyOpened))
else -> null
}
......
......@@ -24,19 +24,6 @@ import toothpick.config.Module
*/
class MyMergeRequestsFragment : BaseFragment(), MyMergeRequestListView {
companion object {
private val ARG_MODE_CREATED_BY_ME = "arg_mode_created_by_me"
private val ARG_MODE_ONLY_OPENED = "arg_mode_only opened"
fun newInstance(createdByMe: Boolean, onlyOpened: Boolean) =
MyMergeRequestsFragment().apply {
arguments = Bundle().apply {
putBoolean(ARG_MODE_CREATED_BY_ME, createdByMe)
putBoolean(ARG_MODE_ONLY_OPENED, onlyOpened)
}
}
}
override val layoutRes = R.layout.fragment_my_merge_requests
@InjectPresenter
......@@ -128,4 +115,17 @@ class MyMergeRequestsFragment : BaseFragment(), MyMergeRequestListView {
override fun showMessage(message: String) {
showSnackMessage(message)
}
companion object {
private const val ARG_MODE_CREATED_BY_ME = "arg_mode_created_by_me"
private const val ARG_MODE_ONLY_OPENED = "arg_mode_only opened"
fun create(createdByMe: Boolean, onlyOpened: Boolean) =
MyMergeRequestsFragment().apply {
arguments = Bundle().apply {
putBoolean(ARG_MODE_CREATED_BY_ME, createdByMe)
putBoolean(ARG_MODE_ONLY_OPENED, onlyOpened)
}
}
}
}
\ No newline at end of file
......@@ -4,6 +4,8 @@ import android.os.Bundle
import android.support.v4.app.FragmentPagerAdapter
import kotlinx.android.synthetic.main.fragment_my_todos_container.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.presentation.global.GlobalMenuController
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
......@@ -15,6 +17,9 @@ import javax.inject.Inject
*/
class MyTodosContainerFragment : BaseFragment() {
@Inject
lateinit var router: FlowRouter
@Inject
lateinit var menuController: GlobalMenuController
......@@ -34,10 +39,14 @@ class MyTodosContainerFragment : BaseFragment() {
viewPager.adapter = adapter
}
override fun onBackPressed() {
router.exit()
}
private inner class MyTodosPagerAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int) = when (position) {
0 -> MyTodosFragment.newInstance(true)
1 -> MyTodosFragment.newInstance(false)
0 -> Screens.createFragment(Screens.MY_TODOS_SCREEN, true)
1 -> Screens.createFragment(Screens.MY_TODOS_SCREEN, false)
else -> null
}
......
......@@ -26,14 +26,6 @@ import toothpick.config.Module
*/
class MyTodosFragment : BaseFragment(), MyTodoListView {
companion object {
private val ARG_MODE_IS_PENDING = "arg_mode_is_pending"
fun newInstance(isPending: Boolean) = MyTodosFragment().apply {
arguments = Bundle().apply { putBoolean(ARG_MODE_IS_PENDING, isPending) }
}
}
override val layoutRes = R.layout.fragment_my_todos
private val adapter: TargetsAdapter by lazy {
......@@ -112,4 +104,12 @@ class MyTodosFragment : BaseFragment(), MyTodoListView {
override fun showMessage(message: String) {
showSnackMessage(message)
}
companion object {
private const val ARG_MODE_IS_PENDING = "arg_mode_is_pending"
fun create(isPending: Boolean) = MyTodosFragment().apply {
arguments = Bundle().apply { putBoolean(ARG_MODE_IS_PENDING, isPending) }
}
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ class ProjectFlowFragment : FlowFragment(), MvpView {
initScope()
super.onCreate(savedInstanceState)
if (childFragmentManager.fragments.isEmpty()) {
navigator.setLaunchScreen(Screens.PROJECT_SCREEN, null)
navigator.setLaunchScreen(Screens.PROJECT_MAIN_FLOW, null)
}
}
......