From 16d0b2e9e59aa565a9eaeeca76066283857baab1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 Jul 2022 23:07:20 +0200 Subject: [PATCH] do not show the Storage Analysis tab at file picker intent --- .../pro/activities/MainActivity.kt | 21 +++++++++++++++---- .../pro/adapters/ViewPagerAdapter.kt | 5 ++--- .../filemanager/pro/helpers/Constants.kt | 1 - 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index 64b08903..9093ae28 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -39,7 +39,6 @@ import com.simplemobiletools.filemanager.pro.fragments.MyViewPagerFragment import com.simplemobiletools.filemanager.pro.fragments.StorageFragment import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT import com.simplemobiletools.filemanager.pro.helpers.RootHelpers -import com.simplemobiletools.filemanager.pro.helpers.tabsList import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener import com.stericson.RootTools.RootTools import kotlinx.android.synthetic.main.activity_main.* @@ -58,6 +57,7 @@ class MainActivity : SimpleActivity() { private var wasBackJustPressed = false private var mIsPasswordProtectionPending = false private var mWasProtectionHandled = false + private var mTabsToShow = ArrayList() private var searchMenuItem: MenuItem? = null private var storedFontSize = 0 @@ -69,6 +69,7 @@ class MainActivity : SimpleActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) appLaunched(BuildConfig.APPLICATION_ID) + mTabsToShow = getTabsList() if (!config.wasStorageAnalysisTabAdded && isOreoPlus()) { config.wasStorageAnalysisTabAdded = true @@ -381,7 +382,7 @@ class MainActivity : SimpleActivity() { } private fun initFragments() { - main_view_pager.adapter = ViewPagerAdapter(this) + main_view_pager.adapter = ViewPagerAdapter(this, mTabsToShow) main_view_pager.offscreenPageLimit = 2 main_view_pager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { @@ -406,7 +407,17 @@ class MainActivity : SimpleActivity() { private fun setupTabs() { main_tabs_holder.removeAllTabs() - tabsList.forEachIndexed { index, value -> + val isPickFileIntent = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER || intent.action == Intent.ACTION_GET_CONTENT + if (isPickFileIntent) { + mTabsToShow.remove(TAB_STORAGE_ANALYSIS) + if (mTabsToShow.none { it and config.showTabs != 0 }) { + config.showTabs = TAB_FILES + storedShowTabs = TAB_FILES + mTabsToShow = arrayListOf(TAB_FILES) + } + } + + mTabsToShow.forEachIndexed { index, value -> if (config.showTabs and value != 0) { main_tabs_holder.newTab().setCustomView(R.layout.bottom_tablayout_item).apply { customView?.findViewById(R.id.tab_item_icon)?.setImageDrawable(getTabIcon(index)) @@ -702,7 +713,7 @@ class MainActivity : SimpleActivity() { } } - private fun getInactiveTabIndexes(activeIndex: Int) = (0 until tabsList.size).filter { it != activeIndex } + private fun getInactiveTabIndexes(activeIndex: Int) = (0 until getTabsList().size).filter { it != activeIndex } private fun getAllFragments(): ArrayList = arrayListOf(items_fragment, recents_fragment, storage_fragment) @@ -724,6 +735,8 @@ class MainActivity : SimpleActivity() { return fragments.getOrNull(main_view_pager.currentItem) } + private fun getTabsList() = arrayListOf(TAB_FILES, TAB_RECENT_FILES, TAB_STORAGE_ANALYSIS) + private fun checkWhatsNewDialog() { arrayListOf().apply { add(Release(26, R.string.release_26)) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt index c9e27de0..7aad2f83 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ViewPagerAdapter.kt @@ -11,9 +11,8 @@ import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.activities.SimpleActivity import com.simplemobiletools.filemanager.pro.extensions.config 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, val tabsToShow: ArrayList) : PagerAdapter() { override fun instantiateItem(container: ViewGroup, position: Int): Any { val layout = getFragment(position) val view = activity.layoutInflater.inflate(layout, container, false) @@ -31,7 +30,7 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() { container.removeView(item as View) } - override fun getCount() = tabsList.filter { it and activity.config.showTabs != 0 }.size + override fun getCount() = tabsToShow.filter { it and activity.config.showTabs != 0 }.size override fun isViewFromObject(view: View, item: Any) = view == item diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt index 8c6b99df..91f4b669 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Constants.kt @@ -32,7 +32,6 @@ const val OPEN_AS_VIDEO = 4 const val OPEN_AS_OTHER = 5 const val ALL_TABS_MASK = TAB_FILES or TAB_RECENT_FILES or TAB_STORAGE_ANALYSIS -val tabsList = arrayListOf(TAB_FILES, TAB_RECENT_FILES, TAB_STORAGE_ANALYSIS) const val IMAGES = "images" const val VIDEOS = "videos"