...
 
Commits (9)
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
package ru.terrakok.gitlabclient.entity.app
import ru.terrakok.gitlabclient.entity.Commit
import ru.terrakok.gitlabclient.entity.Author
import ru.terrakok.gitlabclient.entity.commit.Commit
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 20.10.18.
*/
data class CommitWithAvatarUrl(val commit: Commit, val authorAvatarUrl: String?)
\ No newline at end of file
data class CommitWithAuthor(val commit: Commit, val author: Author?)
\ No newline at end of file
package ru.terrakok.gitlabclient.entity
package ru.terrakok.gitlabclient.entity.commit
import com.google.gson.annotations.SerializedName
import org.threeten.bp.LocalDateTime
......
package ru.terrakok.gitlabclient.entity.commit
import com.google.gson.annotations.SerializedName
data class CommitDiff(
@SerializedName("old_path") val oldPath: String,
@SerializedName("new_path") val newPath: String,
@SerializedName("a_mode") val aMode: String,
@SerializedName("b_mode") val bMode: String,
@SerializedName("new_file") val newFile: Boolean,
@SerializedName("renamed_file") val renamedFile: Boolean,
@SerializedName("deleted_file") val deletedFile: Boolean,
@SerializedName("diff") val diff: String
)
\ No newline at end of file
......@@ -5,6 +5,8 @@ import io.reactivex.Single
import org.threeten.bp.LocalDateTime
import retrofit2.http.*
import ru.terrakok.gitlabclient.entity.*
import ru.terrakok.gitlabclient.entity.commit.Commit
import ru.terrakok.gitlabclient.entity.commit.CommitDiff
import ru.terrakok.gitlabclient.entity.event.Event
import ru.terrakok.gitlabclient.entity.event.EventAction
import ru.terrakok.gitlabclient.entity.event.EventTarget
......@@ -19,7 +21,6 @@ import ru.terrakok.gitlabclient.entity.target.TargetType
import ru.terrakok.gitlabclient.entity.todo.Todo
import ru.terrakok.gitlabclient.entity.todo.TodoAction
import ru.terrakok.gitlabclient.entity.todo.TodoState
/**
* @author Konstantin Tskhovrebov (aka terrakok). Date: 28.03.17
*/
......@@ -261,4 +262,16 @@ interface GitlabApi {
@Path("project_id") projectId: Long,
@Path("merge_request_id") mergeRequestId: Long
): Single<MergeRequest>
@GET("$API_PATH/projects/{project_id}/repository/commits/{sha}/diff")
fun getCommitDiff(
@Path("project_id") projectId: Long,
@Path("sha") commitId: String
): Single<CommitDiff>
@GET("$API_PATH//projects/:id/repository/commits/:sha")
fun getCommit(
@Path("project_id") projectId: Long,
@Path("sha") commitId: String
): Single<Commit>
}
\ No newline at end of file
......@@ -60,5 +60,10 @@ class ProjectInteractor @Inject constructor(
.observeOn(schedulers.ui())
fun getCommitDiff(
projectId: Long,
commitId: String
) = projectRepository.getCommitDiff(projectId, commitId)
class ReadmeNotFound : Exception()
}
\ No newline at end of file
......@@ -5,8 +5,9 @@ import io.reactivex.Single
import io.reactivex.functions.BiFunction
import org.threeten.bp.LocalDateTime
import ru.terrakok.gitlabclient.entity.*
import ru.terrakok.gitlabclient.entity.app.CommitWithAvatarUrl
import ru.terrakok.gitlabclient.entity.app.CommitWithAuthor
import ru.terrakok.gitlabclient.entity.app.target.*
import ru.terrakok.gitlabclient.entity.commit.Commit
import ru.terrakok.gitlabclient.entity.event.EventAction
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequest
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestScope
......@@ -217,11 +218,11 @@ class MergeRequestRepository @Inject constructor(
.zip(
getAllMergeRequestParticipants(projectId, mergeRequestId),
api.getMergeRequestCommits(projectId, mergeRequestId, page, pageSize),
BiFunction<List<Author>, List<Commit>, List<CommitWithAvatarUrl>> { participants, commits ->
BiFunction<List<Author>, List<Commit>, List<CommitWithAuthor>> { participants, commits ->
commits.map { commit ->
CommitWithAvatarUrl(
CommitWithAuthor(
commit,
participants.find { it.name == commit.authorName || it.username == commit.authorName }?.avatarUrl
participants.find { it.name == commit.authorName || it.username == commit.authorName }
)
}
}
......
......@@ -71,4 +71,14 @@ class ProjectRepository @Inject constructor(
.getRepositoryTree(projectId, path, branchName, recursive)
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
fun getCommit(projectId: Long, commitId: String) = api
.getCommit(projectId, commitId)
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
fun getCommitDiff(projectId: Long, commitId: String) = api
.getCommitDiff(projectId, commitId)
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
}
\ No newline at end of file
package ru.terrakok.gitlabclient.presentation.mergerequest.commits
import com.arellomobile.mvp.InjectViewState
import ru.terrakok.gitlabclient.entity.app.CommitWithAvatarUrl
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.entity.app.CommitWithAuthor
import ru.terrakok.gitlabclient.model.interactor.mergerequest.MergeRequestInteractor
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.presentation.global.BasePresenter
import ru.terrakok.gitlabclient.presentation.global.ErrorHandler
import ru.terrakok.gitlabclient.presentation.global.MarkDownConverter
......@@ -21,7 +23,8 @@ class MergeRequestCommitsPresenter @Inject constructor(
@MergeRequestId mrIdWrapper: PrimitiveWrapper<Long>,
private val mrInteractor: MergeRequestInteractor,
private val mdConverter: MarkDownConverter,
private val errorHandler: ErrorHandler
private val errorHandler: ErrorHandler,
private val flowRouter: FlowRouter
) : BasePresenter<MergeRequestCommitsView>() {
private val projectId = projectIdWrapper.value
......@@ -35,7 +38,7 @@ class MergeRequestCommitsPresenter @Inject constructor(
private val paginator = Paginator(
{ page -> mrInteractor.getMergeRequestCommits(projectId, mrId, page) },
object : Paginator.ViewController<CommitWithAvatarUrl> {
object : Paginator.ViewController<CommitWithAuthor> {
override fun showEmptyProgress(show: Boolean) {
viewState.showEmptyProgress(show)
}
......@@ -56,7 +59,7 @@ class MergeRequestCommitsPresenter @Inject constructor(
viewState.showEmptyView(show)
}
override fun showData(show: Boolean, data: List<CommitWithAvatarUrl>) {
override fun showData(show: Boolean, data: List<CommitWithAuthor>) {
viewState.showCommits(show, data)
}
......@@ -73,6 +76,10 @@ class MergeRequestCommitsPresenter @Inject constructor(
fun refreshCommits() = paginator.refresh()
fun loadNextCommitsPage() = paginator.loadNewPage()
fun onUserClicked(userId: Long) {
flowRouter.startFlow(Screens.UserFlow(userId))
}
override fun onDestroy() {
super.onDestroy()
paginator.release()
......
......@@ -4,7 +4,7 @@ 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.app.CommitWithAvatarUrl
import ru.terrakok.gitlabclient.entity.app.CommitWithAuthor
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 20.10.18.
......@@ -17,7 +17,7 @@ interface MergeRequestCommitsView : MvpView {
fun showPageProgress(show: Boolean)
fun showEmptyView(show: Boolean)
fun showEmptyError(show: Boolean, message: String?)
fun showCommits(show: Boolean, commits: List<CommitWithAvatarUrl>)
fun showCommits(show: Boolean, commits: List<CommitWithAuthor>)
@StateStrategyType(OneExecutionStateStrategy::class)
fun showMessage(message: String)
......
......@@ -6,7 +6,7 @@ import android.view.ViewGroup
import com.hannesdorfmann.adapterdelegates3.AdapterDelegate
import kotlinx.android.synthetic.main.item_merge_request_commit.view.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.app.CommitWithAvatarUrl
import ru.terrakok.gitlabclient.entity.app.CommitWithAuthor
import ru.terrakok.gitlabclient.extension.humanTime
import ru.terrakok.gitlabclient.extension.inflate
import ru.terrakok.gitlabclient.extension.loadRoundedImage
......@@ -14,10 +14,12 @@ import ru.terrakok.gitlabclient.extension.loadRoundedImage
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 20.10.18.
*/
class CommitAdapterDelegate : AdapterDelegate<MutableList<Any>>() {
class CommitAdapterDelegate(
private val userClickListener: (Long) -> Unit
) : AdapterDelegate<MutableList<Any>>() {
override fun isForViewType(items: MutableList<Any>, position: Int) =
items[position] is CommitWithAvatarUrl
items[position] is CommitWithAuthor
override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder =
ViewHolder(parent.inflate(R.layout.item_merge_request_commit))
......@@ -27,20 +29,24 @@ class CommitAdapterDelegate : AdapterDelegate<MutableList<Any>>() {
position: Int,
viewHolder: RecyclerView.ViewHolder,
payloads: MutableList<Any>
) = (viewHolder as ViewHolder).bind(items[position] as CommitWithAvatarUrl)
) = (viewHolder as ViewHolder).bind(items[position] as CommitWithAuthor)
private inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
private lateinit var commitWithAvatarUrl: CommitWithAvatarUrl
private lateinit var commitWithAuthor: CommitWithAuthor
fun bind(commitWithAvatarUrl: CommitWithAvatarUrl) {
this.commitWithAvatarUrl = commitWithAvatarUrl
init {
view.avatarImageView.setOnClickListener { commitWithAuthor.author?.id?.let(userClickListener) }
}
fun bind(commitWithAuthor: CommitWithAuthor) {
this.commitWithAuthor = commitWithAuthor
with(itemView) {
avatarImageView.loadRoundedImage(commitWithAvatarUrl.authorAvatarUrl)
titleTextView.text = commitWithAvatarUrl.commit.title
avatarImageView.loadRoundedImage(commitWithAuthor.author?.avatarUrl)
titleTextView.text = commitWithAuthor.commit.title
descriptionTextView.text = String.format(
context.getString(R.string.merge_request_commits_description),
commitWithAvatarUrl.commit.authorName,
commitWithAvatarUrl.commit.authoredDate.humanTime(resources)
commitWithAuthor.commit.authorName,
commitWithAuthor.commit.authoredDate.humanTime(resources)
)
}
}
......
......@@ -3,22 +3,23 @@ package ru.terrakok.gitlabclient.ui.global.list
import android.support.v7.util.DiffUtil
import android.support.v7.widget.RecyclerView
import com.hannesdorfmann.adapterdelegates3.ListDelegationAdapter
import ru.terrakok.gitlabclient.entity.app.CommitWithAvatarUrl
import ru.terrakok.gitlabclient.entity.app.CommitWithAuthor
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 20.10.18.
*/
class TargetCommitsAdapter(
userClickListener: (Long) -> Unit,
private val nextPageListener: () -> Unit
) : ListDelegationAdapter<MutableList<Any>>() {
init {
items = mutableListOf()
delegatesManager.addDelegate(CommitAdapterDelegate())
delegatesManager.addDelegate(CommitAdapterDelegate(userClickListener))
delegatesManager.addDelegate(ProgressAdapterDelegate())
}
fun setData(data: List<CommitWithAvatarUrl>) {
fun setData(data: List<CommitWithAuthor>) {
val oldItems = items.toList()
items.clear()
......@@ -66,7 +67,7 @@ class TargetCommitsAdapter(
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return if (newItem is CommitWithAvatarUrl && oldItem is CommitWithAvatarUrl) {
return if (newItem is CommitWithAuthor && oldItem is CommitWithAuthor) {
newItem.commit.id == oldItem.commit.id
} else {
newItem is ProgressItem && oldItem is ProgressItem
......@@ -77,7 +78,7 @@ class TargetCommitsAdapter(
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return if (newItem is CommitWithAvatarUrl && oldItem is CommitWithAvatarUrl) {
return if (newItem is CommitWithAuthor && oldItem is CommitWithAuthor) {
newItem == oldItem
} else {
true
......
......@@ -7,7 +7,7 @@ import com.arellomobile.mvp.presenter.ProvidePresenter
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.CommitWithAvatarUrl
import ru.terrakok.gitlabclient.entity.app.CommitWithAuthor
import ru.terrakok.gitlabclient.extension.showSnackMessage
import ru.terrakok.gitlabclient.extension.visible
import ru.terrakok.gitlabclient.presentation.mergerequest.commits.MergeRequestCommitsPresenter
......@@ -26,7 +26,12 @@ class MergeRequestCommitsFragment : BaseFragment(), MergeRequestCommitsView {
override val layoutRes = R.layout.fragment_mr_commits
private val adapter by lazy { TargetCommitsAdapter({ presenter.loadNextCommitsPage() }) }
private val adapter by lazy {
TargetCommitsAdapter(
{ presenter.onUserClicked(it) },
{ presenter.loadNextCommitsPage() }
)
}
private var zeroViewHolder: ZeroViewHolder? = null
@InjectPresenter
......@@ -77,7 +82,7 @@ class MergeRequestCommitsFragment : BaseFragment(), MergeRequestCommitsView {
else zeroViewHolder?.hide()
}
override fun showCommits(show: Boolean, commits: List<CommitWithAvatarUrl>) {
override fun showCommits(show: Boolean, commits: List<CommitWithAuthor>) {
recyclerView.visible(show)
postViewAction { adapter.setData(commits) }
}
......