Commit 2f19b07c authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Merge branch 'feature/user_activity_badges_model' into 'feature/user_activity_badges'

Implement user assigned todo/issue/mergerequest count model.

See merge request terrakok/gitlab-client!174
parents a56ca1f6 fcba0ad4
......@@ -19,7 +19,7 @@ import ru.terrakok.gitlabclient.model.interactor.issue.IssueInteractor
import ru.terrakok.gitlabclient.model.interactor.mergerequest.MergeRequestInteractor
import ru.terrakok.gitlabclient.model.interactor.milestone.MilestoneInteractor
import ru.terrakok.gitlabclient.model.interactor.project.ProjectInteractor
import ru.terrakok.gitlabclient.model.interactor.todo.TodoListInteractor
import ru.terrakok.gitlabclient.model.interactor.todo.TodoInteractor
import ru.terrakok.gitlabclient.model.interactor.user.UserInteractor
import ru.terrakok.gitlabclient.model.repository.event.EventRepository
import ru.terrakok.gitlabclient.model.repository.issue.IssueRepository
......@@ -99,6 +99,6 @@ class ServerModule(userAccount: UserAccount?) : Module() {
//Todos
bind(TodoRepository::class.java)
bind(TodoListInteractor::class.java)
bind(TodoInteractor::class.java)
}
}
\ No newline at end of file
......@@ -25,6 +25,7 @@ import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.google.android.material.snackbar.Snackbar
import retrofit2.adapter.rxjava2.Result
import ru.terrakok.cicerone.Navigator
import ru.terrakok.cicerone.android.support.SupportAppScreen
import ru.terrakok.cicerone.commands.BackTo
......@@ -206,4 +207,8 @@ fun Any.objectScopeName() = "${javaClass.simpleName}_${hashCode()}"
fun View.setBackgroundTintByColor(@ColorInt color: Int) {
val wrappedDrawable = DrawableCompat.wrap(background)
DrawableCompat.setTint(wrappedDrawable.mutate(), color)
}
fun Result<*>.getXTotalHeader(): Int {
return if (!isError) response().headers().get("X-Total")?.toInt() ?: 0 else 0
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package ru.terrakok.gitlabclient.model.data.server
import io.reactivex.Completable
import io.reactivex.Single
import org.threeten.bp.LocalDateTime
import retrofit2.adapter.rxjava2.Result
import retrofit2.http.*
import ru.terrakok.gitlabclient.entity.*
import ru.terrakok.gitlabclient.entity.event.Event
......@@ -373,4 +374,24 @@ interface GitlabApi {
@Path("project_id") projectId: Long,
@Path("label_id") labelId: Long
): Single<Label>
@HEAD("$API_PATH/merge_requests")
fun getMyAssignedMergeRequestHeaders(
@Query("scope") scope: MergeRequestScope = MergeRequestScope.ASSIGNED_TO_ME,
@Query("state") state: MergeRequestState = MergeRequestState.OPENED,
@Query("per_page") pageSize: Int = 1
): Single<Result<Unit>>
@HEAD("$API_PATH/issues")
fun getMyAssignedIssueHeaders(
@Query("scope") scope: IssueScope = IssueScope.ASSIGNED_BY_ME,
@Query("state") state: IssueState = IssueState.OPENED,
@Query("per_page") pageSize: Int = 1
): Single<Result<Unit>>
@HEAD("$API_PATH/todos")
fun getMyAssignedTodoHeaders(
@Query("state") state: TodoState = TodoState.PENDING,
@Query("per_page") pageSize: Int = 1
): Single<Result<Unit>>
}
\ No newline at end of file
......@@ -59,4 +59,6 @@ class IssueInteractor @Inject constructor(
issueId: Long,
body: String
) = issueRepository.createIssueNote(projectId, issueId, body)
fun getMyAssignedIssueCount() = issueRepository.getMyAssignedIssueCount()
}
\ No newline at end of file
......@@ -66,4 +66,6 @@ class MergeRequestInteractor @Inject constructor(
projectId: Long,
mergeRequestId: Long
) = mergeRequestRepository.getMergeRequestChanges(projectId, mergeRequestId)
fun getMyAssignedMergeRequestCount() = mergeRequestRepository.getMyAssignedMergeRequestCount()
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ import javax.inject.Inject
/**
* @author Eugene Shapovalov (CraggyHaggy). Date: 21.09.17
*/
class TodoListInteractor @Inject constructor(
class TodoInteractor @Inject constructor(
private val todoRepository: TodoRepository,
private val profileRepository: ProfileRepository
) {
......@@ -24,4 +24,6 @@ class TodoListInteractor @Inject constructor(
page = page
)
}
fun getMyAssignedTodoCount() = todoRepository.getMyAssignedTodoCount()
}
\ No newline at end of file
......@@ -14,8 +14,10 @@ import ru.terrakok.gitlabclient.entity.event.EventAction
import ru.terrakok.gitlabclient.entity.issue.Issue
import ru.terrakok.gitlabclient.entity.issue.IssueScope
import ru.terrakok.gitlabclient.entity.issue.IssueState
import ru.terrakok.gitlabclient.extension.getXTotalHeader
import ru.terrakok.gitlabclient.model.data.server.GitlabApi
import ru.terrakok.gitlabclient.model.data.server.MarkDownUrlResolver
import ru.terrakok.gitlabclient.model.repository.session.SessionRepository
import ru.terrakok.gitlabclient.model.system.SchedulersProvider
import javax.inject.Inject
......@@ -26,7 +28,8 @@ class IssueRepository @Inject constructor(
private val api: GitlabApi,
private val schedulers: SchedulersProvider,
@DefaultPageSize private val defaultPageSizeWrapper: PrimitiveWrapper<Int>,
private val markDownUrlResolver: MarkDownUrlResolver
private val markDownUrlResolver: MarkDownUrlResolver,
private val sessionRepository: SessionRepository
) {
private val defaultPageSize = defaultPageSizeWrapper.value
......@@ -206,4 +209,10 @@ class IssueRepository @Inject constructor(
.getMilestoneIssues(projectId, milestoneId, page, pageSize)
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
fun getMyAssignedIssueCount(): Single<Int> =
api.getMyAssignedIssueHeaders()
.map { it.getXTotalHeader() }
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequest
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestScope
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestState
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestViewType
import ru.terrakok.gitlabclient.extension.getXTotalHeader
import ru.terrakok.gitlabclient.model.data.server.GitlabApi
import ru.terrakok.gitlabclient.model.data.server.MarkDownUrlResolver
import ru.terrakok.gitlabclient.model.system.SchedulersProvider
......@@ -254,4 +255,10 @@ class MergeRequestRepository @Inject constructor(
.getMilestoneMergeRequests(projectId, milestoneId, page, pageSize)
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
fun getMyAssignedMergeRequestCount(): Single<Int> =
api.getMyAssignedMergeRequestHeaders()
.map { it.getXTotalHeader() }
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
}
\ No newline at end of file
package ru.terrakok.gitlabclient.model.repository.todo
import io.reactivex.Single
import ru.terrakok.gitlabclient.di.DefaultPageSize
import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.entity.Assignee
......@@ -10,6 +11,7 @@ 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
import ru.terrakok.gitlabclient.extension.getXTotalHeader
import ru.terrakok.gitlabclient.model.data.server.GitlabApi
import ru.terrakok.gitlabclient.model.system.SchedulersProvider
import javax.inject.Inject
......@@ -93,4 +95,10 @@ class TodoRepository @Inject constructor(
fun markPendingTodoAsDone(id: Int) = api.markPendingTodoAsDone(id)
fun markAllPendingTodosAsDone() = api.markAllPendingTodosAsDone()
fun getMyAssignedTodoCount(): Single<Int> =
api.getMyAssignedTodoHeaders()
.map { it.getXTotalHeader() }
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ import ru.terrakok.gitlabclient.di.PrimitiveWrapper
import ru.terrakok.gitlabclient.di.TodoListPendingState
import ru.terrakok.gitlabclient.entity.app.target.TargetHeader
import ru.terrakok.gitlabclient.extension.openInfo
import ru.terrakok.gitlabclient.model.interactor.todo.TodoListInteractor
import ru.terrakok.gitlabclient.model.interactor.todo.TodoInteractor
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.presentation.global.BasePresenter
import ru.terrakok.gitlabclient.presentation.global.ErrorHandler
......@@ -21,7 +21,7 @@ import javax.inject.Inject
@InjectViewState
class MyTodosPresenter @Inject constructor(
@TodoListPendingState private val pendingStateWrapper: PrimitiveWrapper<Boolean>,
private val todoListInteractor: TodoListInteractor,
private val todoInteractor: TodoInteractor,
private val mdConverter: MarkDownConverter,
private val errorHandler: ErrorHandler,
private val router: FlowRouter
......@@ -37,7 +37,7 @@ class MyTodosPresenter @Inject constructor(
private val paginator = Paginator(
{
todoListInteractor.getMyTodos(isPending, it)
todoInteractor.getMyTodos(isPending, it)
.flattenAsObservable { it }
.concatMap { item ->
when (item) {
......
......@@ -13,9 +13,9 @@ import ru.terrakok.gitlabclient.model.repository.todo.TodoRepository
/**
* @author Eugene Shapovalov (CraggyHaggy). Date: 21.09.17
*/
class TodoListInteractorTest {
class TodoInteractorTest {
private lateinit var interactor: TodoListInteractor
private lateinit var interactor: TodoInteractor
private lateinit var todoRepository: TodoRepository
private lateinit var profileRepository: ProfileRepository
......@@ -27,7 +27,7 @@ class TodoListInteractorTest {
fun setUp() {
todoRepository = mock()
profileRepository = mock()
interactor = TodoListInteractor(todoRepository, profileRepository)
interactor = TodoInteractor(todoRepository, profileRepository)
}
@Test
......
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