Commit 747a4713 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Merge branch 'bug/optimize_bottom_tab_tab_selection' into 'develop'

Refactored bottom bar fragment transactions.

See merge request !76
parents 353a192d 3fc7de53
......@@ -111,10 +111,8 @@ class MainActivity : BaseActivity(), LaunchView {
//region nav drawer
private fun openNavDrawer(open: Boolean) {
drawerLayout.postDelayed({
if (open) drawerLayout.openDrawer(GravityCompat.START)
else drawerLayout.closeDrawer(GravityCompat.START)
}, 150)
if (open) drawerLayout.openDrawer(GravityCompat.START)
else drawerLayout.closeDrawer(GravityCompat.START)
}
private fun enableNavDrawer(enable: Boolean) {
......
......@@ -46,6 +46,19 @@ class MainFragment : BaseFragment(), MainView {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
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) showTab(position, currentItem)
true
}
}
if (savedInstanceState == null) {
tabs = createNewFragments()
childFragmentManager.beginTransaction()
......@@ -53,25 +66,21 @@ class MainFragment : BaseFragment(), MainView {
.add(R.id.mainScreenContainer, tabs[tabKeys[1]], tabKeys[1])
.add(R.id.mainScreenContainer, tabs[tabKeys[2]], tabKeys[2])
.add(R.id.mainScreenContainer, tabs[tabKeys[3]], tabKeys[3])
.commit()
showTab(0)
.hide(tabs[tabKeys[1]])
.hide(tabs[tabKeys[2]])
.hide(tabs[tabKeys[3]])
.commitNow()
bottomBar.setCurrentItem(0, false)
} else {
tabs = findFragments()
}
}
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 showTab(newItem: Int, oldItem: Int) {
childFragmentManager.beginTransaction()
.hide(tabs[tabKeys[oldItem]])
.show(tabs[tabKeys[newItem]])
.commit()
}
private fun createNewFragments(): HashMap<String, BaseFragment> = hashMapOf(
......@@ -88,15 +97,5 @@ class MainFragment : BaseFragment(), MainView {
tabKeys[3] to childFragmentManager.findFragmentByTag(tabKeys[3]) as BaseFragment
)
private fun showTab(position: Int) {
childFragmentManager.beginTransaction()
.detach(tabs[tabKeys[0]])
.detach(tabs[tabKeys[1]])
.detach(tabs[tabKeys[2]])
.detach(tabs[tabKeys[3]])
.attach(tabs[tabKeys[position]])
.commit()
}
override fun onBackPressed() = presenter.onBackPressed()
}
\ 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