Commit 19222afc authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Merge branch 'feature/project_files_tab_ux_fix' into 'feature/project_files_tab'

Implement empty state for project files screen.

See merge request !150
parents aa8ced2c 63d004a0
......@@ -3,11 +3,13 @@ package ru.terrakok.gitlabclient.presentation.project.files
import com.arellomobile.mvp.InjectViewState
import io.reactivex.Single
import io.reactivex.functions.BiFunction
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.Branch
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.RepositoryTreeNodeType
import ru.terrakok.gitlabclient.entity.app.ProjectFile
import ru.terrakok.gitlabclient.model.interactor.project.ProjectInteractor
import ru.terrakok.gitlabclient.model.system.ResourceManager
import ru.terrakok.gitlabclient.model.system.flow.FlowRouter
import ru.terrakok.gitlabclient.presentation.global.BasePresenter
import ru.terrakok.gitlabclient.presentation.global.ErrorHandler
......@@ -25,7 +27,8 @@ class ProjectFilesPresenter @Inject constructor(
private val projectInteractor: ProjectInteractor,
private val errorHandler: ErrorHandler,
private val router: FlowRouter,
private val projectFileDestination: ProjectFileDestination
private val projectFileDestination: ProjectFileDestination,
private val resourceManager: ResourceManager
) : BasePresenter<ProjectFilesView>() {
private val projectId = projectIdWrapper.value
......@@ -76,40 +79,58 @@ class ProjectFilesPresenter @Inject constructor(
super.onFirstViewAttach()
if (projectFileDestination.isInitiated()) {
projectInteractor.getProjectBranches(projectId)
.doOnSubscribe { viewState.showBlockingProgress(true) }
.doAfterTerminate { viewState.showBlockingProgress(false) }
.subscribe(
{
projectBranches.addAll(it)
projectFileDestination.moveToRoot()
},
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
)
.connect()
loadBranches()
} else {
Single
.zip(
projectInteractor.getProject(projectId),
projectInteractor.getProjectBranches(projectId),
BiFunction<Project, List<Branch>, Pair<Project, List<Branch>>> { project, branches ->
Pair(project, branches)
}
)
.doOnSubscribe { viewState.showBlockingProgress(true) }
.doAfterTerminate { viewState.showBlockingProgress(false) }
.subscribe(
{ (project, branches) ->
projectBranches.addAll(branches)
projectFileDestination.init(project.path, project.defaultBranch)
projectFileDestination.moveToRoot()
},
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
)
.connect()
loadProjectWithBranches()
}
}
private fun loadBranches() {
projectInteractor.getProjectBranches(projectId)
.doOnSubscribe { viewState.showBlockingProgress(true) }
.doAfterTerminate { viewState.showBlockingProgress(false) }
.subscribe(
{
viewState.showBranchSelection(true)
projectBranches.addAll(it)
projectFileDestination.moveToRoot()
},
{ handleLoadingProjectDetailsError(it) }
)
.connect()
}
private fun loadProjectWithBranches() {
Single
.zip(
projectInteractor.getProject(projectId),
projectInteractor.getProjectBranches(projectId),
BiFunction<Project, List<Branch>, Pair<Project, List<Branch>>> { project, branches ->
Pair(project, branches)
}
)
.doOnSubscribe { viewState.showBlockingProgress(true) }
.doAfterTerminate { viewState.showBlockingProgress(false) }
.subscribe(
{ (project, branches) ->
viewState.showBranchSelection(true)
projectBranches.addAll(branches)
projectFileDestination.init(project.path, project.defaultBranch)
projectFileDestination.moveToRoot()
},
{ handleLoadingProjectDetailsError(it) }
)
.connect()
}
private fun handleLoadingProjectDetailsError(error: Throwable) {
viewState.setPath(resourceManager.getString(R.string.project_files_default_path))
viewState.showBranchSelection(false)
errorHandler.proceed(error, { viewState.showEmptyError(true, it) })
}
private val paginator = Paginator(
{
projectInteractor.getProjectFiles(
......@@ -154,7 +175,17 @@ class ProjectFilesPresenter @Inject constructor(
}
)
fun refreshFiles() = paginator.refresh()
fun refreshFiles() {
if (projectFileDestination.isInitiated()) {
paginator.refresh()
} else {
viewState.showEmptyError(false, null)
viewState.showRefreshProgress(false)
loadProjectWithBranches()
}
}
fun loadNextFilesPage() = paginator.loadNewPage()
fun onShowBranchesClick() = viewState.showBranches(projectBranches)
fun onBackPressed() = projectFileDestination.moveBack()
......
......@@ -178,6 +178,7 @@
<!--Project files screen-->
<string name="project_files_show_branches">Branches</string>
<string name="project_files_default_path">Project Files</string>
<!--Privacy policy screen-->
<string name="privacy_policy">Privacy policy</string>
......
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