Commit 81a267a1 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Add dynamic scopes for project flow.

parent 210b239d
......@@ -4,6 +4,7 @@ import android.content.Intent
import android.net.Uri
import ru.terrakok.gitlabclient.entity.issue.IssueState
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestState
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.about.AboutFragment
import ru.terrakok.gitlabclient.ui.auth.AuthFlowFragment
import ru.terrakok.gitlabclient.ui.auth.AuthFragment
......@@ -112,52 +113,51 @@ object Screens {
fun createFragment(screenKey: String, data: Any? = null): BaseFragment? =
when (screenKey) {
//DRAWER SCOPE SCREENS
Screens.DRAWER_FLOW -> DrawerFlowFragment()
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()
//AUTH SCREENS
Screens.AUTH_FLOW -> AuthFlowFragment()
Screens.AUTH_SCREEN -> AuthFragment()
//USER SCOPE SCREENS
Screens.USER_FLOW -> UserFlowFragment.create(data as Long)
Screens.USER_INFO_SCREEN -> UserInfoFragment()
Screens.PROJECT_FLOW -> ProjectFlowFragment.create(data as Long)
Screens.PROJECT_MAIN_FLOW -> ProjectFragment()
Screens.PROJECT_INFO_CONTAINER_SCREEN -> ProjectInfoContainerFragment()
Screens.PROJECT_INFO_SCREEN -> ProjectInfoFragment()
Screens.PROJECT_EVENTS_SCREEN -> ProjectEventsFragment()
Screens.PROJECT_ISSUES_CONTAINER_SCREEN -> ProjectIssuesContainerFragment()
Screens.PROJECT_ISSUES_SCREEN -> ProjectIssuesFragment.create(data as IssueState)
Screens.PROJECT_MR_CONTAINER_SCREEN -> ProjectMergeRequestsContainerFragment()
Screens.PROJECT_MR_SCREEN -> ProjectMergeRequestsFragment.create(data as MergeRequestState)
//PROJECT SCOPE SCREENS
Screens.PROJECT_FLOW -> {
ProjectFlowFragment.create(data as Long, DI.PROJECT_FLOW_SCOPE + " " + System.currentTimeMillis())
}
Screens.PROJECT_MAIN_FLOW -> ProjectFragment.create(data as String)
Screens.PROJECT_INFO_CONTAINER_SCREEN -> ProjectInfoContainerFragment.create(data as String)
Screens.PROJECT_INFO_SCREEN -> ProjectInfoFragment.create(data as String)
Screens.PROJECT_EVENTS_SCREEN -> ProjectEventsFragment.create(data as String)
Screens.PROJECT_ISSUES_CONTAINER_SCREEN -> ProjectIssuesContainerFragment.create(data as String)
Screens.PROJECT_ISSUES_SCREEN -> (data as Pair<IssueState, String>).let { (issueState, scope) ->
ProjectIssuesFragment.create(issueState, scope)
}
Screens.PROJECT_MR_CONTAINER_SCREEN -> ProjectMergeRequestsContainerFragment.create(data as String)
Screens.PROJECT_MR_SCREEN -> (data as Pair<MergeRequestState, String>).let { (mrState, scope) ->
ProjectMergeRequestsFragment.create(mrState, scope)
}
//MR SCOPE SCREENS
Screens.MR_FLOW -> {
val (projectId, mrId) = data as Pair<Long, Long>
MergeRequestFlowFragment.create(projectId, mrId)
......@@ -166,6 +166,7 @@ object Screens {
Screens.MR_INFO_SCREEN -> MergeRequestInfoFragment()
Screens.MR_NOTES_SCREEN -> MergeRequestNotesFragment()
//ISSUE SCOPE SCREENS
Screens.ISSUE_FLOW -> {
val (projectId, issueId) = data as Pair<Long, Long>
IssueFlowFragment.create(projectId, issueId)
......@@ -175,6 +176,8 @@ object Screens {
Screens.ISSUE_NOTES_SCREEN -> IssueNotesFragment()
Screens.PRIVACY_POLICY_FLOW -> PrivacyPolicyFragment()
Screens.ABOUT_SCREEN -> AboutFragment()
Screens.APP_LIBRARIES_FLOW -> LibrariesFragment()
else -> null
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ package ru.terrakok.gitlabclient.presentation.project
import com.arellomobile.mvp.MvpView
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.presentation.global.BasePresenter
import ru.terrakok.gitlabclient.toothpick.DI
import toothpick.Scope
import toothpick.Toothpick
import javax.inject.Inject
......@@ -11,11 +11,12 @@ import javax.inject.Inject
* Created by Konstantin Tskhovrebov (aka @terrakok) on 03.09.18.
*/
class ProjectFlowPresenter @Inject constructor(
private val router: Router
private val router: Router,
private val scope: Scope
) : BasePresenter<MvpView>() {
override fun onDestroy() {
Toothpick.closeScope(DI.PROJECT_FLOW_SCOPE)
Toothpick.closeScope(scope.name)
super.onDestroy()
}
......
......@@ -4,13 +4,15 @@ package ru.terrakok.gitlabclient.toothpick
* @author Konstantin Tskhovrebov (aka terrakok) on 09.07.17.
*/
object DI {
//single scopes
const val APP_SCOPE = "app scope"
const val SERVER_SCOPE = "server scope"
const val DRAWER_FLOW_SCOPE = "drawer flow scope"
const val AUTH_FLOW_SCOPE = "auth flow scope"
const val USER_FLOW_SCOPE = "user flow scope"
const val PROJECT_FLOW_SCOPE = "project flow scope"
const val MERGE_REQUEST_FLOW_SCOPE = "merge request flow scope"
const val ISSUE_FLOW_SCOPE = "issue flow scope"
//multi scopes
const val USER_FLOW_SCOPE = "user flow scope: "
const val PROJECT_FLOW_SCOPE = "project flow scope: "
const val MERGE_REQUEST_FLOW_SCOPE = "merge request flow scope: "
const val ISSUE_FLOW_SCOPE = "issue flow scope: "
}
\ No newline at end of file
......@@ -23,25 +23,26 @@ import toothpick.config.Module
class ProjectFlowFragment : FlowFragment(), MvpView {
private val projectId by argument(ARG_PROJECT_ID, 0L)
private val scopeName: String? by argument(ARG_SCOPE_NAME)
@InjectPresenter
lateinit var presenter: ProjectFlowPresenter
@ProvidePresenter
fun providePresenter() =
Toothpick.openScope(DI.PROJECT_FLOW_SCOPE)
Toothpick.openScope(scopeName)
.getInstance(ProjectFlowPresenter::class.java)
override fun onCreate(savedInstanceState: Bundle?) {
initScope()
super.onCreate(savedInstanceState)
if (childFragmentManager.fragments.isEmpty()) {
navigator.setLaunchScreen(Screens.PROJECT_MAIN_FLOW, null)
navigator.setLaunchScreen(Screens.PROJECT_MAIN_FLOW, scopeName)
}
}
private fun initScope() {
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, DI.PROJECT_FLOW_SCOPE)
val scope = Toothpick.openScopes(DI.SERVER_SCOPE, scopeName)
scope.installModules(
FlowNavigationModule(scope.getInstance(AppRouter::class.java)),
object : Module() {
......@@ -61,10 +62,12 @@ class ProjectFlowFragment : FlowFragment(), MvpView {
companion object {
private const val ARG_PROJECT_ID = "arg_project_id"
fun create(projectId: Long) =
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(projectId: Long, scope: String) =
ProjectFlowFragment().apply {
arguments = Bundle().apply {
putLong(ARG_PROJECT_ID, projectId)
putString(ARG_SCOPE_NAME, scope)
}
}
}
......
......@@ -5,10 +5,10 @@ import com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter
import kotlinx.android.synthetic.main.fragment_project.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.extension.color
import ru.terrakok.gitlabclient.extension.shareText
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.project.info.ProjectInfoFragment
import toothpick.Toothpick
......@@ -19,6 +19,7 @@ import javax.inject.Inject
*/
class ProjectFragment : BaseFragment(), ProjectInfoFragment.ProjectInfoToolbar {
override val layoutRes: Int = R.layout.fragment_project
private val scopeName: String? by argument(ARG_SCOPE_NAME)
private val currentTabFragment: BaseFragment?
get() = childFragmentManager.fragments.firstOrNull { !it.isHidden } as? BaseFragment
......@@ -29,7 +30,7 @@ class ProjectFragment : BaseFragment(), ProjectInfoFragment.ProjectInfoToolbar {
private var shareUrl: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
Toothpick.inject(this, Toothpick.openScope(DI.PROJECT_FLOW_SCOPE))
Toothpick.inject(this, Toothpick.openScope(scopeName))
super.onCreate(savedInstanceState)
}
......@@ -89,7 +90,7 @@ class ProjectFragment : BaseFragment(), ProjectInfoFragment.ProjectInfoToolbar {
}
private fun createTabFragment(tab: String) =
Screens.createFragment(tab) ?: throw RuntimeException("Unknown tab $tab")
Screens.createFragment(tab, scopeName) ?: throw RuntimeException("Unknown tab $tab")
override fun onBackPressed() {
super.onBackPressed()
......@@ -104,4 +105,14 @@ class ProjectFragment : BaseFragment(), ProjectInfoFragment.ProjectInfoToolbar {
override fun setShareUrl(url: String?) {
shareUrl = url
}
companion object {
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(scope: String) =
ProjectFragment().apply {
arguments = Bundle().apply {
putString(ARG_SCOPE_NAME, scope)
}
}
}
}
\ No newline at end of file
......@@ -8,11 +8,11 @@ import kotlinx.android.synthetic.main.layout_base_list.*
import kotlinx.android.synthetic.main.layout_zero.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.app.target.TargetHeader
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.extension.showSnackMessage
import ru.terrakok.gitlabclient.extension.visible
import ru.terrakok.gitlabclient.presentation.project.events.ProjectEventsPresenter
import ru.terrakok.gitlabclient.presentation.project.events.ProjectEventsView
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.global.ZeroViewHolder
import ru.terrakok.gitlabclient.ui.my.TargetsAdapter
......@@ -23,6 +23,7 @@ import toothpick.Toothpick
*/
class ProjectEventsFragment : BaseFragment(), ProjectEventsView {
override val layoutRes = R.layout.fragment_project_events
private val scopeName: String? by argument(ARG_SCOPE_NAME)
@InjectPresenter
lateinit var presenter: ProjectEventsPresenter
......@@ -39,7 +40,7 @@ class ProjectEventsFragment : BaseFragment(), ProjectEventsView {
@ProvidePresenter
fun providePresenter(): ProjectEventsPresenter =
Toothpick
.openScope(DI.PROJECT_FLOW_SCOPE)
.openScope(scopeName)
.getInstance(ProjectEventsPresenter::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
......@@ -93,4 +94,14 @@ class ProjectEventsFragment : BaseFragment(), ProjectEventsView {
override fun onBackPressed() {
presenter.onBackPressed()
}
companion object {
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(scope: String) =
ProjectEventsFragment().apply {
arguments = Bundle().apply {
putString(ARG_SCOPE_NAME, scope)
}
}
}
}
\ No newline at end of file
......@@ -5,8 +5,8 @@ import android.support.v4.app.FragmentPagerAdapter
import kotlinx.android.synthetic.main.fragment_project_info_container.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import toothpick.Toothpick
import javax.inject.Inject
......@@ -17,11 +17,12 @@ class ProjectInfoContainerFragment : BaseFragment(), ProjectInfoFragment.Project
lateinit var router: FlowRouter
override val layoutRes = R.layout.fragment_project_info_container
private val scopeName: String? by argument(ARG_SCOPE_NAME)
private val adapter: ProjectInfoPagesAdapter by lazy { ProjectInfoPagesAdapter() }
override fun onCreate(savedInstanceState: Bundle?) {
Toothpick.inject(this, Toothpick.openScope(DI.PROJECT_FLOW_SCOPE))
Toothpick.inject(this, Toothpick.openScope(scopeName))
super.onCreate(savedInstanceState)
}
......@@ -44,8 +45,8 @@ class ProjectInfoContainerFragment : BaseFragment(), ProjectInfoFragment.Project
private inner class ProjectInfoPagesAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int) = when (position) {
0 -> Screens.createFragment(Screens.PROJECT_INFO_SCREEN)
1 -> Screens.createFragment(Screens.PROJECT_EVENTS_SCREEN)
0 -> Screens.createFragment(Screens.PROJECT_INFO_SCREEN, scopeName)
1 -> Screens.createFragment(Screens.PROJECT_EVENTS_SCREEN, scopeName)
else -> null
}
......@@ -57,4 +58,14 @@ class ProjectInfoContainerFragment : BaseFragment(), ProjectInfoFragment.Project
else -> null
}
}
companion object {
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(scope: String) =
ProjectInfoContainerFragment().apply {
arguments = Bundle().apply {
putString(ARG_SCOPE_NAME, scope)
}
}
}
}
\ No newline at end of file
......@@ -12,7 +12,6 @@ import ru.terrakok.gitlabclient.entity.Visibility
import ru.terrakok.gitlabclient.extension.*
import ru.terrakok.gitlabclient.presentation.project.info.ProjectInfoPresenter
import ru.terrakok.gitlabclient.presentation.project.info.ProjectInfoView
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import toothpick.Toothpick
......@@ -22,6 +21,7 @@ import toothpick.Toothpick
class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
override val layoutRes = R.layout.fragment_project_info
private val scopeName: String? by argument(ARG_SCOPE_NAME)
@InjectPresenter
lateinit var presenter: ProjectInfoPresenter
......@@ -29,7 +29,7 @@ class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
@ProvidePresenter
fun providePresenter(): ProjectInfoPresenter =
Toothpick
.openScopes(DI.PROJECT_FLOW_SCOPE)
.openScopes(scopeName)
.getInstance(ProjectInfoPresenter::class.java)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
......@@ -77,4 +77,14 @@ class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
fun setTitle(title: String)
fun setShareUrl(url: String?)
}
companion object {
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(scope: String) =
ProjectInfoFragment().apply {
arguments = Bundle().apply {
putString(ARG_SCOPE_NAME, scope)
}
}
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ import kotlinx.android.synthetic.main.fragment_my_issues_container.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.entity.issue.IssueState
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.ui.global.BaseFragment
/**
......@@ -13,6 +14,7 @@ import ru.terrakok.gitlabclient.ui.global.BaseFragment
*/
class ProjectIssuesContainerFragment : BaseFragment() {
override val layoutRes = R.layout.fragment_project_issues_container
private val scopeName: String? by argument(ARG_SCOPE_NAME)
private val adapter: ProjectIssuesPagesAdapter by lazy { ProjectIssuesPagesAdapter() }
......@@ -25,8 +27,8 @@ class ProjectIssuesContainerFragment : BaseFragment() {
private inner class ProjectIssuesPagesAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int) = when (position) {
0 -> Screens.createFragment(Screens.PROJECT_ISSUES_SCREEN, IssueState.OPENED)
1 -> Screens.createFragment(Screens.PROJECT_ISSUES_SCREEN, IssueState.CLOSED)
0 -> Screens.createFragment(Screens.PROJECT_ISSUES_SCREEN, Pair(IssueState.OPENED, scopeName))
1 -> Screens.createFragment(Screens.PROJECT_ISSUES_SCREEN, Pair(IssueState.CLOSED, scopeName))
else -> null
}
......@@ -38,4 +40,14 @@ class ProjectIssuesContainerFragment : BaseFragment() {
else -> null
}
}
companion object {
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(scope: String) =
ProjectIssuesContainerFragment().apply {
arguments = Bundle().apply {
putString(ARG_SCOPE_NAME, scope)
}
}
}
}
\ No newline at end of file
......@@ -9,11 +9,11 @@ import kotlinx.android.synthetic.main.layout_zero.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.app.target.TargetHeader
import ru.terrakok.gitlabclient.entity.issue.IssueState
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.extension.showSnackMessage
import ru.terrakok.gitlabclient.extension.visible
import ru.terrakok.gitlabclient.presentation.project.issues.ProjectIssuesPresenter
import ru.terrakok.gitlabclient.presentation.project.issues.ProjectIssuesView
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.global.ZeroViewHolder
import ru.terrakok.gitlabclient.ui.my.TargetsAdapter
......@@ -25,14 +25,15 @@ import toothpick.config.Module
*/
class ProjectIssuesFragment : BaseFragment(), ProjectIssuesView {
override val layoutRes = R.layout.fragment_project_issues
private val scopeName: String? by argument(ARG_SCOPE_NAME)
@InjectPresenter
lateinit var presenter: ProjectIssuesPresenter
@ProvidePresenter
fun providePresenter(): ProjectIssuesPresenter {
val scopeName = "ProjectIssuesScope_${hashCode()}"
val scope = Toothpick.openScopes(DI.PROJECT_FLOW_SCOPE, scopeName)
val subScopeName = "ProjectIssuesScope_${hashCode()}"
val scope = Toothpick.openScopes(scopeName, subScopeName)
scope.installModules(object : Module() {
init {
bind(IssueState::class.java)
......@@ -41,7 +42,7 @@ class ProjectIssuesFragment : BaseFragment(), ProjectIssuesView {
})
return scope.getInstance(ProjectIssuesPresenter::class.java).also {
Toothpick.closeScope(scopeName)
Toothpick.closeScope(subScopeName)
}
}
......@@ -112,11 +113,13 @@ class ProjectIssuesFragment : BaseFragment(), ProjectIssuesView {
companion object {
private const val ARG_ISSUE_STATE = "arg issue state"
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(issueState: IssueState) =
fun create(issueState: IssueState, scope: String) =
ProjectIssuesFragment().apply {
arguments = Bundle().apply {
putSerializable(ARG_ISSUE_STATE, issueState)
putString(ARG_SCOPE_NAME, scope)
}
}
}
......
......@@ -6,6 +6,7 @@ import kotlinx.android.synthetic.main.fragment_my_merge_requests_container.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestState
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.ui.global.BaseFragment
/**
......@@ -13,6 +14,7 @@ import ru.terrakok.gitlabclient.ui.global.BaseFragment
*/
class ProjectMergeRequestsContainerFragment : BaseFragment() {
override val layoutRes = R.layout.fragment_project_merge_requests_container
private val scopeName: String? by argument(ARG_SCOPE_NAME)
private val adapter: ProjectMergeRequestsPagesAdapter by lazy { ProjectMergeRequestsPagesAdapter() }
......@@ -26,9 +28,9 @@ class ProjectMergeRequestsContainerFragment : BaseFragment() {
FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int) = when (position) {
0 -> Screens.createFragment(Screens.PROJECT_MR_SCREEN, MergeRequestState.OPENED)
1 -> Screens.createFragment(Screens.PROJECT_MR_SCREEN, MergeRequestState.MERGED)
2 -> Screens.createFragment(Screens.PROJECT_MR_SCREEN, MergeRequestState.CLOSED)
0 -> Screens.createFragment(Screens.PROJECT_MR_SCREEN, Pair(MergeRequestState.OPENED, scopeName))
1 -> Screens.createFragment(Screens.PROJECT_MR_SCREEN, Pair(MergeRequestState.MERGED, scopeName))
2 -> Screens.createFragment(Screens.PROJECT_MR_SCREEN, Pair(MergeRequestState.CLOSED, scopeName))
else -> null
}
......@@ -41,4 +43,14 @@ class ProjectMergeRequestsContainerFragment : BaseFragment() {
else -> null
}
}
companion object {
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(scope: String) =
ProjectMergeRequestsContainerFragment().apply {
arguments = Bundle().apply {
putString(ARG_SCOPE_NAME, scope)
}
}
}
}
\ No newline at end of file
......@@ -9,11 +9,11 @@ import kotlinx.android.synthetic.main.layout_zero.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.app.target.TargetHeader
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestState
import ru.terrakok.gitlabclient.extension.argument
import ru.terrakok.gitlabclient.extension.showSnackMessage
import ru.terrakok.gitlabclient.extension.visible
import ru.terrakok.gitlabclient.presentation.project.mergerequest.ProjectMergeRequestsPresenter
import ru.terrakok.gitlabclient.presentation.project.mergerequest.ProjectMergeRequestsView
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.global.ZeroViewHolder
import ru.terrakok.gitlabclient.ui.my.TargetsAdapter
......@@ -25,14 +25,15 @@ import toothpick.config.Module
*/
class ProjectMergeRequestsFragment : BaseFragment(), ProjectMergeRequestsView {
override val layoutRes = R.layout.fragment_my_merge_requests
private val scopeName: String? by argument(ARG_SCOPE_NAME)
@InjectPresenter
lateinit var presenter: ProjectMergeRequestsPresenter
@ProvidePresenter
fun providePresenter(): ProjectMergeRequestsPresenter {
val scopeName = "ProjectMergeRequestsScope_${hashCode()}"
val scope = Toothpick.openScopes(DI.PROJECT_FLOW_SCOPE, scopeName)
val subScopeName = "ProjectMergeRequestsScope_${hashCode()}"
val scope = Toothpick.openScopes(scopeName, subScopeName)
scope.installModules(object : Module() {
init {
bind(MergeRequestState::class.java)
......@@ -41,7 +42,7 @@ class ProjectMergeRequestsFragment : BaseFragment(), ProjectMergeRequestsView {
})
return scope.getInstance(ProjectMergeRequestsPresenter::class.java).also {
Toothpick.closeScope(scopeName)
Toothpick.closeScope(subScopeName)
}
}
......@@ -112,11 +113,13 @@ class ProjectMergeRequestsFragment : BaseFragment(), ProjectMergeRequestsView {
companion object {
private const val ARG_MERGE_REQUEST_STATE = "arg merge request state"
private const val ARG_SCOPE_NAME = "arg_scope_name"
fun create(mergeRequestState: MergeRequestState) =
fun create(mergeRequestState: MergeRequestState, scope: String) =
ProjectMergeRequestsFragment().apply {
arguments = Bundle().apply {
putSerializable(ARG_MERGE_REQUEST_STATE, mergeRequestState)
putString(ARG_SCOPE_NAME, scope)
}
}
}
......
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