Skip to content

Commit

Permalink
adding some list/grid viewtype related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed May 19, 2021
1 parent 0c648d4 commit 92092b6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
private var skipItemUpdating = false
private var isSearchOpen = false
private var lastSearchedText = ""
private var currentViewType = VIEW_TYPE_LIST
private var scrollStates = HashMap<String, Parcelable>()
private var zoomListener: MyRecyclerView.MyZoomListener? = null

Expand Down Expand Up @@ -459,13 +458,17 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
}

override fun increaseColumnCount() {
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
columnCountChanged()
if (currentViewType == VIEW_TYPE_GRID) {
context?.config?.fileColumnCnt = ++(items_list.layoutManager as MyGridLayoutManager).spanCount
columnCountChanged()
}
}

override fun reduceColumnCount() {
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
columnCountChanged()
if (currentViewType == VIEW_TYPE_GRID) {
context?.config?.fileColumnCnt = --(items_list.layoutManager as MyGridLayoutManager).spanCount
columnCountChanged()
}
}

private fun columnCountChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import android.util.AttributeSet
import android.widget.RelativeLayout
import com.simplemobiletools.commons.extensions.isAudioFast
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.activities.MainActivity
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent

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

var currentPath = ""
var isGetContentIntent = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ package com.simplemobiletools.filemanager.pro.fragments
import android.content.Context
import android.provider.MediaStore
import android.util.AttributeSet
import androidx.recyclerview.widget.GridLayoutManager
import com.simplemobiletools.commons.extensions.getLongValue
import com.simplemobiletools.commons.extensions.getStringValue
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.mydebug
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.pro.extensions.config
import com.simplemobiletools.filemanager.pro.interfaces.ItemOperationsListener
import com.simplemobiletools.filemanager.pro.models.ListItem
import kotlinx.android.synthetic.main.items_fragment.view.*
import kotlinx.android.synthetic.main.recents_fragment.view.*
import java.util.*

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

recents_list.scheduleLayoutAnimation()
if (context != null && currentViewType != context!!.config.getFolderViewType(currentPath)) {
setupLayoutManager()
}
}
}
}

private fun addItems(recents: ArrayList<ListItem>, forceRefresh: Boolean) {
if (!forceRefresh && recents.hashCode() == (recents_list.adapter as? ItemsAdapter)?.listItems.hashCode()) {
return
}

ItemsAdapter(activity as SimpleActivity, recents, this, recents_list, isPickMultipleIntent, null, recents_swipe_refresh) {
clickedPath((it as FileDirItem).path)
}.apply {
recents_list.adapter = this
}

recents_list.scheduleLayoutAnimation()
}

override fun setupColors(textColor: Int, adjustedPrimaryColor: Int) {}

private fun setupLayoutManager() {
if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
currentViewType = VIEW_TYPE_GRID
setupGridLayoutManager()
} else {
currentViewType = VIEW_TYPE_LIST
setupListLayoutManager()
}

val oldItems = (recents_list.adapter as? ItemsAdapter)?.listItems?.toMutableList() as ArrayList<ListItem>
recents_list.adapter = null
addItems(oldItems, true)
}

private fun setupGridLayoutManager() {
val layoutManager = recents_list.layoutManager as MyGridLayoutManager
layoutManager.spanCount = context?.config?.fileColumnCnt ?: 3

layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (getRecyclerAdapter()?.isASectionTitle(position) == true) {
layoutManager.spanCount
} else {
1
}
}
}
}

private fun setupListLayoutManager() {
val layoutManager = recents_list.layoutManager as MyGridLayoutManager
layoutManager.spanCount = 1
}

private fun getRecents(callback: (recents: ArrayList<ListItem>) -> Unit) {
val showHidden = context?.config?.shouldShowHidden ?: return
val uri = MediaStore.Files.getContentUri("external")
Expand All @@ -53,7 +104,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
MediaStore.Files.FileColumns.SIZE
)

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

Expand Down Expand Up @@ -84,12 +135,17 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}

override fun increaseColumnCount() {
columnCountChanged()
if (currentViewType == VIEW_TYPE_GRID) {
context?.config?.fileColumnCnt = ++(recents_list.layoutManager as MyGridLayoutManager).spanCount
columnCountChanged()
}
}

override fun reduceColumnCount() {
context?.config?.fileColumnCnt = --(recents_list.layoutManager as MyGridLayoutManager).spanCount
columnCountChanged()
if (currentViewType == VIEW_TYPE_GRID) {
context?.config?.fileColumnCnt = --(recents_list.layoutManager as MyGridLayoutManager).spanCount
columnCountChanged()
}
}

private fun columnCountChanged() {
Expand Down

0 comments on commit 92092b6

Please sign in to comment.