Commit 4c15e3be authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

Moved toolbar into ProjectInfoFragment.

parent 4d521966
......@@ -28,6 +28,8 @@ class ProjectInfoPresenter @Inject constructor(
override fun onFirstViewAttach() {
super.onFirstViewAttach()
viewState.setToolbarTitle(projectId.toString(10))
projectInteractor
.getProject(projectId)
.flatMap { project ->
......@@ -45,7 +47,10 @@ class ProjectInfoPresenter @Inject constructor(
.doOnSubscribe { viewState.showProgress(true) }
.doAfterTerminate { viewState.showProgress(false) }
.subscribe(
{ (project, mdReadme) -> viewState.showProject(project, mdReadme) },
{ (project, mdReadme) ->
viewState.setToolbarTitle(project.name)
viewState.showProject(project, mdReadme)
},
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
)
.connect()
......
......@@ -11,6 +11,7 @@ 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)
......
......@@ -27,16 +27,6 @@ class ProjectFragment : BaseFragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
if (savedInstanceState == null) {
tabs = createNewFragments()
childFragmentManager.beginTransaction()
.add(R.id.projectScreenContainer, tabs[tabKeys[0]], tabKeys[0])
.commit()
showTab(0)
bottomBar.setCurrentItem(0, false)
} else {
tabs = findFragments()
}
AHBottomNavigationAdapter(activity, R.menu.project_bottom_menu).apply {
setupWithBottomNavigation(bottomBar)
}
......@@ -45,10 +35,27 @@ class ProjectFragment : BaseFragment() {
inactiveColor = context.color(R.color.silver)
setOnTabSelectedListener { position, wasSelected ->
if (!wasSelected) postDelayed({ showTab(position) }, 150)
if (!wasSelected) showTab(position, currentItem)
true
}
}
if (savedInstanceState == null) {
tabs = createNewFragments()
childFragmentManager.beginTransaction()
.add(R.id.projectScreenContainer, tabs[tabKeys[0]], tabKeys[0])
.commitNow()
bottomBar.setCurrentItem(0, false)
} else {
tabs = findFragments()
}
}
private fun showTab(newItem: Int, oldItem: Int) {
childFragmentManager.beginTransaction()
.hide(tabs[tabKeys[oldItem]])
.show(tabs[tabKeys[newItem]])
.commit()
}
private fun createNewFragments(): HashMap<String, BaseFragment> = hashMapOf(
......@@ -58,11 +65,4 @@ class ProjectFragment : BaseFragment() {
private fun findFragments(): HashMap<String, BaseFragment> = hashMapOf(
tabKeys[0] to childFragmentManager.findFragmentByTag(tabKeys[0]) as BaseFragment
)
private fun showTab(position: Int) {
childFragmentManager.beginTransaction()
.detach(tabs[tabKeys[0]])
.attach(tabs[tabKeys[position]])
.commit()
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.ui.project.info
import android.os.Bundle
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import kotlinx.android.synthetic.main.fragment_project_info.*
......@@ -8,6 +9,7 @@ import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.Visibility
import ru.terrakok.gitlabclient.extension.loadRoundedImage
import ru.terrakok.gitlabclient.extension.shareText
import ru.terrakok.gitlabclient.extension.visible
import ru.terrakok.gitlabclient.presentation.project.ProjectInfoPresenter
import ru.terrakok.gitlabclient.presentation.project.ProjectInfoView
......@@ -24,13 +26,35 @@ class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
@InjectPresenter lateinit var presenter: ProjectInfoPresenter
private var project: Project? = null
@ProvidePresenter
fun providePresenter(): ProjectInfoPresenter =
Toothpick
.openScopes(DI.PROJECT_SCOPE)
.getInstance(ProjectInfoPresenter::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
toolbar.setNavigationOnClickListener { presenter.onBackPressed() }
toolbar.inflateMenu(R.menu.share_menu)
toolbar.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.shareAction -> shareText(project?.webUrl)
}
true
}
}
override fun setToolbarTitle(title: String) {
toolbar.title = title
}
override fun showProject(project: Project, mdReadme: CharSequence) {
this.project = project
titleTextView.text = project.nameWithNamespace
descriptionTextView.text = project.description
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:navigationIcon="@drawable/ic_arrow_back_24dp"
tools:title="GitFox" />
<FrameLayout
android:id="@+id/projectScreenContainer"
android:layout_width="match_parent"
......
......@@ -6,6 +6,14 @@
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:navigationIcon="@drawable/ic_arrow_back_24dp"
tools:title="GitFox" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
......
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