mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
handle some menu items at both tabs
This commit is contained in:
@ -27,6 +27,7 @@ import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog
|
|||||||
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
|
import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.config
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
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.MyViewPagerFragment
|
||||||
import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
|
import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
|
||||||
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
|
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
|
||||||
@ -129,22 +130,22 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
|
||||||
val favorites = config.favorites
|
val favorites = config.favorites
|
||||||
val fragment = getCurrentFragment() ?: return true
|
val currentFragment = getCurrentFragment()
|
||||||
|
|
||||||
menu!!.apply {
|
menu!!.apply {
|
||||||
findItem(R.id.add_favorite).isVisible = !favorites.contains(fragment.currentPath)
|
findItem(R.id.add_favorite).isVisible = !favorites.contains(currentFragment.currentPath)
|
||||||
findItem(R.id.remove_favorite).isVisible = favorites.contains(fragment.currentPath)
|
findItem(R.id.remove_favorite).isVisible = favorites.contains(currentFragment.currentPath)
|
||||||
findItem(R.id.go_to_favorite).isVisible = favorites.isNotEmpty()
|
findItem(R.id.go_to_favorite).isVisible = favorites.isNotEmpty()
|
||||||
|
|
||||||
findItem(R.id.toggle_filename).isVisible = config.getFolderViewType(fragment.currentPath) == VIEW_TYPE_GRID
|
findItem(R.id.toggle_filename).isVisible = config.getFolderViewType(currentFragment.currentPath) == VIEW_TYPE_GRID
|
||||||
findItem(R.id.go_home).isVisible = fragment.currentPath != config.homeFolder
|
findItem(R.id.go_home).isVisible = currentFragment.currentPath != config.homeFolder
|
||||||
findItem(R.id.set_as_home).isVisible = fragment.currentPath != config.homeFolder
|
findItem(R.id.set_as_home).isVisible = currentFragment.currentPath != config.homeFolder
|
||||||
|
|
||||||
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden
|
findItem(R.id.temporarily_show_hidden).isVisible = !config.shouldShowHidden
|
||||||
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden
|
findItem(R.id.stop_showing_hidden).isVisible = config.temporarilyShowHidden
|
||||||
|
|
||||||
findItem(R.id.increase_column_count).isVisible = config.getFolderViewType(fragment.currentPath) == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT
|
findItem(R.id.increase_column_count).isVisible = config.getFolderViewType(currentFragment.currentPath) == VIEW_TYPE_GRID && config.fileColumnCnt < MAX_COLUMN_COUNT
|
||||||
findItem(R.id.reduce_column_count).isVisible = config.getFolderViewType(fragment.currentPath) == VIEW_TYPE_GRID && config.fileColumnCnt > 1
|
findItem(R.id.reduce_column_count).isVisible = config.getFolderViewType(currentFragment.currentPath) == VIEW_TYPE_GRID && config.fileColumnCnt > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -157,13 +158,13 @@ class MainActivity : SimpleActivity() {
|
|||||||
R.id.sort -> showSortingDialog()
|
R.id.sort -> showSortingDialog()
|
||||||
R.id.add_favorite -> addFavorite()
|
R.id.add_favorite -> addFavorite()
|
||||||
R.id.remove_favorite -> removeFavorite()
|
R.id.remove_favorite -> removeFavorite()
|
||||||
R.id.toggle_filename -> getCurrentFragment().toggleFilenameVisibility()
|
R.id.toggle_filename -> toggleFilenameVisibility()
|
||||||
R.id.set_as_home -> setAsHome()
|
R.id.set_as_home -> setAsHome()
|
||||||
R.id.change_view_type -> changeViewType()
|
R.id.change_view_type -> changeViewType()
|
||||||
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
|
R.id.temporarily_show_hidden -> tryToggleTemporarilyShowHidden()
|
||||||
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
|
R.id.stop_showing_hidden -> tryToggleTemporarilyShowHidden()
|
||||||
R.id.increase_column_count -> getCurrentFragment().increaseColumnCount()
|
R.id.increase_column_count -> increaseColumnCount()
|
||||||
R.id.reduce_column_count -> getCurrentFragment().reduceColumnCount()
|
R.id.reduce_column_count -> reduceColumnCount()
|
||||||
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||||
R.id.about -> launchAbout()
|
R.id.about -> launchAbout()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
@ -173,7 +174,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
outState.putString(PICKED_PATH, getCurrentFragment().currentPath)
|
outState.putString(PICKED_PATH, items_fragment.currentPath)
|
||||||
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
|
outState.putBoolean(WAS_PROTECTION_HANDLED, mWasProtectionHandled)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,13 +231,13 @@ class MainActivity : SimpleActivity() {
|
|||||||
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
MenuItemCompat.setOnActionExpandListener(searchMenuItem, object : MenuItemCompat.OnActionExpandListener {
|
||||||
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
|
||||||
isSearchOpen = true
|
isSearchOpen = true
|
||||||
getCurrentFragment().searchOpened()
|
(getCurrentFragment() as? ItemsFragment)?.searchOpened()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
|
||||||
isSearchOpen = false
|
isSearchOpen = false
|
||||||
getCurrentFragment().searchClosed()
|
(getCurrentFragment() as? ItemsFragment)?.searchClosed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -289,10 +290,10 @@ class MainActivity : SimpleActivity() {
|
|||||||
openPath(config.homeFolder)
|
openPath(config.homeFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentFragment()?.apply {
|
getAllFragments().forEach {
|
||||||
isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
|
it?.isGetRingtonePicker = intent.action == RingtoneManager.ACTION_RINGTONE_PICKER
|
||||||
isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT
|
it?.isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT
|
||||||
isPickMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
|
it?.isPickMultipleIntent = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +387,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
newPath = internalStoragePath
|
newPath = internalStoragePath
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentFragment()?.openPath(newPath, forceRefresh)
|
items_fragment?.openPath(newPath, forceRefresh)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goHome() {
|
private fun goHome() {
|
||||||
@ -397,7 +398,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun showSortingDialog() {
|
private fun showSortingDialog() {
|
||||||
ChangeSortingDialog(this, getCurrentFragment().currentPath) {
|
ChangeSortingDialog(this, getCurrentFragment().currentPath) {
|
||||||
getCurrentFragment().refreshItems()
|
(getCurrentFragment() as? ItemsFragment)?.refreshItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,6 +410,24 @@ class MainActivity : SimpleActivity() {
|
|||||||
config.removeFavorite(getCurrentFragment().currentPath)
|
config.removeFavorite(getCurrentFragment().currentPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun toggleFilenameVisibility() {
|
||||||
|
getAllFragments().forEach {
|
||||||
|
it?.toggleFilenameVisibility()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun increaseColumnCount() {
|
||||||
|
getAllFragments().forEach {
|
||||||
|
it?.increaseColumnCount()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun reduceColumnCount() {
|
||||||
|
getAllFragments().forEach {
|
||||||
|
it?.reduceColumnCount()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun goToFavorite() {
|
private fun goToFavorite() {
|
||||||
val favorites = config.favorites
|
val favorites = config.favorites
|
||||||
val items = ArrayList<RadioItem>(favorites.size)
|
val items = ArrayList<RadioItem>(favorites.size)
|
||||||
@ -469,7 +488,12 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if (getCurrentFragment().breadcrumbs.childCount <= 1) {
|
if (getCurrentFragment() !is ItemsFragment) {
|
||||||
|
super.onBackPressed()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getCurrentFragment().breadcrumbs.childCount ?: 2 <= 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)
|
||||||
@ -554,7 +578,10 @@ 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() = items_fragment
|
private fun getCurrentFragment(): MyViewPagerFragment = when (main_view_pager.currentItem) {
|
||||||
|
TAB_FILES -> items_fragment
|
||||||
|
else -> recents_fragment
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkWhatsNewDialog() {
|
private fun checkWhatsNewDialog() {
|
||||||
arrayListOf<Release>().apply {
|
arrayListOf<Release>().apply {
|
||||||
|
@ -30,11 +30,6 @@ import java.util.*
|
|||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
|
class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
|
||||||
var currentPath = ""
|
|
||||||
var isGetContentIntent = false
|
|
||||||
var isGetRingtonePicker = false
|
|
||||||
var isPickMultipleIntent = false
|
|
||||||
|
|
||||||
private var activity: SimpleActivity? = null
|
private var activity: SimpleActivity? = null
|
||||||
private var showHidden = false
|
private var showHidden = false
|
||||||
private var skipItemUpdating = false
|
private var skipItemUpdating = false
|
||||||
@ -476,12 +471,12 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
|
items_fastscroller.setScrollToY(items_list.computeVerticalScrollOffset())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun increaseColumnCount() {
|
override fun increaseColumnCount() {
|
||||||
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
|
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
|
||||||
columnCountChanged()
|
columnCountChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reduceColumnCount() {
|
override fun reduceColumnCount() {
|
||||||
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
|
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
|
||||||
columnCountChanged()
|
columnCountChanged()
|
||||||
}
|
}
|
||||||
@ -494,7 +489,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleFilenameVisibility() {
|
override fun toggleFilenameVisibility() {
|
||||||
context?.config?.displayFilenames = !context!!.config.displayFilenames
|
context?.config?.displayFilenames = !context!!.config.displayFilenames
|
||||||
getRecyclerAdapter()?.updateDisplayFilenamesInGrid()
|
getRecyclerAdapter()?.updateDisplayFilenamesInGrid()
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,11 @@ import android.widget.RelativeLayout
|
|||||||
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
||||||
|
|
||||||
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
|
||||||
|
var currentPath = ""
|
||||||
|
var isGetContentIntent = false
|
||||||
|
var isGetRingtonePicker = false
|
||||||
|
var isPickMultipleIntent = false
|
||||||
|
|
||||||
abstract fun setupFragment(activity: SimpleActivity)
|
abstract fun setupFragment(activity: SimpleActivity)
|
||||||
|
|
||||||
abstract fun setupColors(textColor: Int, adjustedPrimaryColor: Int)
|
abstract fun setupColors(textColor: Int, adjustedPrimaryColor: Int)
|
||||||
@ -17,4 +22,12 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
abstract fun searchQueryChanged(text: String)
|
abstract fun searchQueryChanged(text: String)
|
||||||
|
|
||||||
abstract fun finishActMode()
|
abstract fun finishActMode()
|
||||||
|
|
||||||
|
abstract fun toggleFilenameVisibility()
|
||||||
|
|
||||||
|
abstract fun increaseColumnCount()
|
||||||
|
|
||||||
|
abstract fun reduceColumnCount()
|
||||||
|
|
||||||
|
abstract fun refreshItems()
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,10 @@ import com.simplemobiletools.commons.extensions.getLongValue
|
|||||||
import com.simplemobiletools.commons.extensions.getStringValue
|
import com.simplemobiletools.commons.extensions.getStringValue
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
|
import com.simplemobiletools.commons.views.MyGridLayoutManager
|
||||||
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
|
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
|
||||||
|
import com.simplemobiletools.filemanager.pro.extensions.config
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
|
||||||
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
|
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
|
||||||
import com.simplemobiletools.filemanager.pro.models.ListItem
|
import com.simplemobiletools.filemanager.pro.models.ListItem
|
||||||
@ -19,14 +21,25 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||||||
private var activity: SimpleActivity? = null
|
private var activity: SimpleActivity? = null
|
||||||
|
|
||||||
override fun setupFragment(activity: SimpleActivity) {
|
override fun setupFragment(activity: SimpleActivity) {
|
||||||
this.activity = activity
|
if (this.activity == null) {
|
||||||
|
this.activity = activity
|
||||||
|
recents_swipe_refresh.setOnRefreshListener { refreshItems() }
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshItems()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun refreshItems() {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
getRecents { recents ->
|
getRecents { recents ->
|
||||||
ItemsAdapter(activity, recents, this, recents_list, false, null, recents_swipe_refresh) {
|
recents_swipe_refresh?.isRefreshing = false
|
||||||
activity.tryOpenPathIntent((it as FileDirItem).path, false)
|
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, false, null, recents_swipe_refresh) {
|
||||||
|
activity?.tryOpenPathIntent((it as FileDirItem).path, false)
|
||||||
}.apply {
|
}.apply {
|
||||||
recents_list.adapter = this
|
recents_list.adapter = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recents_list.scheduleLayoutAnimation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +79,27 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||||||
|
|
||||||
private fun getRecyclerAdapter() = recents_list.adapter as? ItemsAdapter
|
private fun getRecyclerAdapter() = recents_list.adapter as? ItemsAdapter
|
||||||
|
|
||||||
override fun refreshItems() {}
|
override fun toggleFilenameVisibility() {
|
||||||
|
context?.config?.displayFilenames = !context!!.config.displayFilenames
|
||||||
|
getRecyclerAdapter()?.updateDisplayFilenamesInGrid()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun increaseColumnCount() {
|
||||||
|
context?.config?.fileColumnCnt = ++(recents_list.layoutManager as MyGridLayoutManager).spanCount
|
||||||
|
columnCountChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reduceColumnCount() {
|
||||||
|
context?.config?.fileColumnCnt = --(recents_list.layoutManager as MyGridLayoutManager).spanCount
|
||||||
|
columnCountChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun columnCountChanged() {
|
||||||
|
activity?.invalidateOptionsMenu()
|
||||||
|
getRecyclerAdapter()?.apply {
|
||||||
|
notifyItemRangeChanged(0, listItems.size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun deleteFiles(files: ArrayList<FileDirItem>) {}
|
override fun deleteFiles(files: ArrayList<FileDirItem>) {}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user