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 ...@@ -6,7 +6,7 @@ import org.threeten.bp.LocalDateTime
data class Project( data class Project(
@SerializedName("id") val id: Long, @SerializedName("id") val id: Long,
@SerializedName("description") val description: String?, @SerializedName("description") val description: String?,
@SerializedName("default_branch") val defaultBranch: String, @SerializedName("default_branch") val defaultBranch: String?,
@SerializedName("visibility") val visibility: Visibility, @SerializedName("visibility") val visibility: Visibility,
@SerializedName("ssh_url_to_repo") val sshUrlToRepo: String?, @SerializedName("ssh_url_to_repo") val sshUrlToRepo: String?,
@SerializedName("http_url_to_repo") val httpUrlToRepo: String?, @SerializedName("http_url_to_repo") val httpUrlToRepo: String?,
......
...@@ -46,7 +46,7 @@ class ProjectInteractor @Inject constructor( ...@@ -46,7 +46,7 @@ class ProjectInteractor @Inject constructor(
fun getProjectReadme(project: Project) = fun getProjectReadme(project: Project) =
Single Single
.defer { .defer {
if (project.readmeUrl != null) { if (project.defaultBranch != null && project.readmeUrl != null) {
val readmePath = project.readmeUrl.substringAfter( val readmePath = project.readmeUrl.substringAfter(
"${project.webUrl}/blob/${project.defaultBranch}/" "${project.webUrl}/blob/${project.defaultBranch}/"
) )
......
...@@ -114,21 +114,29 @@ class ProjectFilesPresenter @Inject constructor( ...@@ -114,21 +114,29 @@ class ProjectFilesPresenter @Inject constructor(
.doAfterTerminate { viewState.showBlockingProgress(false) } .doAfterTerminate { viewState.showBlockingProgress(false) }
.subscribe( .subscribe(
{ (project, branches) -> { (project, branches) ->
viewState.showBranchSelection(true) if (project.defaultBranch != null) {
viewState.showBranchSelection(true)
projectBranches.addAll(branches) projectBranches.addAll(branches)
projectFileDestination.init(project.path, project.defaultBranch) projectFileDestination.init(project.path, project.defaultBranch)
projectFileDestination.moveToRoot() projectFileDestination.moveToRoot()
} else {
handleLoadingProjectDetailsError(null)
}
}, },
{ handleLoadingProjectDetailsError(it) } { handleLoadingProjectDetailsError(it) }
) )
.connect() .connect()
} }
private fun handleLoadingProjectDetailsError(error: Throwable) { private fun handleLoadingProjectDetailsError(error: Throwable?) {
viewState.setPath(resourceManager.getString(R.string.project_files_default_path)) viewState.setPath(resourceManager.getString(R.string.project_files_default_path))
viewState.showBranchSelection(false) 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( private val paginator = Paginator(
......
...@@ -181,7 +181,8 @@ ...@@ -181,7 +181,8 @@
<!--Project files screen--> <!--Project files screen-->
<string name="project_files_show_branches">Branches</string> <string name="project_files_show_branches">Branches</string>
<string name="project_files_default_path">Project Files</string> <string name="project_files_default_path">Project Files</string>
<string name="project_files_no_branches">You have no branches</string>
<!--Privacy policy screen--> <!--Privacy policy screen-->
<string name="privacy_policy">Privacy policy</string> <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