From f750539695a303b99335f2748f9a37bb354cfc64 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 11 Oct 2021 21:08:31 +0200 Subject: [PATCH] adding the storage tab at the viewpager --- .../filemanager/pro/activities/MainActivity.kt | 14 +++++++++++--- .../filemanager/pro/adapters/ViewPagerAdapter.kt | 5 +++++ .../filemanager/pro/helpers/Constants.kt | 5 +++-- app/src/main/res/drawable/ic_storage_vector.xml | 9 +++++++++ app/src/main/res/layout/storage_fragment.xml | 7 +++++++ 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/ic_storage_vector.xml create mode 100644 app/src/main/res/layout/storage_fragment.xml 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 e191c4c3..c8fa1001 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 @@ -30,6 +30,7 @@ import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent import com.simplemobiletools.filemanager.pro.fragments.ItemsFragment 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 @@ -39,6 +40,7 @@ import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.items_fragment.* import kotlinx.android.synthetic.main.items_fragment.view.* import kotlinx.android.synthetic.main.recents_fragment.* +import kotlinx.android.synthetic.main.storage_fragment.* import java.io.File import java.util.* @@ -151,6 +153,7 @@ class MainActivity : SimpleActivity() { menu!!.apply { findItem(R.id.search).isVisible = currentFragment is ItemsFragment findItem(R.id.sort).isVisible = currentFragment is ItemsFragment + findItem(R.id.change_view_type).isVisible = currentFragment !is StorageFragment findItem(R.id.add_favorite).isVisible = currentFragment is ItemsFragment && !favorites.contains(currentFragment.currentPath) findItem(R.id.remove_favorite).isVisible = currentFragment is ItemsFragment && favorites.contains(currentFragment.currentPath) @@ -160,7 +163,7 @@ class MainActivity : SimpleActivity() { findItem(R.id.go_home).isVisible = currentFragment is ItemsFragment && currentFragment.currentPath != config.homeFolder findItem(R.id.set_as_home).isVisible = currentFragment is ItemsFragment && currentFragment.currentPath != config.homeFolder - findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden + findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden && currentFragment !is StorageFragment findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden findItem(R.id.increase_column_count).isVisible = currentViewType == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT @@ -412,7 +415,8 @@ class MainActivity : SimpleActivity() { private fun getTabIcon(position: Int): Drawable { val drawableId = when (position) { 0 -> R.drawable.ic_folder_vector - else -> R.drawable.ic_clock_vector + 1 -> R.drawable.ic_clock_vector + else -> R.drawable.ic_storage_vector } return resources.getColoredDrawableWithColor(drawableId, config.textColor) @@ -638,7 +642,7 @@ class MainActivity : SimpleActivity() { private fun getInactiveTabIndexes(activeIndex: Int) = (0 until tabsList.size).filter { it != activeIndex } - private fun getAllFragments(): ArrayList = arrayListOf(items_fragment, recents_fragment) + private fun getAllFragments(): ArrayList = arrayListOf(items_fragment, recents_fragment, storage_fragment) private fun getCurrentFragment(): MyViewPagerFragment? { val showTabs = config.showTabs @@ -651,6 +655,10 @@ class MainActivity : SimpleActivity() { fragments.add(recents_fragment) } + if (showTabs and TAB_STORAGE_ANALYSIS != 0) { + fragments.add(storage_fragment) + } + return fragments.getOrNull(main_view_pager.currentItem) } 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 e0158b82..36ced7d7 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 @@ -5,6 +5,7 @@ import android.view.ViewGroup import androidx.viewpager.widget.PagerAdapter import com.simplemobiletools.commons.helpers.TAB_FILES import com.simplemobiletools.commons.helpers.TAB_RECENT_FILES +import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.activities.SimpleActivity import com.simplemobiletools.filemanager.pro.extensions.config @@ -44,6 +45,10 @@ class ViewPagerAdapter(val activity: SimpleActivity) : PagerAdapter() { fragments.add(R.layout.recents_fragment) } + if (showTabs and TAB_STORAGE_ANALYSIS != 0) { + fragments.add(R.layout.storage_fragment) + } + return fragments[position] } } 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 784d2992..72f7acb7 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 @@ -2,6 +2,7 @@ package com.simplemobiletools.filemanager.pro.helpers import com.simplemobiletools.commons.helpers.TAB_FILES import com.simplemobiletools.commons.helpers.TAB_RECENT_FILES +import com.simplemobiletools.commons.helpers.TAB_STORAGE_ANALYSIS const val PATH = "path" const val MAX_COLUMN_COUNT = 20 @@ -30,5 +31,5 @@ const val OPEN_AS_AUDIO = 3 const val OPEN_AS_VIDEO = 4 const val OPEN_AS_OTHER = 5 -const val ALL_TABS_MASK = TAB_FILES or TAB_RECENT_FILES -val tabsList = arrayListOf(TAB_FILES, TAB_RECENT_FILES) +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) diff --git a/app/src/main/res/drawable/ic_storage_vector.xml b/app/src/main/res/drawable/ic_storage_vector.xml new file mode 100644 index 00000000..80565aae --- /dev/null +++ b/app/src/main/res/drawable/ic_storage_vector.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/storage_fragment.xml b/app/src/main/res/layout/storage_fragment.xml new file mode 100644 index 00000000..f4393f42 --- /dev/null +++ b/app/src/main/res/layout/storage_fragment.xml @@ -0,0 +1,7 @@ + + + +