adding the top tab holder
This commit is contained in:
parent
3001db8769
commit
09018683b8
2 changed files with 70 additions and 2 deletions
|
@ -5,6 +5,7 @@ import android.app.SearchManager
|
|||
import android.content.ClipData
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.media.RingtoneManager
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
|
@ -88,6 +89,14 @@ class MainActivity : SimpleActivity() {
|
|||
it.updateDateTimeFormat()
|
||||
}
|
||||
}
|
||||
|
||||
getInactiveTabIndexes(main_view_pager.currentItem).forEach {
|
||||
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(config.textColor)
|
||||
}
|
||||
|
||||
main_tabs_holder.background = ColorDrawable(config.backgroundColor)
|
||||
main_tabs_holder.setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||
main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -163,7 +172,7 @@ class MainActivity : SimpleActivity() {
|
|||
val path = savedInstanceState.getString(PICKED_PATH) ?: internalStoragePath
|
||||
|
||||
if (main_view_pager.adapter == null) {
|
||||
main_view_pager.adapter = ViewPagerAdapter(this)
|
||||
initFragments()
|
||||
main_view_pager.onGlobalLayout {
|
||||
restorePath(path)
|
||||
}
|
||||
|
@ -276,6 +285,43 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun initFragments() {
|
||||
main_view_pager.adapter = ViewPagerAdapter(this)
|
||||
main_view_pager.onPageChangeListener {
|
||||
main_tabs_holder.getTabAt(it)?.select()
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
val tabToOpen = config.lastUsedViewPagerPage
|
||||
main_view_pager.currentItem = tabToOpen
|
||||
main_tabs_holder.onTabSelectionChanged(
|
||||
tabUnselectedAction = {
|
||||
it.icon?.applyColorFilter(config.textColor)
|
||||
},
|
||||
tabSelectedAction = {
|
||||
main_view_pager.currentItem = it.position
|
||||
it.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
}
|
||||
)
|
||||
|
||||
setupTabColors(tabToOpen)
|
||||
}
|
||||
|
||||
private fun setupTabColors(lastUsedTab: Int) {
|
||||
main_tabs_holder.apply {
|
||||
background = ColorDrawable(config.backgroundColor)
|
||||
setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
|
||||
getTabAt(lastUsedTab)?.apply {
|
||||
select()
|
||||
icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||
}
|
||||
|
||||
getInactiveTabIndexes(lastUsedTab).forEach {
|
||||
getTabAt(it)?.icon?.applyColorFilter(config.textColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkOTGPath() {
|
||||
ensureBackgroundThread {
|
||||
if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) {
|
||||
|
@ -466,6 +512,8 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getInactiveTabIndexes(activeIndex: Int) = arrayListOf(0, 1).filter { it != activeIndex }
|
||||
|
||||
private fun getAllFragments() = arrayListOf(items_fragment)
|
||||
|
||||
private fun getCurrentFragment() = items_fragment
|
||||
|
|
|
@ -1,12 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/main_screen"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/main_tabs_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
app:elevation="6dp"
|
||||
app:tabIndicatorColor="@android:color/white"
|
||||
app:tabIndicatorHeight="2dp"
|
||||
app:tabMinWidth="150dp"
|
||||
app:tabSelectedTextColor="@android:color/white">
|
||||
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:id="@+id/tab_files"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:icon="@drawable/ic_folder_vector" />
|
||||
|
||||
</com.google.android.material.tabs.TabLayout>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyViewPager
|
||||
android:id="@+id/main_view_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/main_tabs_holder" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue