mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	allow changing Recents fragments column count with zoom gestures too
This commit is contained in:
		| @@ -583,6 +583,12 @@ class MainActivity : SimpleActivity() { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fun updateFragmentColumnCounts() { | ||||||
|  |         getAllFragments().forEach { | ||||||
|  |             (it as? ItemOperationsListener)?.columnCountChanged() | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     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) | ||||||
|   | |||||||
| @@ -182,14 +182,14 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun increaseColumnCount() { |     fun increaseColumnCount() { | ||||||
|         if (currentViewType == VIEW_TYPE_GRID) { |         if (currentViewType == VIEW_TYPE_GRID) { | ||||||
|             config.fileColumnCnt += 1 |             config.fileColumnCnt += 1 | ||||||
|             columnCountChanged() |             columnCountChanged() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun reduceColumnCount() { |     fun reduceColumnCount() { | ||||||
|         if (currentViewType == VIEW_TYPE_GRID) { |         if (currentViewType == VIEW_TYPE_GRID) { | ||||||
|             config.fileColumnCnt -= 1 |             config.fileColumnCnt -= 1 | ||||||
|             columnCountChanged() |             columnCountChanged() | ||||||
|   | |||||||
| @@ -486,17 +486,17 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun increaseColumnCount() { |     private fun increaseColumnCount() { | ||||||
|         if (currentViewType == VIEW_TYPE_GRID) { |         if (currentViewType == VIEW_TYPE_GRID) { | ||||||
|             context!!.config.fileColumnCnt += 1 |             context!!.config.fileColumnCnt += 1 | ||||||
|             columnCountChanged() |             (activity as? MainActivity)?.updateFragmentColumnCounts() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun reduceColumnCount() { |     private fun reduceColumnCount() { | ||||||
|         if (currentViewType == VIEW_TYPE_GRID) { |         if (currentViewType == VIEW_TYPE_GRID) { | ||||||
|             context!!.config.fileColumnCnt -= 1 |             context!!.config.fileColumnCnt -= 1 | ||||||
|             columnCountChanged() |             (activity as? MainActivity)?.updateFragmentColumnCounts() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,12 +14,14 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread | |||||||
| import com.simplemobiletools.commons.helpers.isOreoPlus | import com.simplemobiletools.commons.helpers.isOreoPlus | ||||||
| import com.simplemobiletools.commons.models.FileDirItem | import com.simplemobiletools.commons.models.FileDirItem | ||||||
| import com.simplemobiletools.commons.views.MyGridLayoutManager | import com.simplemobiletools.commons.views.MyGridLayoutManager | ||||||
|  | import com.simplemobiletools.commons.views.MyRecyclerView | ||||||
| import com.simplemobiletools.filemanager.pro.R | import com.simplemobiletools.filemanager.pro.R | ||||||
| import com.simplemobiletools.filemanager.pro.activities.MainActivity | import com.simplemobiletools.filemanager.pro.activities.MainActivity | ||||||
| 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.config | ||||||
| import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot | import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot | ||||||
|  | import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT | ||||||
| import com.simplemobiletools.filemanager.pro.helpers.RootHelpers | import com.simplemobiletools.filemanager.pro.helpers.RootHelpers | ||||||
| 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 | ||||||
| @@ -30,6 +32,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage | |||||||
|     private val RECENTS_LIMIT = 50 |     private val RECENTS_LIMIT = 50 | ||||||
|     private var filesIgnoringSearch = ArrayList<ListItem>() |     private var filesIgnoringSearch = ArrayList<ListItem>() | ||||||
|     private var lastSearchedText = "" |     private var lastSearchedText = "" | ||||||
|  |     private var zoomListener: MyRecyclerView.MyZoomListener? = null | ||||||
|  |  | ||||||
|     override fun setupFragment(activity: SimpleActivity) { |     override fun setupFragment(activity: SimpleActivity) { | ||||||
|         if (this.activity == null) { |         if (this.activity == null) { | ||||||
| @@ -64,6 +67,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage | |||||||
|         ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, recents_swipe_refresh, false) { |         ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, recents_swipe_refresh, false) { | ||||||
|             clickedPath((it as FileDirItem).path) |             clickedPath((it as FileDirItem).path) | ||||||
|         }.apply { |         }.apply { | ||||||
|  |             setupZoomListener(zoomListener) | ||||||
|             recents_list.adapter = this |             recents_list.adapter = this | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -95,6 +99,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage | |||||||
|  |  | ||||||
|         val oldItems = (recents_list.adapter as? ItemsAdapter)?.listItems?.toMutableList() as ArrayList<ListItem> |         val oldItems = (recents_list.adapter as? ItemsAdapter)?.listItems?.toMutableList() as ArrayList<ListItem> | ||||||
|         recents_list.adapter = null |         recents_list.adapter = null | ||||||
|  |         initZoomListener() | ||||||
|         addItems(oldItems, true) |         addItems(oldItems, true) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -116,6 +121,30 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage | |||||||
|     private fun setupListLayoutManager() { |     private fun setupListLayoutManager() { | ||||||
|         val layoutManager = recents_list.layoutManager as MyGridLayoutManager |         val layoutManager = recents_list.layoutManager as MyGridLayoutManager | ||||||
|         layoutManager.spanCount = 1 |         layoutManager.spanCount = 1 | ||||||
|  |         zoomListener = null | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private fun initZoomListener() { | ||||||
|  |         if (context?.config?.getFolderViewType(currentPath) == VIEW_TYPE_GRID) { | ||||||
|  |             val layoutManager = recents_list.layoutManager as MyGridLayoutManager | ||||||
|  |             zoomListener = object : MyRecyclerView.MyZoomListener { | ||||||
|  |                 override fun zoomIn() { | ||||||
|  |                     if (layoutManager.spanCount > 1) { | ||||||
|  |                         reduceColumnCount() | ||||||
|  |                         getRecyclerAdapter()?.finishActMode() | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 override fun zoomOut() { | ||||||
|  |                     if (layoutManager.spanCount < MAX_COLUMN_COUNT) { | ||||||
|  |                         increaseColumnCount() | ||||||
|  |                         getRecyclerAdapter()?.finishActMode() | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             zoomListener = null | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun getRecents(callback: (recents: ArrayList<ListItem>) -> Unit) { |     private fun getRecents(callback: (recents: ArrayList<ListItem>) -> Unit) { | ||||||
| @@ -176,17 +205,17 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage | |||||||
|         getRecyclerAdapter()?.updateDisplayFilenamesInGrid() |         getRecyclerAdapter()?.updateDisplayFilenamesInGrid() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun increaseColumnCount() { |     private fun increaseColumnCount() { | ||||||
|         if (currentViewType == VIEW_TYPE_GRID) { |         if (currentViewType == VIEW_TYPE_GRID) { | ||||||
|             context!!.config.fileColumnCnt += 1 |             context!!.config.fileColumnCnt += 1 | ||||||
|             columnCountChanged() |             (activity as? MainActivity)?.updateFragmentColumnCounts() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun reduceColumnCount() { |     private fun reduceColumnCount() { | ||||||
|         if (currentViewType == VIEW_TYPE_GRID) { |         if (currentViewType == VIEW_TYPE_GRID) { | ||||||
|             context!!.config.fileColumnCnt -= 1 |             context!!.config.fileColumnCnt -= 1 | ||||||
|             columnCountChanged() |             (activity as? MainActivity)?.updateFragmentColumnCounts() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,7 +1,6 @@ | |||||||
| package com.simplemobiletools.filemanager.pro.interfaces | package com.simplemobiletools.filemanager.pro.interfaces | ||||||
|  |  | ||||||
| import com.simplemobiletools.commons.models.FileDirItem | import com.simplemobiletools.commons.models.FileDirItem | ||||||
| import java.util.* |  | ||||||
|  |  | ||||||
| interface ItemOperationsListener { | interface ItemOperationsListener { | ||||||
|     fun refreshFragment() |     fun refreshFragment() | ||||||
| @@ -20,9 +19,5 @@ interface ItemOperationsListener { | |||||||
|  |  | ||||||
|     fun columnCountChanged() |     fun columnCountChanged() | ||||||
|  |  | ||||||
|     fun increaseColumnCount() |  | ||||||
|  |  | ||||||
|     fun reduceColumnCount() |  | ||||||
|  |  | ||||||
|     fun finishActMode() |     fun finishActMode() | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user