Commit 7ded215c authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Return flow fragments.

parent fa7a0625
......@@ -8,13 +8,13 @@ import ru.terrakok.gitlabclient.entity.issue.IssueState
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestState
import ru.terrakok.gitlabclient.entity.milestone.MilestoneState
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.FlowFactory
import ru.terrakok.gitlabclient.ui.global.StubFragment
import ru.terrakok.gitlabclient.ui.issue.MainIssueFragment
import ru.terrakok.gitlabclient.ui.issue.IssueFlowFragment
import ru.terrakok.gitlabclient.ui.issue.IssueInfoFragment
import ru.terrakok.gitlabclient.ui.issue.IssueNotesFragment
import ru.terrakok.gitlabclient.ui.issue.MainIssueFragment
import ru.terrakok.gitlabclient.ui.libraries.LibrariesFragment
import ru.terrakok.gitlabclient.ui.main.MainFragment
import ru.terrakok.gitlabclient.ui.mergerequest.*
......@@ -27,6 +27,7 @@ import ru.terrakok.gitlabclient.ui.my.todos.MyTodosContainerFragment
import ru.terrakok.gitlabclient.ui.my.todos.MyTodosFragment
import ru.terrakok.gitlabclient.ui.privacypolicy.PrivacyPolicyFragment
import ru.terrakok.gitlabclient.ui.project.MainProjectFragment
import ru.terrakok.gitlabclient.ui.project.ProjectFlowFragment
import ru.terrakok.gitlabclient.ui.project.files.ProjectFilesFragment
import ru.terrakok.gitlabclient.ui.project.info.ProjectEventsFragment
import ru.terrakok.gitlabclient.ui.project.info.ProjectInfoContainerFragment
......@@ -40,6 +41,7 @@ import ru.terrakok.gitlabclient.ui.project.milestones.ProjectMilestonesContainer
import ru.terrakok.gitlabclient.ui.project.milestones.ProjectMilestonesFragment
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
/**
......@@ -49,7 +51,7 @@ object Screens {
//flows
object AuthFlow : SupportAppScreen() {
override fun getFragment() = FlowFactory.createAuthFlowFragment()
override fun getFragment() = AuthFlowFragment()
}
object DrawerFlow : SupportAppScreen() {
......@@ -59,27 +61,27 @@ object Screens {
data class ProjectFlow(
val projectId: Long
) : SupportAppScreen() {
override fun getFragment() = FlowFactory.createProjectFlowFragment(projectId)
override fun getFragment() = ProjectFlowFragment.create(projectId)
}
data class UserFlow(
val userId: Long
) : SupportAppScreen() {
override fun getFragment() = FlowFactory.createUserFlowFragment(userId)
override fun getFragment() = UserFlowFragment.create(userId)
}
data class IssueFlow(
val projectId: Long,
val issueId: Long
) : SupportAppScreen() {
override fun getFragment() = FlowFactory.createIssueFlowFragment(projectId, issueId)
override fun getFragment() = IssueFlowFragment.create(projectId, issueId)
}
data class MergeRequestFlow(
val projectId: Long,
val mrId: Long
) : SupportAppScreen() {
override fun getFragment() = FlowFactory.createMergeRequestFlowFragment(projectId, mrId)
override fun getFragment() = MergeRequestFlowFragment.create(projectId, mrId)
}
//screens
......
package ru.terrakok.gitlabclient.ui.auth
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.ui.global.FlowFragment
class AuthFlowFragment : FlowFragment() {
override fun getLaunchScreen() = Screens.Auth
}
\ No newline at end of file
package ru.terrakok.gitlabclient.ui.global
import android.os.Bundle
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.di.*
import toothpick.config.Module
object FlowFactory {
private const val ARG_TYPE = "arg_type"
private const val ARG_PROJECT_ID = "arg_project_id"
private const val ARG_ISSUE_ID = "arg_issue_id"
private const val ARG_MR_ID = "arg_mr_id"
private const val ARG_USER_ID = "arg_user_id"
private enum class Type {
AUTH,
PROJECT,
ISSUE,
MERGE_REQUEST,
USER
}
fun createAuthFlowFragment() =
FlowFragment().apply {
arguments = Bundle().apply {
putSerializable(ARG_TYPE, Type.AUTH)
}
}
fun createUserFlowFragment(userId: Long) =
FlowFragment().apply {
arguments = Bundle().apply {
putSerializable(ARG_TYPE, Type.USER)
putLong(ARG_USER_ID, userId)
}
}
fun createIssueFlowFragment(projectId: Long, issueId: Long) =
FlowFragment().apply {
arguments = Bundle().apply {
putSerializable(ARG_TYPE, Type.ISSUE)
putLong(ARG_PROJECT_ID, projectId)
putLong(ARG_ISSUE_ID, issueId)
}
}
fun createMergeRequestFlowFragment(projectId: Long, mrId: Long) =
FlowFragment().apply {
arguments = Bundle().apply {
putSerializable(ARG_TYPE, Type.MERGE_REQUEST)
putLong(ARG_PROJECT_ID, projectId)
putLong(ARG_MR_ID, mrId)
}
}
fun createProjectFlowFragment(projectId: Long) =
FlowFragment().apply {
arguments = Bundle().apply {
putSerializable(ARG_TYPE, Type.PROJECT)
putLong(ARG_PROJECT_ID, projectId)
}
}
fun createFlowModule(arguments: Bundle) = object : Module() {
init {
when (arguments.getSerializable(ARG_TYPE) as Type) {
Type.USER -> {
bind(PrimitiveWrapper::class.java)
.withName(UserId::class.java)
.toInstance(PrimitiveWrapper(arguments.getLong(ARG_USER_ID)))
}
Type.ISSUE -> {
bind(PrimitiveWrapper::class.java)
.withName(ProjectId::class.java)
.toInstance(PrimitiveWrapper(arguments.getLong(ARG_PROJECT_ID)))
bind(PrimitiveWrapper::class.java)
.withName(IssueId::class.java)
.toInstance(PrimitiveWrapper(arguments.getLong(ARG_ISSUE_ID)))
}
Type.MERGE_REQUEST -> {
bind(PrimitiveWrapper::class.java)
.withName(ProjectId::class.java)
.toInstance(PrimitiveWrapper(arguments.getLong(ARG_PROJECT_ID)))
bind(PrimitiveWrapper::class.java)
.withName(MergeRequestId::class.java)
.toInstance(PrimitiveWrapper(arguments.getLong(ARG_MR_ID)))
}
Type.PROJECT -> {
bind(PrimitiveWrapper::class.java)
.withName(ProjectId::class.java)
.toInstance(PrimitiveWrapper(arguments.getLong(ARG_PROJECT_ID)))
}
}
}
}
fun getFlowRootScreen(arguments: Bundle) =
when (arguments.getSerializable(ARG_TYPE) as Type) {
Type.AUTH -> Screens.Auth
Type.USER -> Screens.UserInfo
Type.ISSUE -> Screens.MainIssue
Type.MERGE_REQUEST -> Screens.MainMergeRequest
Type.PROJECT -> Screens.MainProject
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import ru.terrakok.cicerone.Navigator
import ru.terrakok.cicerone.NavigatorHolder
import ru.terrakok.cicerone.Router
import ru.terrakok.cicerone.android.support.SupportAppNavigator
import ru.terrakok.cicerone.android.support.SupportAppScreen
import ru.terrakok.cicerone.commands.Command
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.di.module.FlowNavigationModule
......@@ -18,7 +19,7 @@ import javax.inject.Inject
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 03.09.18.
*/
class FlowFragment : BaseFragment() {
abstract class FlowFragment : BaseFragment() {
override val layoutRes: Int = R.layout.layout_container
private val currentFragment
......@@ -32,8 +33,7 @@ class FlowFragment : BaseFragment() {
override fun installModules(scope: Scope) {
scope.installModules(
FlowNavigationModule(scope.getInstance(Router::class.java)),
FlowFactory.createFlowModule(arguments!!)
FlowNavigationModule(scope.getInstance(Router::class.java))
)
}
......@@ -59,10 +59,12 @@ class FlowFragment : BaseFragment() {
super.onCreate(savedInstanceState)
Toothpick.inject(this, scope)
if (childFragmentManager.fragments.isEmpty()) {
navigator.setLaunchScreen(FlowFactory.getFlowRootScreen(arguments!!))
navigator.setLaunchScreen(getLaunchScreen())
}
}
abstract fun getLaunchScreen(): SupportAppScreen
override fun onBackPressed() {
currentFragment?.onBackPressed() ?: super.onBackPressed()
}
......
package ru.terrakok.gitlabclient.ui.issue
import android.os.Bundle
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.di.IssueId
import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.di.ProjectId
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.ui.global.FlowFragment
import toothpick.Scope
import toothpick.config.Module
class IssueFlowFragment : FlowFragment() {
private val issueId by argument(ARG_ISSUE_ID, 0L)
private val projectId by argument(ARG_PROJECT_ID, 0L)
override fun installModules(scope: Scope) {
super.installModules(scope)
scope.installModules(
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
.withName(ProjectId::class.java)
.toInstance(PrimitiveWrapper(projectId))
bind(PrimitiveWrapper::class.java)
.withName(IssueId::class.java)
.toInstance(PrimitiveWrapper(issueId))
}
}
)
}
override fun getLaunchScreen() = Screens.MainIssue
companion object {
private const val ARG_PROJECT_ID = "arg_project_id"
private const val ARG_ISSUE_ID = "arg_issue_id"
fun create(projectId: Long, issueId: Long) =
IssueFlowFragment().apply {
arguments = Bundle().apply {
putLong(ARG_PROJECT_ID, projectId)
putLong(ARG_ISSUE_ID, issueId)
}
}
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.ui.mergerequest
import android.os.Bundle
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.di.MergeRequestId
import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.di.ProjectId
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.ui.global.FlowFragment
import toothpick.Scope
import toothpick.config.Module
class MergeRequestFlowFragment : FlowFragment() {
private val mrId by argument(ARG_MR_ID, 0L)
private val projectId by argument(ARG_PROJECT_ID, 0L)
override fun installModules(scope: Scope) {
super.installModules(scope)
scope.installModules(
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
.withName(ProjectId::class.java)
.toInstance(PrimitiveWrapper(projectId))
bind(PrimitiveWrapper::class.java)
.withName(MergeRequestId::class.java)
.toInstance(PrimitiveWrapper(mrId))
}
}
)
}
override fun getLaunchScreen() = Screens.MainMergeRequest
companion object {
private const val ARG_PROJECT_ID = "arg_project_id"
private const val ARG_MR_ID = "arg_mr_id"
fun create(projectId: Long, mrId: Long) =
MergeRequestFlowFragment().apply {
arguments = Bundle().apply {
putLong(ARG_PROJECT_ID, projectId)
putLong(ARG_MR_ID, mrId)
}
}
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.ui.project
import android.os.Bundle
import ru.terrakok.cicerone.android.support.SupportAppScreen
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.di.ProjectId
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.ui.global.FlowFragment
import toothpick.Scope
import toothpick.config.Module
class ProjectFlowFragment : FlowFragment() {
private val projectId by argument(ARG_PROJECT_ID, 0L)
override fun installModules(scope: Scope) {
super.installModules(scope)
scope.installModules(
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
.withName(ProjectId::class.java)
.toInstance(PrimitiveWrapper(projectId))
}
}
)
}
override fun getLaunchScreen() = Screens.MainProject
companion object {
private const val ARG_PROJECT_ID = "arg_project_id"
fun create(projectId: Long) =
ProjectFlowFragment().apply {
arguments = Bundle().apply {
putLong(ARG_PROJECT_ID, projectId)
}
}
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.ui.user
import android.os.Bundle
import ru.terrakok.cicerone.android.support.SupportAppScreen
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.di.UserId
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.ui.global.FlowFragment
import toothpick.Scope
import toothpick.config.Module
class UserFlowFragment : FlowFragment() {
private val userId by argument(ARG_USER_ID, 0L)
override fun installModules(scope: Scope) {
super.installModules(scope)
scope.installModules(
object : Module() {
init {
bind(PrimitiveWrapper::class.java)
.withName(UserId::class.java)
.toInstance(PrimitiveWrapper(userId))
}
}
)
}
override fun getLaunchScreen() = Screens.UserInfo
companion object {
private const val ARG_USER_ID = "arg_user_id"
fun create(userId: Long) =
UserFlowFragment().apply {
arguments = Bundle().apply {
putLong(ARG_USER_ID, userId)
}
}
}
}
\ 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