Skip to content

Commit 92092b6

Browse files
committed
adding some list/grid viewtype related fixes
1 parent 0c648d4 commit 92092b6

File tree

3 files changed

+76
-15
lines changed

3 files changed

+76
-15
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
3333
private var skipItemUpdating = false
3434
private var isSearchOpen = false
3535
private var lastSearchedText = ""
36-
private var currentViewType = VIEW_TYPE_LIST
3736
private var scrollStates = HashMap<String, Parcelable>()
3837
private var zoomListener: MyRecyclerView.MyZoomListener? = null
3938

@@ -459,13 +458,17 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
459458
}
460459

461460
override fun increaseColumnCount() {
462-
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
463-
columnCountChanged()
461+
if (currentViewType == VIEW_TYPE_GRID) {
462+
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
463+
columnCountChanged()
464+
}
464465
}
465466

466467
override fun reduceColumnCount() {
467-
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
468-
columnCountChanged()
468+
if (currentViewType == VIEW_TYPE_GRID) {
469+
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
470+
columnCountChanged()
471+
}
469472
}
470473

471474
private fun columnCountChanged() {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import android.util.AttributeSet
55
import android.widget.RelativeLayout
66
import com.simplemobiletools.commons.extensions.isAudioFast
77
import com.simplemobiletools.commons.extensions.toast
8+
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
89
import com.simplemobiletools.filemanager.pro.R
910
import com.simplemobiletools.filemanager.pro.activities.MainActivity
1011
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
1112
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
1213

1314
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
1415
protected var activity: SimpleActivity? = null
16+
protected var currentViewType = VIEW_TYPE_LIST
1517

1618
var currentPath = ""
1719
var isGetContentIntent = false

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

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ package com.simplemobiletools.filemanager.pro.fragments
33
import android.content.Context
44
import android.provider.MediaStore
55
import android.util.AttributeSet
6+
import androidx.recyclerview.widget.GridLayoutManager
67
import com.simplemobiletools.commons.extensions.getLongValue
78
import com.simplemobiletools.commons.extensions.getStringValue
9+
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
10+
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
811
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
12+
import com.simplemobiletools.commons.helpers.mydebug
913
import com.simplemobiletools.commons.models.FileDirItem
1014
import com.simplemobiletools.commons.views.MyGridLayoutManager
1115
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
1216
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
1317
import com.simplemobiletools.filemanager.pro.extensions.config
1418
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
1519
import com.simplemobiletools.filemanager.pro.models.ListItem
20+
import kotlinx.android.synthetic.main.items_fragment.view.*
1621
import kotlinx.android.synthetic.main.recents_fragment.view.*
1722
import java.util.*
1823

@@ -30,19 +35,65 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
3035
ensureBackgroundThread {
3136
getRecents { recents ->
3237
recents_swipe_refresh?.isRefreshing = false
33-
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, null, recents_swipe_refresh) {
34-
clickedPath((it as FileDirItem).path)
35-
}.apply {
36-
recents_list.adapter = this
37-
}
38+
addItems(recents, false)
3839

39-
recents_list.scheduleLayoutAnimation()
40+
if (context != null && currentViewType != context!!.config.getFolderViewType(currentPath)) {
41+
setupLayoutManager()
42+
}
4043
}
4144
}
4245
}
4346

47+
private fun addItems(recents: ArrayList<ListItem>, forceRefresh: Boolean) {
48+
if (!forceRefresh && recents.hashCode() == (recents_list.adapter as? ItemsAdapter)?.listItems.hashCode()) {
49+
return
50+
}
51+
52+
ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, null, recents_swipe_refresh) {
53+
clickedPath((it as FileDirItem).path)
54+
}.apply {
55+
recents_list.adapter = this
56+
}
57+
58+
recents_list.scheduleLayoutAnimation()
59+
}
60+
4461
override fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {}
4562

63+
private fun setupLayoutManager() {
64+
if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
65+
currentViewType = VIEW_TYPE_GRID
66+
setupGridLayoutManager()
67+
} else {
68+
currentViewType = VIEW_TYPE_LIST
69+
setupListLayoutManager()
70+
}
71+
72+
val oldItems = (recents_list.adapter as? ItemsAdapter)?.listItems?.toMutableList() as ArrayList<ListItem>
73+
recents_list.adapter = null
74+
addItems(oldItems, true)
75+
}
76+
77+
private fun setupGridLayoutManager() {
78+
val layoutManager = recents_list.layoutManager as MyGridLayoutManager
79+
layoutManager.spanCount = context?.config?.fileColumnCnt ?: 3
80+
81+
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
82+
override fun getSpanSize(position: Int): Int {
83+
return if (getRecyclerAdapter()?.isASectionTitle(position) == true) {
84+
layoutManager.spanCount
85+
} else {
86+
1
87+
}
88+
}
89+
}
90+
}
91+
92+
private fun setupListLayoutManager() {
93+
val layoutManager = recents_list.layoutManager as MyGridLayoutManager
94+
layoutManager.spanCount = 1
95+
}
96+
4697
private fun getRecents(callback: (recents: ArrayList<ListItem>) -> Unit) {
4798
val showHidden = context?.config?.shouldShowHidden ?: return
4899
val uri = MediaStore.Files.getContentUri("external")
@@ -53,7 +104,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
53104
MediaStore.Files.FileColumns.SIZE
54105
)
55106

56-
val sortOrder = "${MediaStore.Files.FileColumns.DATE_MODIFIED} DESC"
107+
val sortOrder = "${MediaStore.Files.FileColumns.DATE_MODIFIED} DESC LIMIT 50"
57108
val cursor = context?.contentResolver?.query(uri, projection, null, null, sortOrder)
58109
val listItems = arrayListOf<ListItem>()
59110

@@ -84,12 +135,17 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
84135
}
85136

86137
override fun increaseColumnCount() {
87-
columnCountChanged()
138+
if (currentViewType == VIEW_TYPE_GRID) {
139+
context?.config?.fileColumnCnt = ++(recents_list.layoutManager as MyGridLayoutManager).spanCount
140+
columnCountChanged()
141+
}
88142
}
89143

90144
override fun reduceColumnCount() {
91-
context?.config?.fileColumnCnt = --(recents_list.layoutManager as MyGridLayoutManager).spanCount
92-
columnCountChanged()
145+
if (currentViewType == VIEW_TYPE_GRID) {
146+
context?.config?.fileColumnCnt = --(recents_list.layoutManager as MyGridLayoutManager).spanCount
147+
columnCountChanged()
148+
}
93149
}
94150

95151
private fun columnCountChanged() {

0 commit comments

Comments
 (0)