show only the selected tabs
This commit is contained in:
parent
1e713ab812
commit
200e2a51d2
3 changed files with 83 additions and 24 deletions
|
@ -6,6 +6,7 @@ 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.ColorDrawable
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
|
@ -52,11 +53,13 @@ class MainActivity : SimpleActivity() {
|
||||||
private var storedFontSize = 0
|
private var storedFontSize = 0
|
||||||
private var storedDateFormat = ""
|
private var storedDateFormat = ""
|
||||||
private var storedTimeFormat = ""
|
private var storedTimeFormat = ""
|
||||||
|
private var storedShowTabs = 0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
appLaunched(BuildConfig.APPLICATION_ID)
|
appLaunched(BuildConfig.APPLICATION_ID)
|
||||||
|
setupTabColors(config.lastUsedViewPagerPage)
|
||||||
storeStateVariables()
|
storeStateVariables()
|
||||||
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
|
mIsPasswordProtectionPending = config.isAppPasswordProtectionOn
|
||||||
|
|
||||||
|
@ -79,6 +82,12 @@ class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
if (storedShowTabs != config.showTabs) {
|
||||||
|
config.lastUsedViewPagerPage = 0
|
||||||
|
System.exit(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
getAllFragments().forEach {
|
getAllFragments().forEach {
|
||||||
it?.setupColors(config.textColor, config.primaryColor)
|
it?.setupColors(config.textColor, config.primaryColor)
|
||||||
}
|
}
|
||||||
|
@ -129,7 +138,7 @@ class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
||||||
val favorites = config.favorites
|
val favorites = config.favorites
|
||||||
val currentFragment = getCurrentFragment() ?: return true
|
val currentFragment = getCurrentFragment()
|
||||||
|
|
||||||
menu!!.apply {
|
menu!!.apply {
|
||||||
findItem(R.id.search).isVisible = currentFragment is ItemsFragment
|
findItem(R.id.search).isVisible = currentFragment is ItemsFragment
|
||||||
|
@ -154,10 +163,6 @@ class MainActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
if (getCurrentFragment() == null) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.go_home -> goHome()
|
R.id.go_home -> goHome()
|
||||||
R.id.go_to_favorite -> goToFavorite()
|
R.id.go_to_favorite -> goToFavorite()
|
||||||
|
@ -180,7 +185,7 @@ class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
outState.putString(PICKED_PATH, items_fragment.currentPath)
|
outState.putString(PICKED_PATH, items_fragment?.currentPath ?: "")
|
||||||
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
|
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +232,7 @@ class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String): Boolean {
|
override fun onQueryTextChange(newText: String): Boolean {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
getCurrentFragment()?.searchQueryChanged(newText)
|
getCurrentFragment().searchQueryChanged(newText)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -254,6 +259,7 @@ class MainActivity : SimpleActivity() {
|
||||||
storedFontSize = fontSize
|
storedFontSize = fontSize
|
||||||
storedDateFormat = dateFormat
|
storedDateFormat = dateFormat
|
||||||
storedTimeFormat = context.getTimeFormat()
|
storedTimeFormat = context.getTimeFormat()
|
||||||
|
storedShowTabs = showTabs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,12 +334,10 @@ class MainActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
setupTabColors(tabToOpen)
|
|
||||||
|
|
||||||
main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
if (isSearchOpen) {
|
if (isSearchOpen) {
|
||||||
getCurrentFragment()?.searchQueryChanged("")
|
getCurrentFragment().searchQueryChanged("")
|
||||||
searchMenuItem?.collapseActionView()
|
searchMenuItem?.collapseActionView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -348,6 +352,27 @@ class MainActivity : SimpleActivity() {
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
main_tabs_holder.removeAllTabs()
|
||||||
|
var skippedTabs = 0
|
||||||
|
tabsList.forEachIndexed { index, value ->
|
||||||
|
if (config.showTabs and value == 0) {
|
||||||
|
skippedTabs++
|
||||||
|
} else {
|
||||||
|
val tab = main_tabs_holder.newTab().setIcon(getTabIcon(index))
|
||||||
|
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.onGlobalLayout {
|
||||||
|
Handler().postDelayed({
|
||||||
|
main_tabs_holder.getTabAt(config.lastUsedViewPagerPage)?.select()
|
||||||
|
invalidateOptionsMenu()
|
||||||
|
}, 100L)
|
||||||
|
}
|
||||||
|
|
||||||
|
main_tabs_holder.beVisibleIf(skippedTabs < tabsList.size - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupTabColors(lastUsedTab: Int) {
|
private fun setupTabColors(lastUsedTab: Int) {
|
||||||
|
@ -372,6 +397,15 @@ class MainActivity : SimpleActivity() {
|
||||||
main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
main_tabs_holder.getTabAt(main_view_pager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getTabIcon(position: Int): Drawable {
|
||||||
|
val drawableId = when (position) {
|
||||||
|
0 -> R.drawable.ic_folder_vector
|
||||||
|
else -> R.drawable.ic_clock_vector
|
||||||
|
}
|
||||||
|
|
||||||
|
return resources.getColoredDrawableWithColor(drawableId, config.textColor)
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkOTGPath() {
|
private fun checkOTGPath() {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) {
|
if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) {
|
||||||
|
@ -402,23 +436,23 @@ class MainActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goHome() {
|
private fun goHome() {
|
||||||
if (config.homeFolder != getCurrentFragment()?.currentPath) {
|
if (config.homeFolder != getCurrentFragment().currentPath) {
|
||||||
openPath(config.homeFolder)
|
openPath(config.homeFolder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortingDialog() {
|
private fun showSortingDialog() {
|
||||||
ChangeSortingDialog(this, getCurrentFragment()!!.currentPath) {
|
ChangeSortingDialog(this, getCurrentFragment().currentPath) {
|
||||||
(getCurrentFragment() as? ItemsFragment)?.refreshItems()
|
(getCurrentFragment() as? ItemsFragment)?.refreshItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addFavorite() {
|
private fun addFavorite() {
|
||||||
config.addFavorite(getCurrentFragment()!!.currentPath)
|
config.addFavorite(getCurrentFragment().currentPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeFavorite() {
|
private fun removeFavorite() {
|
||||||
config.removeFavorite(getCurrentFragment()!!.currentPath)
|
config.removeFavorite(getCurrentFragment().currentPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFilenameVisibility() {
|
private fun toggleFilenameVisibility() {
|
||||||
|
@ -448,7 +482,7 @@ class MainActivity : SimpleActivity() {
|
||||||
favorites.forEachIndexed { index, path ->
|
favorites.forEachIndexed { index, path ->
|
||||||
val visiblePath = humanizePath(path).replace("/", " / ")
|
val visiblePath = humanizePath(path).replace("/", " / ")
|
||||||
items.add(RadioItem(index, visiblePath, path))
|
items.add(RadioItem(index, visiblePath, path))
|
||||||
if (path == getCurrentFragment()!!.currentPath) {
|
if (path == getCurrentFragment().currentPath) {
|
||||||
currFavoriteIndex = index
|
currFavoriteIndex = index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,12 +493,12 @@ class MainActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setAsHome() {
|
private fun setAsHome() {
|
||||||
config.homeFolder = getCurrentFragment()!!.currentPath
|
config.homeFolder = getCurrentFragment().currentPath
|
||||||
toast(R.string.home_folder_updated)
|
toast(R.string.home_folder_updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun changeViewType() {
|
private fun changeViewType() {
|
||||||
ChangeViewTypeDialog(this, getCurrentFragment()!!.currentPath, getCurrentFragment() is ItemsFragment) {
|
ChangeViewTypeDialog(this, getCurrentFragment().currentPath, getCurrentFragment() is ItemsFragment) {
|
||||||
getAllFragments().forEach {
|
getAllFragments().forEach {
|
||||||
it?.refreshItems()
|
it?.refreshItems()
|
||||||
}
|
}
|
||||||
|
@ -509,7 +543,7 @@ class MainActivity : SimpleActivity() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getCurrentFragment()!!.breadcrumbs.childCount <= 1) {
|
if (getCurrentFragment().breadcrumbs.childCount <= 1) {
|
||||||
if (!wasBackJustPressed && config.pressBackTwice) {
|
if (!wasBackJustPressed && config.pressBackTwice) {
|
||||||
wasBackJustPressed = true
|
wasBackJustPressed = true
|
||||||
toast(R.string.press_back_again)
|
toast(R.string.press_back_again)
|
||||||
|
@ -520,8 +554,8 @@ class MainActivity : SimpleActivity() {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCurrentFragment()!!.breadcrumbs.removeBreadcrumb()
|
getCurrentFragment().breadcrumbs.removeBreadcrumb()
|
||||||
openPath(getCurrentFragment()!!.breadcrumbs.getLastItem().path)
|
openPath(getCurrentFragment().breadcrumbs.getLastItem().path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,7 +628,19 @@ class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
private fun getAllFragments(): ArrayList<MyViewPagerFragment?> = arrayListOf(items_fragment, recents_fragment)
|
private fun getAllFragments(): ArrayList<MyViewPagerFragment?> = arrayListOf(items_fragment, recents_fragment)
|
||||||
|
|
||||||
private fun getCurrentFragment() = getAllFragments().getOrNull(main_view_pager.currentItem)
|
private fun getCurrentFragment(): MyViewPagerFragment {
|
||||||
|
val showTabs = config.showTabs
|
||||||
|
val fragments = arrayListOf<MyViewPagerFragment>()
|
||||||
|
if (showTabs and TAB_FILES != 0) {
|
||||||
|
fragments.add(items_fragment)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showTabs and TAB_RECENT_FILES != 0) {
|
||||||
|
fragments.add(recents_fragment)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fragments[main_view_pager.currentItem]
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkWhatsNewDialog() {
|
private fun checkWhatsNewDialog() {
|
||||||
arrayListOf<Release>().apply {
|
arrayListOf<Release>().apply {
|
||||||
|
|
|
@ -3,10 +3,13 @@ package com.simplemobiletools.filemanager.pro.adapters
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.viewpager.widget.PagerAdapter
|
import androidx.viewpager.widget.PagerAdapter
|
||||||
|
import com.simplemobiletools.commons.helpers.TAB_FILES
|
||||||
|
import com.simplemobiletools.commons.helpers.TAB_RECENT_FILES
|
||||||
import com.simplemobiletools.filemanager.pro.R
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.config
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
import com.simplemobiletools.filemanager.pro.fragments.MyViewPagerFragment
|
import com.simplemobiletools.filemanager.pro.fragments.MyViewPagerFragment
|
||||||
|
import com.simplemobiletools.filemanager.pro.helpers.tabsList
|
||||||
|
|
||||||
class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
||||||
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
||||||
|
@ -26,12 +29,21 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() {
|
||||||
container.removeView(item as View)
|
container.removeView(item as View)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCount() = 2
|
override fun getCount() = tabsList.filter { it and activity.config.showTabs != 0 }.size
|
||||||
|
|
||||||
override fun isViewFromObject(view: View, item: Any) = view == item
|
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||||
|
|
||||||
private fun getFragment(position: Int): Int {
|
private fun getFragment(position: Int): Int {
|
||||||
val fragments = arrayListOf(R.layout.items_fragment, R.layout.recents_fragment)
|
val showTabs = activity.config.showTabs
|
||||||
|
val fragments = arrayListOf<Int>()
|
||||||
|
if (showTabs and TAB_FILES != 0) {
|
||||||
|
fragments.add(R.layout.items_fragment)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showTabs and TAB_RECENT_FILES != 0) {
|
||||||
|
fragments.add(R.layout.recents_fragment)
|
||||||
|
}
|
||||||
|
|
||||||
return fragments[position]
|
return fragments[position]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@ package com.simplemobiletools.filemanager.pro.dialogs
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.TAB_FILES
|
||||||
|
import com.simplemobiletools.commons.helpers.TAB_RECENT_FILES
|
||||||
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
import com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
import com.simplemobiletools.filemanager.pro.R
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.config
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
|
|
Loading…
Reference in a new issue