Commit 3a181bb6 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Merge branch 'fix/project_files_branch_crash' into 'develop'

Fix crash with project files, when default branch is null.

See merge request !155
parents 8abf7c68 6e9e2ba0
......@@ -6,7 +6,7 @@ import org.threeten.bp.LocalDateTime
data class Project(
@SerializedName("id") val id: Long,
@SerializedName("description") val description: String?,
@SerializedName("default_branch") val defaultBranch: String,
@SerializedName("default_branch") val defaultBranch: String?,
@SerializedName("visibility") val visibility: Visibility,
@SerializedName("ssh_url_to_repo") val sshUrlToRepo: String?,
@SerializedName("http_url_to_repo") val httpUrlToRepo: String?,
......
......@@ -46,7 +46,7 @@ class ProjectInteractor @Inject constructor(
fun getProjectReadme(project: Project) =
Single
.defer {
if (project.readmeUrl != null) {
if (project.defaultBranch != null && project.readmeUrl != null) {
val readmePath = project.readmeUrl.substringAfter(
"${project.webUrl}/blob/${project.defaultBranch}/"
)
......
package ru.terrakok.gitlabclient.presentation.project.files
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 04.01.19.
*/
class NoBranchesError : RuntimeException()
\ No newline at end of file
......@@ -114,11 +114,15 @@ class ProjectFilesPresenter @Inject constructor(
.doAfterTerminate { viewState.showBlockingProgress(false) }
.subscribe(
{ (project, branches) ->
viewState.showBranchSelection(true)
if (project.defaultBranch != null) {
viewState.showBranchSelection(true)
projectBranches.addAll(branches)
projectFileDestination.init(project.path, project.defaultBranch)
projectFileDestination.moveToRoot()
projectBranches.addAll(branches)
projectFileDestination.init(project.path, project.defaultBranch)
projectFileDestination.moveToRoot()
} else {
handleLoadingProjectDetailsError(NoBranchesError())
}
},
{ handleLoadingProjectDetailsError(it) }
)
......@@ -128,7 +132,11 @@ class ProjectFilesPresenter @Inject constructor(
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) })
if (error is NoBranchesError) {
viewState.showEmptyError(true, resourceManager.getString(R.string.project_files_no_branches))
} else {
errorHandler.proceed(error, { viewState.showEmptyError(true, it) })
}
}
private val paginator = Paginator(
......
......@@ -181,7 +181,8 @@
<!--Project files screen-->
<string name="project_files_show_branches">Branches</string>
<string name="project_files_default_path">Project Files</string>
<string name="project_files_no_branches">You have no branches</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