@@ -6,7 +6,6 @@ import android.app.SearchManager
66import android.content.ClipData
77import android.content.Context
88import android.content.Intent
9- import android.graphics.drawable.ColorDrawable
109import android.graphics.drawable.Drawable
1110import android.media.RingtoneManager
1211import android.net.Uri
@@ -16,6 +15,8 @@ import android.os.Handler
1615import android.provider.Settings
1716import android.view.Menu
1817import android.view.MenuItem
18+ import android.widget.ImageView
19+ import android.widget.TextView
1920import androidx.appcompat.widget.SearchView
2021import androidx.core.view.MenuItemCompat
2122import androidx.viewpager.widget.ViewPager
@@ -75,8 +76,8 @@ class MainActivity : SimpleActivity() {
7576 }
7677 }
7778
78- setupTabColors(config.lastUsedViewPagerPage)
7979 storeStateVariables()
80+ setupTabs()
8081 mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
8182
8283 if (savedInstanceState == null ) {
@@ -104,6 +105,7 @@ class MainActivity : SimpleActivity() {
104105 return
105106 }
106107
108+ setupTabColors()
107109 getAllFragments().forEach {
108110 it?.onResume(getProperTextColor())
109111 }
@@ -120,15 +122,6 @@ class MainActivity : SimpleActivity() {
120122 }
121123 }
122124
123- getInactiveTabIndexes(main_view_pager.currentItem).forEach {
124- main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(getProperTextColor())
125- }
126-
127- val properPrimaryColor = getProperPrimaryColor()
128- main_tabs_holder.background = ColorDrawable (getProperBackgroundColor())
129- main_tabs_holder.setSelectedTabIndicatorColor(properPrimaryColor)
130- main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(properPrimaryColor)
131-
132125 if (main_view_pager.adapter == null && mWasProtectionHandled) {
133126 initFragments()
134127 }
@@ -221,7 +214,6 @@ class MainActivity : SimpleActivity() {
221214 main_view_pager.onGlobalLayout {
222215 restorePath(path)
223216 }
224- updateTabColors()
225217 } else {
226218 restorePath(path)
227219 }
@@ -390,27 +382,12 @@ class MainActivity : SimpleActivity() {
390382 private fun initFragments () {
391383 main_view_pager.adapter = ViewPagerAdapter (this )
392384 main_view_pager.offscreenPageLimit = 2
393- main_view_pager.currentItem = config.lastUsedViewPagerPage
394- main_view_pager.onPageChangeListener {
395- main_tabs_holder.getTabAt(it)?.select()
396- invalidateOptionsMenu()
397- }
398-
399- val tabToOpen = config.lastUsedViewPagerPage
400- main_view_pager.currentItem = tabToOpen
401- main_tabs_holder.onTabSelectionChanged(
402- tabUnselectedAction = {
403- it.icon?.applyColorFilter(getProperTextColor())
404- },
405- tabSelectedAction = {
406- main_view_pager.currentItem = it.position
407- it.icon?.applyColorFilter(getProperPrimaryColor())
408- }
409- )
410385
411386 main_view_pager.addOnPageChangeListener(object : ViewPager .OnPageChangeListener {
412387 override fun onPageScrollStateChanged (state : Int ) {
413- closeSearchIfOpen()
388+ if (state == ViewPager .SCROLL_STATE_SETTLING ) {
389+ closeSearch()
390+ }
414391 }
415392
416393 override fun onPageScrolled (position : Int , positionOffset : Float , positionOffsetPixels : Int ) {}
@@ -423,50 +400,47 @@ class MainActivity : SimpleActivity() {
423400 invalidateOptionsMenu()
424401 }
425402 })
403+ main_view_pager.currentItem = config.lastUsedViewPagerPage
404+ }
426405
406+ private fun setupTabs () {
427407 main_tabs_holder.removeAllTabs()
428- var skippedTabs = 0
429408 tabsList.forEachIndexed { index, value ->
430- if (config.showTabs and value = = 0 ) {
431- skippedTabs ++
432- } else {
433- val tab = main_tabs_holder.newTab().setIcon(getTabIcon( index) )
434- tab.contentDescription = getTabContentDescription(index )
435- main_tabs_holder.addTab(tab, index - skippedTabs, config.lastUsedViewPagerPage == index - skippedTabs)
409+ if (config.showTabs and value ! = 0 ) {
410+ main_tabs_holder.newTab().setCustomView( R .layout.bottom_tablayout_item). apply {
411+ customView?.findViewById< ImageView >( R .id.tab_item_icon)?.setImageDrawable(getTabIcon(index))
412+ customView?.findViewById< TextView >( R .id.tab_item_label)?.text = getTabLabel( index)
413+ main_tabs_holder.addTab( this )
414+ }
436415 }
437416 }
438417
439- // selecting the proper tab sometimes glitches, add an extra selector to make sure we have it right
440- main_tabs_holder.onGlobalLayout {
441- Handler ().postDelayed({
442- main_tabs_holder.getTabAt(config.lastUsedViewPagerPage)?.select()
443- invalidateOptionsMenu()
444- }, 100L )
445- }
418+ main_tabs_holder.onTabSelectionChanged(
419+ tabUnselectedAction = {
420+ updateBottomTabItemColors(it.customView, false )
421+ },
422+ tabSelectedAction = {
423+ closeSearch()
424+ main_view_pager.currentItem = it.position
425+ updateBottomTabItemColors(it.customView, true )
426+ }
427+ )
446428
447- main_tabs_holder.beVisibleIf(skippedTabs < tabsList.size - 1 )
429+ main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1 )
448430 }
449431
450- private fun setupTabColors (lastUsedTab : Int ) {
451- main_tabs_holder.apply {
452- background = ColorDrawable (getProperBackgroundColor())
453- setSelectedTabIndicatorColor(getProperPrimaryColor())
454- getTabAt(lastUsedTab)?.apply {
455- select()
456- icon?.applyColorFilter(getProperPrimaryColor())
457- }
432+ private fun setupTabColors () {
433+ val activeView = main_tabs_holder.getTabAt(main_view_pager.currentItem)?.customView
434+ updateBottomTabItemColors(activeView, true )
458435
459- getInactiveTabIndexes(lastUsedTab ).forEach {
460- getTabAt(it )?.icon?.applyColorFilter(getProperTextColor())
461- }
436+ getInactiveTabIndexes(main_view_pager.currentItem ).forEach { index ->
437+ val inactiveView = main_tabs_holder. getTabAt(index )?.customView
438+ updateBottomTabItemColors(inactiveView, false )
462439 }
463- }
464440
465- private fun updateTabColors () {
466- getInactiveTabIndexes(main_view_pager.currentItem).forEach {
467- main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(getProperTextColor())
468- }
469- main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(getProperPrimaryColor())
441+ val bottomBarColor = getBottomTabsBackgroundColor()
442+ main_tabs_holder.setBackgroundColor(bottomBarColor)
443+ updateNavigationBarColor(bottomBarColor)
470444 }
471445
472446 private fun getTabIcon (position : Int ): Drawable {
@@ -479,7 +453,7 @@ class MainActivity : SimpleActivity() {
479453 return resources.getColoredDrawableWithColor(drawableId, getProperTextColor())
480454 }
481455
482- private fun getTabContentDescription (position : Int ): String {
456+ private fun getTabLabel (position : Int ): String {
483457 val stringId = when (position) {
484458 0 -> R .string.files_tab
485459 1 -> R .string.recent_files_tab
@@ -500,9 +474,11 @@ class MainActivity : SimpleActivity() {
500474 }
501475 }
502476
503- private fun closeSearchIfOpen () {
477+ private fun closeSearch () {
504478 if (isSearchOpen) {
505- (getCurrentFragment() as ? ItemOperationsListener )?.searchQueryChanged(" " )
479+ getAllFragments().forEach {
480+ (it as ? ItemOperationsListener )?.searchQueryChanged(" " )
481+ }
506482 searchMenuItem?.collapseActionView()
507483 }
508484 }
@@ -614,12 +590,12 @@ class MainActivity : SimpleActivity() {
614590
615591 private fun launchSettings () {
616592 hideKeyboard()
617- closeSearchIfOpen ()
593+ closeSearch ()
618594 startActivity(Intent (applicationContext, SettingsActivity ::class .java))
619595 }
620596
621597 private fun launchAbout () {
622- closeSearchIfOpen ()
598+ closeSearch ()
623599 val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEWER
624600
625601 val faqItems = arrayListOf (
0 commit comments