Skip to content

Commit ebd65dd

Browse files
committed
allow changing Recents fragments column count with zoom gestures too
1 parent 51c3810 commit ebd65dd

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,12 @@ class MainActivity : SimpleActivity() {
583583
}
584584
}
585585

586+
fun updateFragmentColumnCounts() {
587+
getAllFragments().forEach {
588+
(it as? ItemOperationsListener)?.columnCountChanged()
589+
}
590+
}
591+
586592
private fun goToFavorite() {
587593
val favorites = config.favorites
588594
val items = ArrayList<RadioItem>(favorites.size)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ class MimeTypesActivity : SimpleActivity(), ItemOperationsListener {
182182
}
183183
}
184184

185-
override fun increaseColumnCount() {
185+
fun increaseColumnCount() {
186186
if (currentViewType == VIEW_TYPE_GRID) {
187187
config.fileColumnCnt += 1
188188
columnCountChanged()
189189
}
190190
}
191191

192-
override fun reduceColumnCount() {
192+
fun reduceColumnCount() {
193193
if (currentViewType == VIEW_TYPE_GRID) {
194194
config.fileColumnCnt -= 1
195195
columnCountChanged()

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,17 +486,17 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
486486
}
487487
}
488488

489-
override fun increaseColumnCount() {
489+
private fun increaseColumnCount() {
490490
if (currentViewType == VIEW_TYPE_GRID) {
491491
context!!.config.fileColumnCnt += 1
492-
columnCountChanged()
492+
(activity as? MainActivity)?.updateFragmentColumnCounts()
493493
}
494494
}
495495

496-
override fun reduceColumnCount() {
496+
private fun reduceColumnCount() {
497497
if (currentViewType == VIEW_TYPE_GRID) {
498498
context!!.config.fileColumnCnt -= 1
499-
columnCountChanged()
499+
(activity as? MainActivity)?.updateFragmentColumnCounts()
500500
}
501501
}
502502

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import com.simplemobiletools.commons.helpers.ensureBackgroundThread
1414
import com.simplemobiletools.commons.helpers.isOreoPlus
1515
import com.simplemobiletools.commons.models.FileDirItem
1616
import com.simplemobiletools.commons.views.MyGridLayoutManager
17+
import com.simplemobiletools.commons.views.MyRecyclerView
1718
import com.simplemobiletools.filemanager.pro.R
1819
import com.simplemobiletools.filemanager.pro.activities.MainActivity
1920
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
2021
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
2122
import com.simplemobiletools.filemanager.pro.extensions.config
2223
import com.simplemobiletools.filemanager.pro.extensions.isPathOnRoot
24+
import com.simplemobiletools.filemanager.pro.helpers.MAX_COLUMN_COUNT
2325
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
2426
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
2527
import com.simplemobiletools.filemanager.pro.models.ListItem
@@ -30,6 +32,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
3032
private val RECENTS_LIMIT = 50
3133
private var filesIgnoringSearch = ArrayList<ListItem>()
3234
private var lastSearchedText = ""
35+
private var zoomListener: MyRecyclerView.MyZoomListener? = null
3336

3437
override fun setupFragment(activity: SimpleActivity) {
3538
if (this.activity == null) {
@@ -64,6 +67,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
6467
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, recents_swipe_refresh, false) {
6568
clickedPath((it as FileDirItem).path)
6669
}.apply {
70+
setupZoomListener(zoomListener)
6771
recents_list.adapter = this
6872
}
6973

@@ -95,6 +99,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
9599

96100
val oldItems = (recents_list.adapter as? ItemsAdapter)?.listItems?.toMutableList() as ArrayList<ListItem>
97101
recents_list.adapter = null
102+
initZoomListener()
98103
addItems(oldItems, true)
99104
}
100105

@@ -116,6 +121,30 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
116121
private fun setupListLayoutManager() {
117122
val layoutManager = recents_list.layoutManager as MyGridLayoutManager
118123
layoutManager.spanCount = 1
124+
zoomListener = null
125+
}
126+
127+
private fun initZoomListener() {
128+
if (context?.config?.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
129+
val layoutManager = recents_list.layoutManager as MyGridLayoutManager
130+
zoomListener = object : MyRecyclerView.MyZoomListener {
131+
override fun zoomIn() {
132+
if (layoutManager.spanCount > 1) {
133+
reduceColumnCount()
134+
getRecyclerAdapter()?.finishActMode()
135+
}
136+
}
137+
138+
override fun zoomOut() {
139+
if (layoutManager.spanCount < MAX_COLUMN_COUNT) {
140+
increaseColumnCount()
141+
getRecyclerAdapter()?.finishActMode()
142+
}
143+
}
144+
}
145+
} else {
146+
zoomListener = null
147+
}
119148
}
120149

121150
private fun getRecents(callback: (recents: ArrayList<ListItem>) -> Unit) {
@@ -176,17 +205,17 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
176205
getRecyclerAdapter()?.updateDisplayFilenamesInGrid()
177206
}
178207

179-
override fun increaseColumnCount() {
208+
private fun increaseColumnCount() {
180209
if (currentViewType == VIEW_TYPE_GRID) {
181210
context!!.config.fileColumnCnt += 1
182-
columnCountChanged()
211+
(activity as? MainActivity)?.updateFragmentColumnCounts()
183212
}
184213
}
185214

186-
override fun reduceColumnCount() {
215+
private fun reduceColumnCount() {
187216
if (currentViewType == VIEW_TYPE_GRID) {
188217
context!!.config.fileColumnCnt -= 1
189-
columnCountChanged()
218+
(activity as? MainActivity)?.updateFragmentColumnCounts()
190219
}
191220
}
192221

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/interfaces/ItemOperationsListener.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.simplemobiletools.filemanager.pro.interfaces
22

33
import com.simplemobiletools.commons.models.FileDirItem
4-
import java.util.*
54

65
interface ItemOperationsListener {
76
fun refreshFragment()
@@ -20,9 +19,5 @@ interface ItemOperationsListener {
2019

2120
fun columnCountChanged()
2221

23-
fun increaseColumnCount()
24-
25-
fun reduceColumnCount()
26-
2722
fun finishActMode()
2823
}

0 commit comments

Comments
 (0)