toggle between list and grid view as needed

This commit is contained in:
tibbi 2020-10-29 20:43:24 +01:00
parent c80b981a51
commit 34edd70b99
3 changed files with 29 additions and 4 deletions

View File

@ -285,7 +285,7 @@ class MainActivity : SimpleActivity() {
private fun changeViewType() {
ChangeViewTypeDialog(this, fragment.currentPath) {
fragment.setupLayoutManager(true)
}
}

View File

@ -10,11 +10,12 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isRPlus
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.Breadcrumbs
import com.simplemobiletools.commons.views.MyLinearLayoutManager
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.activities.MainActivity
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
@ -67,6 +68,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
breadcrumbs.listener = this@ItemsFragment
breadcrumbs.updateFontSize(context!!.getTextSize())
}
setupLayoutManager(false)
}
override fun onSaveInstanceState(outState: Bundle) {
@ -189,7 +191,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
private fun getScrollState() = getRecyclerLayoutManager().onSaveInstanceState()
private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as MyLinearLayoutManager)
private fun getRecyclerLayoutManager() = (mView.items_list.layoutManager as MyGridLayoutManager)
private fun getItems(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
skipItemUpdating = false
@ -404,6 +406,29 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
private fun getRecyclerAdapter() = mView.items_list.adapter as? ItemsAdapter
fun setupLayoutManager(resetAdapter: Boolean) {
if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
setupGridLayoutManager()
} else {
setupListLayoutManager()
}
if (resetAdapter) {
mView.items_list.adapter = null
addItems(storedItems, true)
}
}
private fun setupGridLayoutManager() {
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
layoutManager.spanCount = 3
}
private fun setupListLayoutManager() {
val layoutManager = mView.items_list.layoutManager as MyGridLayoutManager
layoutManager.spanCount = 1
}
override fun breadcrumbClicked(id: Int) {
if (id == 0) {
StoragePickerDialog(activity as SimpleActivity, currentPath, true) {

View File

@ -58,7 +58,7 @@
android:layout_below="@+id/breadcrumbs"
android:clipToPadding="false"
android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager" />
<com.simplemobiletools.commons.views.FastScroller
android:id="@+id/items_fastscroller"