Commit 350b5ab2 authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

Moved toolbar to ProjectFragment.

parent c9361bda
......@@ -50,6 +50,4 @@ class ProjectInfoPresenter @Inject constructor(
)
.connect()
}
fun onBackPressed() = router.exit()
}
\ No newline at end of file
......@@ -3,18 +3,27 @@ package ru.terrakok.gitlabclient.ui.project
import android.os.Bundle
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter
import kotlinx.android.synthetic.main.fragment_project.*
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.extension.color
import ru.terrakok.gitlabclient.extension.shareText
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.project.info.ProjectInfoFragment
import toothpick.Toothpick
import javax.inject.Inject
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 10.02.18.
*/
class ProjectFragment : BaseFragment() {
class ProjectFragment : BaseFragment(), ProjectInfoFragment.ToolbarConfigurator {
override val layoutRes: Int = R.layout.fragment_project
@Inject lateinit var router: Router
private var shareUrl: String? = null
private lateinit var tabs: HashMap<String, BaseFragment>
private val tabKeys = listOf(
tabIdToFragmentTag(R.id.tab_info),
......@@ -24,9 +33,22 @@ class ProjectFragment : BaseFragment() {
private fun tabIdToFragmentTag(id: Int) = "tab_$id"
override fun onCreate(savedInstanceState: Bundle?) {
Toothpick.inject(this, Toothpick.openScope(DI.PROJECT_SCOPE))
super.onCreate(savedInstanceState)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
toolbar.setNavigationOnClickListener { router.exit() }
toolbar.inflateMenu(R.menu.share_menu)
toolbar.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.shareAction -> shareText(shareUrl)
}
true
}
AHBottomNavigationAdapter(activity, R.menu.project_bottom_menu).apply {
setupWithBottomNavigation(bottomBar)
}
......@@ -65,4 +87,18 @@ class ProjectFragment : BaseFragment() {
private fun findFragments(): HashMap<String, BaseFragment> = hashMapOf(
tabKeys[0] to childFragmentManager.findFragmentByTag(tabKeys[0]) as BaseFragment
)
override fun setTitle(title: String) {
toolbar.title = title
}
override fun setShareUrl(url: String?) {
shareUrl = url
}
override fun onBackPressed() {
super.onBackPressed()
router.exit()
}
}
\ 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.*
......@@ -9,7 +8,6 @@ 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
......@@ -26,32 +24,17 @@ 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 showProject(project: Project, mdReadme: CharSequence) {
this.project = project
toolbar.title = project.name
(parentFragment as? ProjectInfoFragment.ToolbarConfigurator)?.apply {
setTitle(project.name)
setShareUrl(project.webUrl)
}
titleTextView.text = project.nameWithNamespace
descriptionTextView.text = project.description
starsTextView.text = project.starCount.toString()
......@@ -69,7 +52,7 @@ class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
}
override fun showProgress(show: Boolean) {
fullscreenProgressView.visible(show)
showProgressDialog(show)
projectInfoLayout.visible(!show)
}
......@@ -77,5 +60,8 @@ class ProjectInfoFragment : BaseFragment(), ProjectInfoView {
showSnackMessage(message)
}
override fun onBackPressed() = presenter.onBackPressed()
interface ToolbarConfigurator {
fun setTitle(title: String)
fun setShareUrl(url: String?)
}
}
\ No newline at end of file
<?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/container"
android:layout_width="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