...
 
Commits (2)
......@@ -218,8 +218,8 @@ object Screens {
override fun getFragment() = MergeRequestNotesFragment()
}
object MergeRequestChanges : SupportAppScreen() {
override fun getFragment() = MergeRequestChangesFragment()
object MergeRequestDiffDataList : SupportAppScreen() {
override fun getFragment() = MergeRequestDiffDataListFragment()
}
object MainIssue : SupportAppScreen() {
......
package ru.terrakok.gitlabclient.entity.mergerequest
package ru.terrakok.gitlabclient.entity
import com.google.gson.annotations.SerializedName
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 26.10.18.
*/
data class MergeRequestChange(
data class DiffData(
@SerializedName("old_path") val oldPath: String,
@SerializedName("new_path") val newPath: String,
@SerializedName("a_mode") val aMode: String,
......
......@@ -2,6 +2,7 @@ package ru.terrakok.gitlabclient.entity.mergerequest
import com.google.gson.annotations.SerializedName
import org.threeten.bp.ZonedDateTime
import ru.terrakok.gitlabclient.entity.DiffData
import ru.terrakok.gitlabclient.entity.ShortUser
import ru.terrakok.gitlabclient.entity.TimeStats
import ru.terrakok.gitlabclient.entity.milestone.Milestone
......@@ -41,7 +42,7 @@ data class MergeRequest(
@SerializedName("closed_at") val closedAt: ZonedDateTime?,
@SerializedName("merged_by") val mergedBy: ShortUser?,
@SerializedName("merged_at") val mergedAt: ZonedDateTime?,
@SerializedName("changes") val changes: List<MergeRequestChange>?,
@SerializedName("changes") val diffDataList: List<DiffData>?,
@SerializedName("assignees") val assignees: List<ShortUser>,
@SerializedName("time_stats") val timeStats: TimeStats,
@SerializedName("discussion_locked") val discussionLocked: Boolean
......
......@@ -278,7 +278,7 @@ interface GitlabApi {
): Single<List<ShortUser>>
@GET("$API_PATH/projects/{project_id}/merge_requests/{merge_request_id}/changes")
fun getMergeRequestChanges(
fun getMergeRequestDiffDataList(
@Path("project_id") projectId: Long,
@Path("merge_request_id") mergeRequestId: Long
): Single<MergeRequest>
......
......@@ -62,10 +62,10 @@ class MergeRequestInteractor @Inject constructor(
page: Int
) = mergeRequestRepository.getMergeRequestCommits(projectId, mergeRequestId, page)
fun getMergeRequestChanges(
fun getMergeRequestDiffDataList(
projectId: Long,
mergeRequestId: Long
) = mergeRequestRepository.getMergeRequestChanges(projectId, mergeRequestId)
) = mergeRequestRepository.getMergeRequestDiffDataList(projectId, mergeRequestId)
fun getMyAssignedMergeRequestCount() = mergeRequestRepository.getMyAssignedMergeRequestCount()
}
\ No newline at end of file
......@@ -252,9 +252,9 @@ class MergeRequestRepository @Inject constructor(
.flatMapIterable { it }
.toList()
fun getMergeRequestChanges(projectId: Long, mergeRequestId: Long) =
api.getMergeRequestChanges(projectId, mergeRequestId)
.map { it.changes ?: arrayListOf() }
fun getMergeRequestDiffDataList(projectId: Long, mergeRequestId: Long) =
api.getMergeRequestDiffDataList(projectId, mergeRequestId)
.map { it.diffDataList ?: arrayListOf() }
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
......
......@@ -5,7 +5,7 @@ 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.entity.mergerequest.MergeRequestChange
import ru.terrakok.gitlabclient.entity.DiffData
import ru.terrakok.gitlabclient.model.interactor.mergerequest.MergeRequestInteractor
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.presentation.global.BasePresenter
......@@ -16,34 +16,34 @@ import javax.inject.Inject
* Created by Konstantin Tskhovrebov (aka @terrakok) on 12.02.18.
*/
@InjectViewState
class MergeRequestChangesPresenter @Inject constructor(
class MergeRequestDiffDataListPresenter @Inject constructor(
@ProjectId projectIdWrapper: PrimitiveWrapper<Long>,
@MergeRequestId mrIdWrapper: PrimitiveWrapper<Long>,
private val mrInteractor: MergeRequestInteractor,
private val errorHandler: ErrorHandler,
private val flowRouter: FlowRouter
) : BasePresenter<MergeRequestChangesView>() {
) : BasePresenter<MergeRequestDiffDataListView>() {
private val projectId = projectIdWrapper.value
private val mrId = mrIdWrapper.value
private val changes = arrayListOf<MergeRequestChange>()
private val diffDataList = arrayListOf<DiffData>()
private var isEmptyError: Boolean = false
override fun onFirstViewAttach() {
super.onFirstViewAttach()
mrInteractor
.getMergeRequestChanges(projectId, mrId)
.getMergeRequestDiffDataList(projectId, mrId)
.doOnSubscribe { viewState.showEmptyProgress(true) }
.doAfterTerminate { viewState.showEmptyProgress(false) }
.subscribe(
{
if (it.isNotEmpty()) {
changes.addAll(it)
viewState.showChanges(true, it)
diffDataList.addAll(it)
viewState.showDiffDataList(true, it)
} else {
viewState.showChanges(false, it)
viewState.showDiffDataList(false, it)
viewState.showEmptyView(true)
}
},
......@@ -55,18 +55,18 @@ class MergeRequestChangesPresenter @Inject constructor(
.connect()
}
fun refreshChanges() {
fun refreshDiffDataList() {
mrInteractor
.getMergeRequestChanges(projectId, mrId)
.getMergeRequestDiffDataList(projectId, mrId)
.doOnSubscribe {
if (isEmptyError) {
viewState.showEmptyError(false, null)
isEmptyError = false
}
if (changes.isEmpty()) {
if (diffDataList.isEmpty()) {
viewState.showEmptyView(false)
}
if (changes.isNotEmpty()) {
if (diffDataList.isNotEmpty()) {
viewState.showRefreshProgress(true)
} else {
viewState.showEmptyProgress(true)
......@@ -74,22 +74,22 @@ class MergeRequestChangesPresenter @Inject constructor(
}
.subscribe(
{
if (changes.isNotEmpty()) {
if (diffDataList.isNotEmpty()) {
viewState.showRefreshProgress(false)
} else {
viewState.showEmptyProgress(false)
}
changes.clear()
diffDataList.clear()
if (it.isNotEmpty()) {
changes.addAll(it)
viewState.showChanges(true, it)
diffDataList.addAll(it)
viewState.showDiffDataList(true, it)
} else {
viewState.showChanges(false, it)
viewState.showDiffDataList(false, it)
viewState.showEmptyView(true)
}
},
{
if (changes.isNotEmpty()) {
if (diffDataList.isNotEmpty()) {
viewState.showRefreshProgress(false)
} else {
viewState.showEmptyProgress(false)
......@@ -97,7 +97,7 @@ class MergeRequestChangesPresenter @Inject constructor(
errorHandler.proceed(
it,
{
if (changes.isNotEmpty()) {
if (diffDataList.isNotEmpty()) {
viewState.showMessage(it)
} else {
isEmptyError = true
......@@ -110,7 +110,7 @@ class MergeRequestChangesPresenter @Inject constructor(
.connect()
}
fun onMergeRequestChangeClick(item: MergeRequestChange) {
fun onMergeRequestDiffDataClicked(item: DiffData) {
mrInteractor.getMergeRequest(projectId, mrId)
.doOnSubscribe { viewState.showFullscreenProgress(true) }
.doAfterTerminate { viewState.showFullscreenProgress(false) }
......
......@@ -4,19 +4,19 @@ 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.mergerequest.MergeRequestChange
import ru.terrakok.gitlabclient.entity.DiffData
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 26.10.18.
*/
@StateStrategyType(AddToEndSingleStrategy::class)
interface MergeRequestChangesView : MvpView {
interface MergeRequestDiffDataListView : MvpView {
fun showRefreshProgress(show: Boolean)
fun showEmptyProgress(show: Boolean)
fun showEmptyView(show: Boolean)
fun showEmptyError(show: Boolean, message: String?)
fun showChanges(show: Boolean, changes: List<MergeRequestChange>)
fun showDiffDataList(show: Boolean, diffDataList: List<DiffData>)
@StateStrategyType(OneExecutionStateStrategy::class)
fun showMessage(message: String)
......
......@@ -4,26 +4,26 @@ import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.hannesdorfmann.adapterdelegates4.AdapterDelegate
import kotlinx.android.synthetic.main.item_merge_request_change.view.*
import kotlinx.android.synthetic.main.item_diff_data.view.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestChange
import ru.terrakok.gitlabclient.entity.DiffData
import ru.terrakok.gitlabclient.extension.extractFileNameFromPath
import ru.terrakok.gitlabclient.extension.inflate
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 26.10.18.
*/
class MergeRequestChangeAdapterDelegate(
private val clickListener: (MergeRequestChange) -> Unit
) : AdapterDelegate<MutableList<MergeRequestChange>>() {
class DiffDataAdapterDelegate(
private val clickListener: (DiffData) -> Unit
) : AdapterDelegate<MutableList<DiffData>>() {
override fun isForViewType(items: MutableList<MergeRequestChange>, position: Int) = true
override fun isForViewType(items: MutableList<DiffData>, position: Int) = true
override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder =
ViewHolder(parent.inflate(R.layout.item_merge_request_change))
ViewHolder(parent.inflate(R.layout.item_diff_data))
override fun onBindViewHolder(
items: MutableList<MergeRequestChange>,
items: MutableList<DiffData>,
position: Int,
viewHolder: RecyclerView.ViewHolder,
payloads: MutableList<Any>
......@@ -35,38 +35,38 @@ class MergeRequestChangeAdapterDelegate(
}
private inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
private lateinit var item: MergeRequestChange
private lateinit var item: DiffData
init {
view.setOnClickListener { clickListener(item) }
}
fun bind(item: MergeRequestChange) {
fun bind(item: DiffData) {
this.item = item
with(itemView) {
changePath.text = item.newPath
changeIcon.setImageResource(
diffDataPath.text = item.newPath
diffDataIcon.setImageResource(
when {
item.newFile -> R.drawable.ic_file_added
item.deletedFile -> R.drawable.ic_file_deleted
else -> R.drawable.ic_file_changed
}
)
changeFileName.text = item.newPath.extractFileNameFromPath()
gitDiffView.setGitDiffText(item.diff)
changeAddedCount.text = context.getString(
R.string.merge_request_changes_added_count,
gitDiffView.getAddedLineCount()
diffDataFileName.text = item.newPath.extractFileNameFromPath()
diffDataDiffView.setGitDiffText(item.diff)
diffDataAddedCount.text = context.getString(
R.string.item_diff_data_added_count,
diffDataDiffView.getAddedLineCount()
)
changeDeletedCount.text = context.getString(
R.string.merge_request_changes_deleted_count,
gitDiffView.getDeletedLineCount()
diffDataDeletedCount.text = context.getString(
R.string.item_diff_data_deleted_count,
diffDataDiffView.getDeletedLineCount()
)
}
}
fun recycle() {
itemView.gitDiffView.release()
itemView.diffDataDiffView.release()
}
}
}
\ No newline at end of file
......@@ -2,22 +2,22 @@ package ru.terrakok.gitlabclient.ui.mergerequest
import androidx.recyclerview.widget.DiffUtil
import com.hannesdorfmann.adapterdelegates4.ListDelegationAdapter
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestChange
import ru.terrakok.gitlabclient.ui.global.list.MergeRequestChangeAdapterDelegate
import ru.terrakok.gitlabclient.entity.DiffData
import ru.terrakok.gitlabclient.ui.global.list.DiffDataAdapterDelegate
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 26.10.18.
*/
class MergeRequestChangeAdapter(
clickListener: (MergeRequestChange) -> Unit
) : ListDelegationAdapter<MutableList<MergeRequestChange>>() {
class DiffDataListAdapter(
clickListener: (DiffData) -> Unit
) : ListDelegationAdapter<MutableList<DiffData>>() {
init {
items = mutableListOf()
delegatesManager.addDelegate(MergeRequestChangeAdapterDelegate(clickListener))
delegatesManager.addDelegate(DiffDataAdapterDelegate(clickListener))
}
fun setData(data: List<MergeRequestChange>) {
fun setData(data: List<DiffData>) {
val oldItems = items.toList()
items.clear()
......@@ -29,8 +29,8 @@ class MergeRequestChangeAdapter(
}
private inner class DiffCallback(
private val newItems: List<MergeRequestChange>,
private val oldItems: List<MergeRequestChange>
private val newItems: List<DiffData>,
private val oldItems: List<DiffData>
) : DiffUtil.Callback() {
override fun getOldListSize() = oldItems.size
......
......@@ -67,7 +67,7 @@ class MainMergeRequestFragment : BaseFragment(), MergeRequestView {
TAB_INFO -> Screens.MergeRequestInfo.fragment
TAB_COMMITS -> Screens.MergeRequestCommits.fragment
TAB_NOTES -> Screens.MergeRequestNotes.fragment
else -> Screens.MergeRequestChanges.fragment
else -> Screens.MergeRequestDiffDataList.fragment
}
override fun getCount() = 5
......@@ -77,7 +77,7 @@ class MainMergeRequestFragment : BaseFragment(), MergeRequestView {
TAB_INFO -> getString(R.string.merge_request_info_tab)
TAB_COMMITS -> getString(R.string.merge_request_commits_tab)
TAB_NOTES -> getString(R.string.merge_request_discussion_tab)
TAB_CHANGES -> getString(R.string.merge_request_changes_tab)
TAB_DIFF_DATA -> getString(R.string.merge_request_changes_tab)
else -> null
}
}
......@@ -87,6 +87,6 @@ class MainMergeRequestFragment : BaseFragment(), MergeRequestView {
private const val TAB_INFO = 1
private const val TAB_COMMITS = 2
private const val TAB_NOTES = 3
private const val TAB_CHANGES = 4
private const val TAB_DIFF_DATA = 4
}
}
\ No newline at end of file
......@@ -6,29 +6,29 @@ import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import kotlinx.android.synthetic.main.layout_base_list.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestChange
import ru.terrakok.gitlabclient.entity.DiffData
import ru.terrakok.gitlabclient.extension.showSnackMessage
import ru.terrakok.gitlabclient.extension.visible
import ru.terrakok.gitlabclient.presentation.mergerequest.changes.MergeRequestChangesPresenter
import ru.terrakok.gitlabclient.presentation.mergerequest.changes.MergeRequestChangesView
import ru.terrakok.gitlabclient.presentation.mergerequest.changes.MergeRequestDiffDataListPresenter
import ru.terrakok.gitlabclient.presentation.mergerequest.changes.MergeRequestDiffDataListView
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.global.list.SimpleDividerDecorator
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 25.10.18.
*/
class MergeRequestChangesFragment : BaseFragment(), MergeRequestChangesView {
class MergeRequestDiffDataListFragment : BaseFragment(), MergeRequestDiffDataListView {
override val layoutRes = R.layout.fragment_mr_changes
override val layoutRes = R.layout.fragment_mr_diff_data_list
private val adapter by lazy { MergeRequestChangeAdapter({ presenter.onMergeRequestChangeClick(it) }) }
private val adapter by lazy { DiffDataListAdapter({ presenter.onMergeRequestDiffDataClicked(it) }) }
@InjectPresenter
lateinit var presenter: MergeRequestChangesPresenter
lateinit var presenter: MergeRequestDiffDataListPresenter
@ProvidePresenter
fun providePresenter() =
scope.getInstance(MergeRequestChangesPresenter::class.java)
scope.getInstance(MergeRequestDiffDataListPresenter::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
......@@ -37,11 +37,11 @@ class MergeRequestChangesFragment : BaseFragment(), MergeRequestChangesView {
setHasFixedSize(true)
layoutManager = LinearLayoutManager(context)
addItemDecoration(SimpleDividerDecorator(context))
adapter = this@MergeRequestChangesFragment.adapter
adapter = this@MergeRequestDiffDataListFragment.adapter
}
swipeToRefresh.setOnRefreshListener { presenter.refreshChanges() }
emptyView.setRefreshListener { presenter.refreshChanges() }
swipeToRefresh.setOnRefreshListener { presenter.refreshDiffDataList() }
emptyView.setRefreshListener { presenter.refreshDiffDataList() }
}
override fun showRefreshProgress(show: Boolean) {
......@@ -64,9 +64,9 @@ class MergeRequestChangesFragment : BaseFragment(), MergeRequestChangesView {
emptyView.apply { if (show) showEmptyError(message) else hide() }
}
override fun showChanges(show: Boolean, changes: List<MergeRequestChange>) {
override fun showDiffDataList(show: Boolean, diffDataList: List<DiffData>) {
recyclerView.visible(show)
postViewAction { adapter.setData(changes) }
postViewAction { adapter.setData(diffDataList) }
}
override fun showMessage(message: String) {
......
......@@ -9,7 +9,7 @@
android:paddingBottom="20dp">
<TextView
android:id="@+id/changePath"
android:id="@+id/diffDataPath"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
......@@ -23,19 +23,19 @@
tools:text="…gitlabclient / model / interactor / issue" />
<ImageView
android:id="@+id/changeIcon"
android:id="@+id/diffDataIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginTop="4dp"
app:layout_constraintEnd_toStartOf="@id/changeFileName"
app:layout_constraintEnd_toStartOf="@id/diffDataFileName"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="@id/changePath"
app:layout_constraintTop_toTopOf="@id/changeFileName"
app:layout_constraintStart_toStartOf="@id/diffDataPath"
app:layout_constraintTop_toTopOf="@id/diffDataFileName"
tools:src="@drawable/ic_file_changed" />
<TextView
android:id="@+id/changeFileName"
android:id="@+id/diffDataFileName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
......@@ -43,44 +43,44 @@
android:singleLine="true"
android:layout_marginTop="16dp"
android:textAppearance="@style/TextTitle"
app:layout_constraintEnd_toStartOf="@id/changeAddedCount"
app:layout_constraintEnd_toStartOf="@id/diffDataAddedCount"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@id/changeIcon"
app:layout_constraintTop_toBottomOf="@id/changePath"
app:layout_constraintStart_toEndOf="@id/diffDataIcon"
app:layout_constraintTop_toBottomOf="@id/diffDataPath"
tools:text="IssueInteractor" />
<TextView
android:id="@+id/changeAddedCount"
android:id="@+id/diffDataAddedCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="14dp"
android:textAppearance="@style/TextTitle"
android:textColor="@color/green"
app:layout_constraintEnd_toStartOf="@id/changeDeletedCount"
app:layout_constraintStart_toEndOf="@id/changeFileName"
app:layout_constraintTop_toTopOf="@id/changeFileName"
app:layout_constraintEnd_toStartOf="@id/diffDataDeletedCount"
app:layout_constraintStart_toEndOf="@id/diffDataFileName"
app:layout_constraintTop_toTopOf="@id/diffDataFileName"
tools:text="+5" />
<TextView
android:id="@+id/changeDeletedCount"
android:id="@+id/diffDataDeletedCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:textAppearance="@style/TextTitle"
android:textColor="@color/red"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/changeAddedCount"
app:layout_constraintTop_toTopOf="@id/changeFileName"
app:layout_constraintStart_toEndOf="@id/diffDataAddedCount"
app:layout_constraintTop_toTopOf="@id/diffDataFileName"
tools:text="-2" />
<ru.terrakok.gitlabclient.ui.global.view.custom.GitDiffView
android:id="@+id/gitDiffView"
android:id="@+id/diffDataDiffView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/changeFileName"
app:layout_constraintTop_toBottomOf="@id/diffDataFileName"
tools:text="@@ -0,0 +1,8 @@\n+package ru.terrakok.gitlabclient.entity.app\n+\n+import ru.terrakok.gitlabclient.entity.Commit\n+\n+/**\n+ * Created by Eugene Shapovalov (@CraggyHaggy) on 20.10.18.\n+ */\n+data class CommitWithAvatarUrl(val commit: Commit, val authorAvatarUrl: String?)\n\\ No newline at end of file\n" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -158,9 +158,9 @@
<!--Merge Request Commits screen-->
<string name="merge_request_commits_description" formatted="false">%s authored %s</string>
<!--Merge Request Changes screen-->
<string name="merge_request_changes_added_count" formatted="false">+%d</string>
<string name="merge_request_changes_deleted_count" formatted="false">-%d</string>
<!--Diff data item-->
<string name="item_diff_data_added_count" formatted="false">+%d</string>
<string name="item_diff_data_deleted_count" formatted="false">-%d</string>
<!--Issue Info screen-->
<string name="issue_title" formatted="false">#%d</string>
......