fix query for recents fragment

This commit is contained in:
darthpaul 2021-11-10 20:46:05 +00:00
parent 1e067e3614
commit 2de754e4cf
2 changed files with 35 additions and 14 deletions

View file

@ -66,7 +66,7 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
documentFile.createDirectory(path.getFilenameFromPath())
success(alertDialog)
}
path.startsWith(activity.internalStoragePath, true) -> {
isRPlus() || path.startsWith(activity.internalStoragePath, true) -> {
if (activity.isRestrictedAndroidDir(path)) {
activity.handlePrimarySAFDialog(path) {
if (!it) {
@ -136,7 +136,7 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
}
}
path.startsWith(activity.internalStoragePath, true) -> {
isRPlus() || path.startsWith(activity.internalStoragePath, true) -> {
if (File(path).createNewFile()) {
success(alertDialog)
}

View file

@ -1,14 +1,14 @@
package com.simplemobiletools.filemanager.pro.fragments
import android.content.ContentResolver
import android.content.Context
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
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.MyGridLayoutManager
import com.simplemobiletools.filemanager.pro.R
@ -24,6 +24,8 @@ import kotlinx.android.synthetic.main.recents_fragment.view.*
import java.util.*
class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet), ItemOperationsListener {
private val RECENTS_LIMIT = 50
override fun setupFragment(activity: SimpleActivity) {
if (this.activity == null) {
this.activity = activity
@ -120,17 +122,36 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
FileColumns.SIZE
)
val sortOrder = "${FileColumns.DATE_MODIFIED} DESC LIMIT 50"
val cursor = if (isOreoPlus()) {
val queryArgs = bundleOf(
ContentResolver.QUERY_ARG_LIMIT to RECENTS_LIMIT,
ContentResolver.QUERY_ARG_SORT_COLUMNS to arrayOf(FileColumns.DATE_MODIFIED),
ContentResolver.QUERY_ARG_SORT_DIRECTION to ContentResolver.QUERY_SORT_DIRECTION_DESCENDING
)
context?.contentResolver?.query(uri, projection, queryArgs, null)
} else {
val sortOrder = "${FileColumns.DATE_MODIFIED} DESC LIMIT $RECENTS_LIMIT"
context?.contentResolver?.query(uri, projection, null, null, sortOrder)
}
context?.queryCursor(uri, projection, sortOrder = sortOrder, showErrors = true) { cursor ->
val path = cursor.getStringValue(FileColumns.DATA)
val name = cursor.getStringValue(FileColumns.DISPLAY_NAME) ?: path.getFilenameFromPath()
val size = cursor.getLongValue(FileColumns.SIZE)
val modified = cursor.getLongValue(FileColumns.DATE_MODIFIED) * 1000
val fileDirItem = ListItem(path, name, false, 0, size, modified, false)
if ((showHidden || !name.startsWith(".")) && activity?.getDoesFilePathExist(path) == true) {
listItems.add(fileDirItem)
try {
cursor?.use {
if (cursor.moveToFirst()) {
do {
val path = cursor.getStringValue(FileColumns.DATA)
val name = cursor.getStringValue(FileColumns.DISPLAY_NAME) ?: path.getFilenameFromPath()
val size = cursor.getLongValue(FileColumns.SIZE)
val modified = cursor.getLongValue(FileColumns.DATE_MODIFIED) * 1000
val fileDirItem = ListItem(path, name, false, 0, size, modified, false)
if ((showHidden || !name.startsWith(".")) && activity?.getDoesFilePathExist(path) == true) {
listItems.add(fileDirItem)
}
} while (cursor.moveToNext())
}
}
} catch (e: Exception) {
e.printStackTrace()
activity?.showErrorToast(e)
}
activity?.runOnUiThread {