Commit cce7b411 authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

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

parent 90663b1e
......@@ -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}/"
)
......
......@@ -114,21 +114,29 @@ 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(null)
}
},
{ handleLoadingProjectDetailsError(it) }
)
.connect()
}
private fun handleLoadingProjectDetailsError(error: Throwable) {
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 != null) {
errorHandler.proceed(error, { viewState.showEmptyError(true, it) })
} else {
viewState.showEmptyError(true, resourceManager.getString(R.string.project_files_no_branches))
}
}
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