handle column count changing etc at the storage fragment

This commit is contained in:
tibbi 2023-01-07 20:39:22 +01:00
parent 4128936d72
commit b850c19205
4 changed files with 82 additions and 64 deletions

View File

@ -538,22 +538,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
override fun deleteFiles(files: ArrayList<FileDirItem>) {
val hasFolder = files.any { it.isDirectory }
val firstPath = files.firstOrNull()?.path
if (firstPath == null || firstPath.isEmpty() || context == null) {
return
}
if (context!!.isPathOnRoot(firstPath)) {
RootHelpers(activity!!).deleteFiles(files)
} else {
(activity as SimpleActivity).deleteFiles(files, hasFolder) {
if (!it) {
activity!!.runOnUiThread {
activity!!.toast(R.string.unknown_error_occurred)
}
}
}
}
handleFileDeleting(files, hasFolder)
}
override fun selectedPaths(paths: ArrayList<String>) {

View File

@ -5,10 +5,13 @@ import android.util.AttributeSet
import android.widget.RelativeLayout
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.commons.models.FileDirItem
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.isPathOnRoot
import com.simplemobiletools.filemanager.pro.extensions.tryOpenPathIntent
import com.simplemobiletools.filemanager.pro.helpers.RootHelpers
import kotlinx.android.synthetic.main.items_fragment.view.*
abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet) {
@ -48,6 +51,25 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
items_fab?.setImageDrawable(fabIcon)
}
fun handleFileDeleting(files: ArrayList<FileDirItem>, hasFolder: Boolean) {
val firstPath = files.firstOrNull()?.path
if (firstPath == null || firstPath.isEmpty() || context == null) {
return
}
if (context!!.isPathOnRoot(firstPath)) {
RootHelpers(activity!!).deleteFiles(files)
} else {
(activity as SimpleActivity).deleteFiles(files, hasFolder) {
if (!it) {
activity!!.runOnUiThread {
activity!!.toast(R.string.unknown_error_occurred)
}
}
}
}
}
protected fun isProperMimeType(wantedMimeType: String, path: String, isDirectory: Boolean): Boolean {
return if (wantedMimeType.isEmpty() || wantedMimeType == "*/*" || isDirectory) {
true

View File

@ -6,7 +6,6 @@ import android.provider.MediaStore.Files
import android.provider.MediaStore.Files.FileColumns
import android.util.AttributeSet
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.GridLayoutManager
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
@ -15,14 +14,11 @@ import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.commons.views.MyRecyclerView
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.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.pro.extensions.config
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.interfaces.ItemOperationsListener
import com.simplemobiletools.filemanager.pro.models.ListItem
import kotlinx.android.synthetic.main.recents_fragment.view.*
@ -52,7 +48,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
filesIgnoringSearch = recents
addItems(recents, false)
if (context != null && currentViewType != context!!.config.getFolderViewType(currentPath)) {
if (context != null && currentViewType != context!!.config.getFolderViewType("")) {
setupLayoutManager()
}
}
@ -89,7 +85,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
private fun setupLayoutManager() {
if (context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
if (context!!.config.getFolderViewType("") == VIEW_TYPE_GRID) {
currentViewType = VIEW_TYPE_GRID
setupGridLayoutManager()
} else {
@ -106,16 +102,6 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
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() {
@ -125,7 +111,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
private fun initZoomListener() {
if (context?.config?.getFolderViewType(currentPath) == VIEW_TYPE_GRID) {
if (context?.config?.getFolderViewType("") == VIEW_TYPE_GRID) {
val layoutManager = recents_list.layoutManager as MyGridLayoutManager
zoomListener = object : MyRecyclerView.MyZoomListener {
override fun zoomIn() {
@ -240,22 +226,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
override fun deleteFiles(files: ArrayList<FileDirItem>) {
val firstPath = files.firstOrNull()?.path
if (firstPath == null || firstPath.isEmpty() || context == null) {
return
}
if (context!!.isPathOnRoot(firstPath)) {
RootHelpers(activity!!).deleteFiles(files)
} else {
(activity as SimpleActivity).deleteFiles(files, false) {
if (!it) {
activity!!.runOnUiThread {
activity!!.toast(R.string.unknown_error_occurred)
}
}
}
}
handleFileDeleting(files, false)
}
override fun searchQueryChanged(text: String) {

View File

@ -13,11 +13,9 @@ import android.util.AttributeSet
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.LOWER_ALPHA
import com.simplemobiletools.commons.helpers.SHORT_ANIMATION_DURATION
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.activities.MimeTypesActivity
import com.simplemobiletools.filemanager.pro.activities.SimpleActivity
@ -59,9 +57,7 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
others_holder.setOnClickListener { launchMimetypeActivity(OTHERS) }
Handler().postDelayed({
val fileDirItems = getAllFiles()
allDeviceListItems = getListItemsFromFileDirItems(fileDirItems)
setupSearchResultsAdapter()
refreshFragment()
}, 2000)
}
@ -261,7 +257,30 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
}
private fun setupSearchResultsAdapter() {
private fun setupLayoutManager() {
if (context!!.config.getFolderViewType("") == VIEW_TYPE_GRID) {
currentViewType = VIEW_TYPE_GRID
setupGridLayoutManager()
} else {
currentViewType = VIEW_TYPE_LIST
setupListLayoutManager()
}
search_results_list.adapter = null
addItems()
}
private fun setupGridLayoutManager() {
val layoutManager = search_results_list.layoutManager as MyGridLayoutManager
layoutManager.spanCount = context?.config?.fileColumnCnt ?: 3
}
private fun setupListLayoutManager() {
val layoutManager = search_results_list.layoutManager as MyGridLayoutManager
layoutManager.spanCount = 1
}
private fun addItems() {
ItemsAdapter(context as SimpleActivity, allDeviceListItems, this, search_results_list, false, null, false) {
clickedPath((it as FileDirItem).path)
}.apply {
@ -319,19 +338,40 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
return fileDirItems
}
override fun refreshFragment() {}
private fun getRecyclerAdapter() = search_results_list.adapter as? ItemsAdapter
override fun deleteFiles(files: ArrayList<FileDirItem>) {}
override fun refreshFragment() {
val fileDirItems = getAllFiles()
allDeviceListItems = getListItemsFromFileDirItems(fileDirItems)
setupLayoutManager()
}
override fun deleteFiles(files: ArrayList<FileDirItem>) {
handleFileDeleting(files, false)
}
override fun selectedPaths(paths: ArrayList<String>) {}
override fun setupDateTimeFormat() {}
override fun setupDateTimeFormat() {
getRecyclerAdapter()?.updateDateTimeFormat()
}
override fun setupFontSize() {}
override fun setupFontSize() {
getRecyclerAdapter()?.updateFontSizes()
}
override fun toggleFilenameVisibility() {}
override fun toggleFilenameVisibility() {
getRecyclerAdapter()?.updateDisplayFilenamesInGrid()
}
override fun columnCountChanged() {}
override fun columnCountChanged() {
(search_results_list.layoutManager as MyGridLayoutManager).spanCount = context!!.config.fileColumnCnt
getRecyclerAdapter()?.apply {
notifyItemRangeChanged(0, listItems.size)
}
}
override fun finishActMode() {}
override fun finishActMode() {
getRecyclerAdapter()?.finishActMode()
}
}