Commit 26ac8b79 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

changed deprecated bottom navigation bar to more powerful analogue

parent 36815d07
......@@ -96,7 +96,7 @@ dependencies {
//Markdown to HTML converter
compile 'ru.noties:markwon:1.0.3'
//Bottom navigation bar
compile 'com.roughike:bottom-bar:2.3.1'
compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
//Custom fonts
compile 'uk.co.chrisjenx:calligraphy:2.3.0'
//Lottie
......
......@@ -3,8 +3,10 @@ package ru.terrakok.gitlabclient.ui.main
import android.os.Bundle
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.ProvidePresenter
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter
import kotlinx.android.synthetic.main.fragment_main.*
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.extension.color
import ru.terrakok.gitlabclient.presentation.main.MainPresenter
import ru.terrakok.gitlabclient.presentation.main.MainView
import ru.terrakok.gitlabclient.toothpick.DI
......@@ -12,8 +14,6 @@ import ru.terrakok.gitlabclient.ui.global.BaseFragment
import ru.terrakok.gitlabclient.ui.my.activity.MyEventsFragment
import ru.terrakok.gitlabclient.ui.my.issues.MyIssuesContainerFragment
import ru.terrakok.gitlabclient.ui.my.mergerequests.MyMergeRequestsContainerFragment
import ru.terrakok.gitlabclient.ui.my.todos.MyTodosFragment
import ru.terrakok.gitlabclient.ui.my.mergerequests.MyMergeRequestsFragment
import ru.terrakok.gitlabclient.ui.my.todos.MyTodosContainerFragment
import toothpick.Toothpick
......@@ -31,7 +31,8 @@ class MainFragment : BaseFragment(), MainView {
tabIdToFragmentTag(R.id.tab_todo)
)
@InjectPresenter lateinit var presenter: MainPresenter
@InjectPresenter
lateinit var presenter: MainPresenter
@ProvidePresenter
fun providePresenter(): MainPresenter {
......@@ -53,12 +54,23 @@ class MainFragment : BaseFragment(), MainView {
.add(R.id.mainScreenContainer, tabs[tabKeys[2]], tabKeys[2])
.add(R.id.mainScreenContainer, tabs[tabKeys[3]], tabKeys[3])
.commit()
bottomBar.selectTabAtPosition(0, false)
bottomBar.setCurrentItem(0, false)
} else {
tabs = findFragments()
}
bottomBar.setOnTabSelectListener { showTab(it) }
AHBottomNavigationAdapter(activity, R.menu.main_bottom_menu).apply {
setupWithBottomNavigation(bottomBar)
}
with(bottomBar) {
accentColor = context.color(R.color.colorPrimary)
inactiveColor = context.color(R.color.silver)
setOnTabSelectedListener { position, wasSelected ->
if (!wasSelected) postDelayed({ showTab(position) }, 150)
true
}
}
}
private fun createNewFragments(): HashMap<String, BaseFragment> = hashMapOf(
......@@ -75,13 +87,13 @@ class MainFragment : BaseFragment(), MainView {
tabKeys[3] to childFragmentManager.findFragmentByTag(tabKeys[3]) as BaseFragment
)
private fun showTab(id: Int) {
private fun showTab(position: Int) {
childFragmentManager.beginTransaction()
.detach(tabs[tabIdToFragmentTag(R.id.tab_activity)])
.detach(tabs[tabIdToFragmentTag(R.id.tab_issue)])
.detach(tabs[tabIdToFragmentTag(R.id.tab_merge)])
.detach(tabs[tabIdToFragmentTag(R.id.tab_todo)])
.attach(tabs[tabIdToFragmentTag(id)])
.detach(tabs[tabKeys[0]])
.detach(tabs[tabKeys[1]])
.detach(tabs[tabKeys[2]])
.detach(tabs[tabKeys[3]])
.attach(tabs[tabKeys[position]])
.commit()
}
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorPrimary" android:state_enabled="true"/>
<item android:color="@color/lightGrey"/>
</selector>
\ 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
......@@ -12,16 +11,11 @@
android:layout_height="0dp"
android:layout_weight="1"/>
<com.roughike.bottombar.BottomBar
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_height="wrap_content"
android:background="@color/white"
android:elevation="8dp"
app:bb_activeTabColor="@color/colorPrimary"
app:bb_behavior="shifting"
app:bb_inActiveTabAlpha="1.0"
app:bb_inActiveTabColor="@color/silver"
app:bb_tabXmlResource="@xml/main_bottombar_tabs"/>
android:elevation="8dp"/>
</LinearLayout>
......@@ -94,7 +94,7 @@
android:id="@+id/activityMI"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_primary_color"
android:background="@drawable/selector_light_grey_to_white"
android:drawableLeft="@drawable/ic_assessment_grey_800_24dp"
android:drawablePadding="16dp"
android:gravity="center_vertical"
......@@ -108,7 +108,7 @@
android:id="@+id/projectsMI"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_primary_color"
android:background="@drawable/selector_light_grey_to_white"
android:drawableLeft="@drawable/ic_view_list_grey_800_24dp"
android:drawablePadding="16dp"
android:gravity="center_vertical"
......@@ -129,7 +129,7 @@
android:id="@+id/aboutMI"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_primary_color"
android:background="@drawable/selector_light_grey_to_white"
android:drawableLeft="@drawable/ic_info_grey_800_24dp"
android:drawablePadding="16dp"
android:gravity="center_vertical"
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/tab_activity"
android:icon="@drawable/ic_activity"
android:title="@string/gitlab_activity"/>
<item
android:id="@+id/tab_issue"
android:icon="@drawable/ic_issues"
android:title="@string/gitlab_issue"/>
<item
android:id="@+id/tab_merge"
android:icon="@drawable/ic_merge"
android:title="@string/gitlab_merge"/>
<item
android:id="@+id/tab_todo"
android:icon="@drawable/ic_todo"
android:title="@string/gitlab_todo"/>
</menu>
\ No newline at end of file
<tabs>
<tab
id="@+id/tab_activity"
icon="@drawable/ic_activity"
title="@string/gitlab_activity"/>
<tab
id="@+id/tab_issue"
icon="@drawable/ic_issues"
title="@string/gitlab_issue"/>
<tab
id="@+id/tab_merge"
icon="@drawable/ic_merge"
title="@string/gitlab_merge"/>
<tab
id="@+id/tab_todo"
icon="@drawable/ic_todo"
title="@string/gitlab_todo"/>
</tabs>
\ No newline at end of file
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