Commit a4ddc6b3 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

added mr info container fragment

parent 353a192d
......@@ -20,7 +20,7 @@ object Screens {
const val USER_INFO_SCREEN = "user info screen"
const val MR_FLOW = "mr flow"
const val MR_INFO_SCREEN = "mr info screen"
const val MR_SCREEN = "mr screen"
const val ISSUE_FLOW = "issue flow"
const val ISSUE_INFO_SCREEN = "issue info screen"
......
package ru.terrakok.gitlabclient.presentation.mergerequest
package ru.terrakok.gitlabclient.presentation.mergerequest.info
import com.arellomobile.mvp.InjectViewState
import io.reactivex.Single
import io.reactivex.functions.BiFunction
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequest
import ru.terrakok.gitlabclient.model.interactor.mergerequest.MergeRequestInteractor
......@@ -23,9 +22,8 @@ private typealias MergeRequestLinker = BiFunction<Pair<MergeRequest, CharSequenc
*/
@InjectViewState
class MergeRequestInfoPresenter @Inject constructor(
@ProjectId private val projectIdWrapper: PrimitiveWrapper<Long>,
@MergeRequestId private val mrIdWrapper: PrimitiveWrapper<Long>,
private val router: Router,
@ProjectId projectIdWrapper: PrimitiveWrapper<Long>,
@MergeRequestId mrIdWrapper: PrimitiveWrapper<Long>,
private val mrInteractor: MergeRequestInteractor,
private val projectInteractor: ProjectInteractor,
private val mdConverter: MarkDownConverter,
......@@ -53,11 +51,9 @@ class MergeRequestInfoPresenter @Inject constructor(
.doOnSubscribe { viewState.showProgress(true) }
.doAfterTerminate { viewState.showProgress(false) }
.subscribe(
{ viewState.showMergeRequest(it) },
{ viewState.showInfo(it) },
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
)
.connect()
}
fun onBackPressed() = router.exit()
}
\ No newline at end of file
package ru.terrakok.gitlabclient.presentation.mergerequest
package ru.terrakok.gitlabclient.presentation.mergerequest.info
import com.arellomobile.mvp.MvpView
import com.arellomobile.mvp.viewstate.strategy.AddToEndSingleStrategy
......@@ -14,7 +14,7 @@ import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequest
interface MergeRequestInfoView : MvpView {
data class MergeRequestInfo(val mr: MergeRequest, val project: Project, val mdDescription: CharSequence)
fun showMergeRequest(mrInfo: MergeRequestInfo)
fun showInfo(mrInfo: MergeRequestInfo)
fun showProgress(show: Boolean)
@StateStrategyType(OneExecutionStateStrategy::class)
......
package ru.terrakok.gitlabclient.presentation.mergerequest.notes
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.model.interactor.mergerequest.MergeRequestInteractor
import ru.terrakok.gitlabclient.presentation.global.BasePresenter
import ru.terrakok.gitlabclient.presentation.global.ErrorHandler
import ru.terrakok.gitlabclient.presentation.global.MarkDownConverter
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
import ru.terrakok.gitlabclient.toothpick.qualifier.MergeRequestId
import ru.terrakok.gitlabclient.toothpick.qualifier.ProjectId
import javax.inject.Inject
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 12.02.18.
*/
class MergeRequestNotesPresenter @Inject constructor(
@ProjectId projectIdWrapper: PrimitiveWrapper<Long>,
@MergeRequestId mrIdWrapper: PrimitiveWrapper<Long>,
private val router: Router,
private val mrInteractor: MergeRequestInteractor,
private val mdConverter: MarkDownConverter,
private val errorHandler: ErrorHandler
) : BasePresenter<MergeRequestNotesView>() {
private val projectId = projectIdWrapper.value
private val mrId = mrIdWrapper.value
override fun onFirstViewAttach() {
super.onFirstViewAttach()
mrInteractor.getMergeRequestNotes(projectId, mrId)
.toObservable()
.flatMapIterable { it }
.flatMap { note ->
mdConverter.markdownToSpannable(note.body)
.map { MergeRequestNotesView.NoteWithFormattedBody(note, it) }
.toObservable()
}
.toList()
.doOnSubscribe { viewState.showProgress(true) }
.doAfterTerminate { viewState.showProgress(false) }
.subscribe(
{ viewState.showNotes(it) },
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
)
.connect()
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.presentation.mergerequest.notes
import com.arellomobile.mvp.MvpView
import com.arellomobile.mvp.viewstate.strategy.AddToEndSingleStrategy
import com.arellomobile.mvp.viewstate.strategy.OneExecutionStateStrategy
import com.arellomobile.mvp.viewstate.strategy.StateStrategyType
import ru.terrakok.gitlabclient.entity.Note
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 12.02.18.
*/
@StateStrategyType(AddToEndSingleStrategy::class)
interface MergeRequestNotesView : MvpView {
data class NoteWithFormattedBody(val note: Note, val body: CharSequence)
fun showNotes(notes: List<NoteWithFormattedBody>)
fun showProgress(show: Boolean)
@StateStrategyType(OneExecutionStateStrategy::class)
fun showMessage(message: String)
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ class MergeRequestActivity : BaseActivity() {
}
if (savedInstanceState == null) {
navigator.setLaunchScreen(Screens.MR_INFO_SCREEN, null)
navigator.setLaunchScreen(Screens.MR_SCREEN, null)
}
}
......@@ -67,14 +67,14 @@ class MergeRequestActivity : BaseActivity() {
private val navigator = object : FlowNavigator(this, R.id.container) {
override fun createFragment(screenKey: String?, data: Any?) = when(screenKey) {
Screens.MR_INFO_SCREEN -> MergeRequestInfoFragment()
Screens.MR_SCREEN -> MergeRequestFragment()
else -> null
}
}
companion object {
private val ARG_PROJECT_ID = "arg_project_id"
private val ARG_MR_ID = "arg_mr_id"
private const val ARG_PROJECT_ID = "arg_project_id"
private const val ARG_MR_ID = "arg_mr_id"
fun getStartIntent(projectId: Long, mrId: Long, context: Context) =
Intent(context, MergeRequestActivity::class.java).apply {
putExtra(ARG_PROJECT_ID, projectId)
......
package ru.terrakok.gitlabclient.ui.mergerequest
import android.os.Bundle
import android.support.v4.app.FragmentPagerAdapter
import kotlinx.android.synthetic.main.fragment_mr.*
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import toothpick.Toothpick
import javax.inject.Inject
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 14.02.18.
*/
class MergeRequestFragment : BaseFragment(), MergeRequestInfoFragment.ToolbarConfigurator {
override val layoutRes = R.layout.fragment_mr
@Inject
lateinit var router: Router
private val adapter by lazy { MergeRequestPagesAdapter() }
override fun onCreate(savedInstanceState: Bundle?) {
Toothpick.inject(this, Toothpick.openScope(DI.MERGE_REQUEST_SCOPE))
super.onCreate(savedInstanceState)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
toolbar.setNavigationOnClickListener { onBackPressed() }
viewPager.adapter = adapter
}
override fun onBackPressed() {
super.onBackPressed()
router.exit()
}
override fun setTitle(title: String, subTitle: String) {
toolbar.title = title
toolbar.subtitle = subTitle
}
private inner class MergeRequestPagesAdapter : FragmentPagerAdapter(childFragmentManager) {
override fun getItem(position: Int) = when (position) {
0 -> MergeRequestInfoFragment()
1 -> MergeRequestInfoFragment()
else -> null
}
override fun getCount() = 2
override fun getPageTitle(position: Int) = when (position) {
0 -> getString(R.string.merge_request_info_tab)
1 -> getString(R.string.merge_request_discussion_tab)
else -> null
}
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.ui.mergerequest
import android.os.Bundle
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import kotlinx.android.synthetic.main.fragment_mr_info.*
......@@ -10,8 +9,8 @@ import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestState
import ru.terrakok.gitlabclient.extension.color
import ru.terrakok.gitlabclient.extension.humanTime
import ru.terrakok.gitlabclient.extension.loadRoundedImage
import ru.terrakok.gitlabclient.presentation.mergerequest.MergeRequestInfoPresenter
import ru.terrakok.gitlabclient.presentation.mergerequest.MergeRequestInfoView
import ru.terrakok.gitlabclient.presentation.mergerequest.info.MergeRequestInfoPresenter
import ru.terrakok.gitlabclient.presentation.mergerequest.info.MergeRequestInfoView
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import toothpick.Toothpick
......@@ -31,17 +30,13 @@ class MergeRequestInfoFragment : BaseFragment(), MergeRequestInfoView {
Toothpick.openScope(DI.MERGE_REQUEST_SCOPE)
.getInstance(MergeRequestInfoPresenter::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
toolbar.setNavigationOnClickListener { presenter.onBackPressed() }
}
override fun showMergeRequest(mrInfo: MergeRequestInfoView.MergeRequestInfo) {
override fun showInfo(mrInfo: MergeRequestInfoView.MergeRequestInfo) {
val mergeRequest = mrInfo.mr
val project = mrInfo.project
toolbar.title = "!${mergeRequest.iid}"
toolbar.subtitle = project.name
(parentFragment as? ToolbarConfigurator)?.let { toolbarConfigurator ->
toolbarConfigurator.setTitle("!${mergeRequest.iid}", mrInfo.project.nameWithNamespace)
}
titleTextView.text = mergeRequest.title
stateImageView.setImageResource(R.drawable.circle)
// TODO: merge request info (Display action user name for the MERGED/CLOSED states).
......@@ -77,8 +72,7 @@ class MergeRequestInfoFragment : BaseFragment(), MergeRequestInfoView {
showSnackMessage(message)
}
override fun onBackPressed() {
presenter.onBackPressed()
interface ToolbarConfigurator {
fun setTitle(title: String, subTitle: String)
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:elevation="0dp"
app:navigationIcon="@drawable/ic_arrow_back_24dp"
tools:subtitle="GitFox"
tools:title="!56"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
style="@style/ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v4.view.ViewPager>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:navigationIcon="@drawable/ic_arrow_back_24dp"
tools:subtitle="GitFox"
tools:title="!56"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/avatarImageView"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/default_img"/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/titleTextView"
fontPath="@string/font_main_medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:textColor="@color/primary_text"
android:textSize="18sp"
app:layout_constraintLeft_toRightOf="@id/avatarImageView"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/avatarImageView"
tools:text="MergeRequest title"/>
<ImageView
android:id="@+id/avatarImageView"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/default_img"/>
<ImageView
android:id="@+id/stateImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginTop="6dp"
app:layout_constraintStart_toStartOf="@id/titleTextView"
app:layout_constraintTop_toBottomOf="@id/titleTextView"
tools:src="@drawable/circle"/>
<TextView
android:id="@+id/titleTextView"
fontPath="@string/font_main_medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:textColor="@color/primary_text"
android:textSize="18sp"
app:layout_constraintLeft_toRightOf="@id/avatarImageView"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/avatarImageView"
tools:text="MergeRequest title"/>
<TextView
android:id="@+id/subtitleTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:textColor="@color/secondary_text"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@id/stateImageView"
app:layout_constraintTop_toBottomOf="@id/titleTextView"
tools:text="Opened by CraggyHaggy 3d ago"/>
<ImageView
android:id="@+id/stateImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginTop="6dp"
app:layout_constraintStart_toStartOf="@id/titleTextView"
app:layout_constraintTop_toBottomOf="@id/titleTextView"
tools:src="@drawable/circle"/>
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="@dimen/divider_size"
android:layout_marginTop="16dp"
android:background="@color/divider"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/subtitleTextView"/>
<TextView
android:id="@+id/subtitleTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:textColor="@color/secondary_text"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toEndOf="@id/stateImageView"
app:layout_constraintTop_toBottomOf="@id/titleTextView"
tools:text="Opened by CraggyHaggy 3d ago"/>
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:linksClickable="true"
android:padding="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider"/>
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="@dimen/divider_size"
android:layout_marginTop="16dp"
android:background="@color/divider"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/subtitleTextView"/>
</android.support.constraint.ConstraintLayout>
<TextView
android:id="@+id/descriptionTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:linksClickable="true"
android:padding="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider"/>
</ScrollView>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
\ No newline at end of file
</ScrollView>
\ No newline at end of file
......@@ -140,6 +140,8 @@
<string name="todo_action_directly_addressed">directly addressed</string>
<!--Merge Request Info screen-->
<string name="merge_request_info_tab">Details</string>
<string name="merge_request_discussion_tab">Discussion</string>
<string name="merge_request_info_subtitle" formatted="false">%s by %s %s</string>
<!--Issue Info screen-->
......
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