Skip to content

Commit e2a9ce5

Browse files
committed
moving tabs at the bottom
1 parent fa35855 commit e2a9ce5

File tree

3 files changed

+54
-79
lines changed

3 files changed

+54
-79
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ android {
6464
}
6565

6666
dependencies {
67-
implementation 'com.github.SimpleMobileTools:Simple-Commons:d65a4663a4'
67+
implementation 'com.github.SimpleMobileTools:Simple-Commons:4aa0b9aaad'
6868
implementation 'com.github.tibbi:AndroidPdfViewer:da57ff410e'
6969
implementation 'com.github.Stericson:RootTools:df729dcb13'
7070
implementation 'com.github.Stericson:RootShell:1.6'

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 43 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.app.SearchManager
66
import android.content.ClipData
77
import android.content.Context
88
import android.content.Intent
9-
import android.graphics.drawable.ColorDrawable
109
import android.graphics.drawable.Drawable
1110
import android.media.RingtoneManager
1211
import android.net.Uri
@@ -16,6 +15,8 @@ import android.os.Handler
1615
import android.provider.Settings
1716
import android.view.Menu
1817
import android.view.MenuItem
18+
import android.widget.ImageView
19+
import android.widget.TextView
1920
import androidx.appcompat.widget.SearchView
2021
import androidx.core.view.MenuItemCompat
2122
import 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(

app/src/main/res/layout/activity_main.xml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
android:layout_width="match_parent"
66
android:layout_height="match_parent">
77

8-
<com.google.android.material.tabs.TabLayout
9-
android:id="@+id/main_tabs_holder"
10-
android:layout_width="match_parent"
11-
android:layout_height="48dp"
12-
app:elevation="6dp"
13-
app:tabIndicatorColor="@android:color/white"
14-
app:tabIndicatorHeight="2dp"
15-
app:tabMinWidth="150dp"
16-
app:tabSelectedTextColor="@android:color/white" />
17-
188
<com.simplemobiletools.commons.views.MyViewPager
199
android:id="@+id/main_view_pager"
2010
android:layout_width="match_parent"
2111
android:layout_height="match_parent"
22-
android:layout_below="@+id/main_tabs_holder" />
12+
android:layout_above="@+id/main_tabs_holder" />
13+
14+
<com.google.android.material.tabs.TabLayout
15+
android:id="@+id/main_tabs_holder"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:layout_alignParentBottom="true"
19+
app:tabIndicator="@null"
20+
app:tabMinWidth="150dp"
21+
app:tabRippleColor="@null" />
2322

2423
</RelativeLayout>

0 commit comments

Comments
 (0)