mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-19 21:30:37 +01:00
moving tabs at the bottom
This commit is contained in:
parent
fa35855977
commit
e2a9ce578c
@ -64,7 +64,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:d65a4663a4'
|
implementation 'com.github.SimpleMobileTools:Simple-Commons:4aa0b9aaad'
|
||||||
implementation 'com.github.tibbi:AndroidPdfViewer:da57ff410e'
|
implementation 'com.github.tibbi:AndroidPdfViewer:da57ff410e'
|
||||||
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
implementation 'com.github.Stericson:RootTools:df729dcb13'
|
||||||
implementation 'com.github.Stericson:RootShell:1.6'
|
implementation 'com.github.Stericson:RootShell:1.6'
|
||||||
|
@ -6,7 +6,6 @@ import android.app.SearchManager
|
|||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.drawable.ColorDrawable
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -16,6 +15,8 @@ import android.os.Handler
|
|||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.core.view.MenuItemCompat
|
import androidx.core.view.MenuItemCompat
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
@ -75,8 +76,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTabColors(config.lastUsedViewPagerPage)
|
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
|
setupTabs()
|
||||||
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
|
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
@ -104,6 +105,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupTabColors()
|
||||||
getAllFragments().forEach {
|
getAllFragments().forEach {
|
||||||
it?.onResume(getProperTextColor())
|
it?.onResume(getProperTextColor())
|
||||||
}
|
}
|
||||||
@ -120,15 +122,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getInactiveTabIndexes(main_view_pager.currentItem).forEach {
|
|
||||||
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(getProperTextColor())
|
|
||||||
}
|
|
||||||
|
|
||||||
val properPrimaryColor = getProperPrimaryColor()
|
|
||||||
main_tabs_holder.background = ColorDrawable(getProperBackgroundColor())
|
|
||||||
main_tabs_holder.setSelectedTabIndicatorColor(properPrimaryColor)
|
|
||||||
main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(properPrimaryColor)
|
|
||||||
|
|
||||||
if (main_view_pager.adapter == null && mWasProtectionHandled) {
|
if (main_view_pager.adapter == null && mWasProtectionHandled) {
|
||||||
initFragments()
|
initFragments()
|
||||||
}
|
}
|
||||||
@ -221,7 +214,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
main_view_pager.onGlobalLayout {
|
main_view_pager.onGlobalLayout {
|
||||||
restorePath(path)
|
restorePath(path)
|
||||||
}
|
}
|
||||||
updateTabColors()
|
|
||||||
} else {
|
} else {
|
||||||
restorePath(path)
|
restorePath(path)
|
||||||
}
|
}
|
||||||
@ -390,27 +382,12 @@ class MainActivity : SimpleActivity() {
|
|||||||
private fun initFragments() {
|
private fun initFragments() {
|
||||||
main_view_pager.adapter = ViewPagerAdapter(this)
|
main_view_pager.adapter = ViewPagerAdapter(this)
|
||||||
main_view_pager.offscreenPageLimit = 2
|
main_view_pager.offscreenPageLimit = 2
|
||||||
main_view_pager.currentItem = config.lastUsedViewPagerPage
|
|
||||||
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(getProperTextColor())
|
|
||||||
},
|
|
||||||
tabSelectedAction = {
|
|
||||||
main_view_pager.currentItem = it.position
|
|
||||||
it.icon?.applyColorFilter(getProperPrimaryColor())
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
closeSearchIfOpen()
|
if (state == ViewPager.SCROLL_STATE_SETTLING) {
|
||||||
|
closeSearch()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
|
||||||
@ -423,50 +400,47 @@ class MainActivity : SimpleActivity() {
|
|||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
main_view_pager.currentItem = config.lastUsedViewPagerPage
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupTabs() {
|
||||||
main_tabs_holder.removeAllTabs()
|
main_tabs_holder.removeAllTabs()
|
||||||
var skippedTabs = 0
|
|
||||||
tabsList.forEachIndexed { index, value ->
|
tabsList.forEachIndexed { index, value ->
|
||||||
if (config.showTabs and value == 0) {
|
if (config.showTabs and value != 0) {
|
||||||
skippedTabs++
|
main_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply {
|
||||||
} else {
|
customView?.findViewById<ImageView>(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index))
|
||||||
val tab = main_tabs_holder.newTab().setIcon(getTabIcon(index))
|
customView?.findViewById<TextView>(R.id.tab_item_label)?.text = getTabLabel(index)
|
||||||
tab.contentDescription = getTabContentDescription(index)
|
main_tabs_holder.addTab(this)
|
||||||
main_tabs_holder.addTab(tab, index - skippedTabs, config.lastUsedViewPagerPage == index - skippedTabs)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// selecting the proper tab sometimes glitches, add an extra selector to make sure we have it right
|
main_tabs_holder.onTabSelectionChanged(
|
||||||
main_tabs_holder.onGlobalLayout {
|
tabUnselectedAction = {
|
||||||
Handler().postDelayed({
|
updateBottomTabItemColors(it.customView, false)
|
||||||
main_tabs_holder.getTabAt(config.lastUsedViewPagerPage)?.select()
|
},
|
||||||
invalidateOptionsMenu()
|
tabSelectedAction = {
|
||||||
}, 100L)
|
closeSearch()
|
||||||
}
|
main_view_pager.currentItem = it.position
|
||||||
|
updateBottomTabItemColors(it.customView, true)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
main_tabs_holder.beVisibleIf(skippedTabs < tabsList.size - 1)
|
main_tabs_holder.beGoneIf(main_tabs_holder.tabCount == 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupTabColors(lastUsedTab: Int) {
|
private fun setupTabColors() {
|
||||||
main_tabs_holder.apply {
|
val activeView = main_tabs_holder.getTabAt(main_view_pager.currentItem)?.customView
|
||||||
background = ColorDrawable(getProperBackgroundColor())
|
updateBottomTabItemColors(activeView, true)
|
||||||
setSelectedTabIndicatorColor(getProperPrimaryColor())
|
|
||||||
getTabAt(lastUsedTab)?.apply {
|
|
||||||
select()
|
|
||||||
icon?.applyColorFilter(getProperPrimaryColor())
|
|
||||||
}
|
|
||||||
|
|
||||||
getInactiveTabIndexes(lastUsedTab).forEach {
|
getInactiveTabIndexes(main_view_pager.currentItem).forEach { index ->
|
||||||
getTabAt(it)?.icon?.applyColorFilter(getProperTextColor())
|
val inactiveView = main_tabs_holder.getTabAt(index)?.customView
|
||||||
}
|
updateBottomTabItemColors(inactiveView, false)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateTabColors() {
|
val bottomBarColor = getBottomTabsBackgroundColor()
|
||||||
getInactiveTabIndexes(main_view_pager.currentItem).forEach {
|
main_tabs_holder.setBackgroundColor(bottomBarColor)
|
||||||
main_tabs_holder.getTabAt(it)?.icon?.applyColorFilter(getProperTextColor())
|
updateNavigationBarColor(bottomBarColor)
|
||||||
}
|
|
||||||
main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(getProperPrimaryColor())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTabIcon(position: Int): Drawable {
|
private fun getTabIcon(position: Int): Drawable {
|
||||||
@ -479,7 +453,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
return resources.getColoredDrawableWithColor(drawableId, getProperTextColor())
|
return resources.getColoredDrawableWithColor(drawableId, getProperTextColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTabContentDescription(position: Int): String {
|
private fun getTabLabel(position: Int): String {
|
||||||
val stringId = when (position) {
|
val stringId = when (position) {
|
||||||
0 -> R.string.files_tab
|
0 -> R.string.files_tab
|
||||||
1 -> R.string.recent_files_tab
|
1 -> R.string.recent_files_tab
|
||||||
@ -500,9 +474,11 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun closeSearchIfOpen() {
|
private fun closeSearch() {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
(getCurrentFragment() as? ItemOperationsListener)?.searchQueryChanged("")
|
getAllFragments().forEach {
|
||||||
|
(it as? ItemOperationsListener)?.searchQueryChanged("")
|
||||||
|
}
|
||||||
searchMenuItem?.collapseActionView()
|
searchMenuItem?.collapseActionView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -614,12 +590,12 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun launchSettings() {
|
private fun launchSettings() {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
closeSearchIfOpen()
|
closeSearch()
|
||||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchAbout() {
|
private fun launchAbout() {
|
||||||
closeSearchIfOpen()
|
closeSearch()
|
||||||
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEWER
|
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEWER
|
||||||
|
|
||||||
val faqItems = arrayListOf(
|
val faqItems = arrayListOf(
|
||||||
|
@ -5,20 +5,19 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="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.simplemobiletools.commons.views.MyViewPager
|
<com.simplemobiletools.commons.views.MyViewPager
|
||||||
android:id="@+id/main_view_pager"
|
android:id="@+id/main_view_pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_below="@+id/main_tabs_holder" />
|
android:layout_above="@+id/main_tabs_holder" />
|
||||||
|
|
||||||
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:id="@+id/main_tabs_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
app:tabIndicator="@null"
|
||||||
|
app:tabMinWidth="150dp"
|
||||||
|
app:tabRippleColor="@null" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user