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

Refactored code associated with comments.

parent 1b915922
package ru.terrakok.gitlabclient.model.interactor.project
import io.reactivex.Single
import ru.terrakok.gitlabclient.entity.OrderBy
import ru.terrakok.gitlabclient.model.repository.project.ProjectRepository
import ru.terrakok.gitlabclient.model.repository.tools.Base64Tools
......@@ -42,19 +43,18 @@ class ProjectInteractor @Inject constructor(
fun getProject(id: Long) = projectRepository.getProject(id)
/**
* Returns the project readme file at the specified project and branch.
* The project readme is searched ignoring case.
* Returns [Single] with the project readme file decoded as [String]
* at the specified project and branch. The project readme is searched ignoring case.
*
* @param id project id
* @param branchName project branch name to search readme
* @return decoded project readme as String
* @throws NoSuchElementException if project readme with name {@value README_FILE_NAME} not found.
* @param id project id.
* @param branchName project branch name to search readme.
* @return [Single] with readme decoded as [String].
* @throws NoSuchElementException if project readme with name [README_FILE_NAME] not found.
*/
fun getProjectReadme(id: Long, branchName: String) =
projectRepository.getRepositoryTree(projectId = id, branchName = branchName)
.map { treeNodes ->
treeNodes.find { it.name.contains(README_FILE_NAME, true) }
?: throw NoSuchElementException("$README_FILE_NAME not found!")
treeNodes.first { it.name.contains(README_FILE_NAME, true) }
}
.flatMap { treeNode ->
projectRepository.getFile(id, treeNode.name, branchName)
......
......@@ -28,8 +28,6 @@ class ProjectInfoPresenter @Inject constructor(
override fun onFirstViewAttach() {
super.onFirstViewAttach()
viewState.setToolbarTitle(projectId.toString())
projectInteractor
.getProject(projectId)
.flatMap { project ->
......@@ -47,10 +45,7 @@ class ProjectInfoPresenter @Inject constructor(
.doOnSubscribe { viewState.showProgress(true) }
.doAfterTerminate { viewState.showProgress(false) }
.subscribe(
{ (project, mdReadme) ->
viewState.setToolbarTitle(project.name)
viewState.showProject(project, mdReadme)
},
{ (project, mdReadme) -> viewState.showProject(project, mdReadme) },
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
)
.connect()
......
......@@ -11,7 +11,6 @@ import ru.terrakok.gitlabclient.entity.Project
*/
@StateStrategyType(AddToEndSingleStrategy::class)
interface ProjectInfoView : MvpView {
fun setToolbarTitle(title: String)
fun showProject(project: Project, mdReadme: CharSequence)
fun showProgress(show: Boolean)
......
......@@ -43,7 +43,7 @@ class ProjectFragment : BaseFragment() {
if (savedInstanceState == null) {
tabs = createNewFragments()
childFragmentManager.beginTransaction()
.add(R.id.projectScreenContainer, tabs[tabKeys[0]], tabKeys[0])
.add(R.id.container, tabs[tabKeys[0]], tabKeys[0])
.commitNow()
bottomBar.setCurrentItem(0, false)
} else {
......
......@@ -48,15 +48,10 @@ class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
}
}
override fun setToolbarTitle(title: String) {
toolbar.title = title
}
override fun showProject(project: Project, mdReadme: CharSequence) {
this.project = project
constraintView.visible(true)
toolbar.title = project.name
titleTextView.text = project.nameWithNamespace
descriptionTextView.text = project.description
starsTextView.text = project.starCount.toString()
......@@ -75,6 +70,7 @@ class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
override fun showProgress(show: Boolean) {
fullscreenProgressView.visible(show)
projectInfoLayout.visible(!show)
}
override fun showMessage(message: String) {
......
......@@ -5,7 +5,7 @@
android:orientation="vertical">
<FrameLayout
android:id="@+id/projectScreenContainer"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
......
......@@ -24,11 +24,9 @@
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintView"
android:id="@+id/projectInfoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible">
android:layout_height="match_parent">
<ImageView
android:id="@+id/avatarImageView"
......
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