sort files on the Storage fragment from latest to oldest
This commit is contained in:
parent
b12702848c
commit
63fa771118
|
@ -147,9 +147,9 @@ class MainActivity : SimpleActivity() {
|
||||||
val currentFragment = getCurrentFragment()
|
val currentFragment = getCurrentFragment()
|
||||||
if (main_menu.isSearchOpen) {
|
if (main_menu.isSearchOpen) {
|
||||||
main_menu.closeSearch()
|
main_menu.closeSearch()
|
||||||
} else if (currentFragment is RecentsFragment) {
|
} else if (currentFragment is RecentsFragment || currentFragment is StorageFragment) {
|
||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
} else if (currentFragment != null && currentFragment.breadcrumbs.getItemCount() <= 1) {
|
} else if (currentFragment!!.breadcrumbs.getItemCount() <= 1) {
|
||||||
if (!wasBackJustPressed && config.pressBackTwice) {
|
if (!wasBackJustPressed && config.pressBackTwice) {
|
||||||
wasBackJustPressed = true
|
wasBackJustPressed = true
|
||||||
toast(R.string.press_back_again)
|
toast(R.string.press_back_again)
|
||||||
|
@ -160,7 +160,7 @@ class MainActivity : SimpleActivity() {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentFragment?.breadcrumbs?.removeBreadcrumb() ?: return
|
currentFragment.breadcrumbs?.removeBreadcrumb()
|
||||||
openPath(currentFragment.breadcrumbs.getLastItem().path)
|
openPath(currentFragment.breadcrumbs.getLastItem().path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.filemanager.pro.fragments
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.usage.StorageStatsManager
|
import android.app.usage.StorageStatsManager
|
||||||
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
|
@ -10,6 +11,7 @@ import android.provider.MediaStore
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.os.bundleOf
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.LOWER_ALPHA
|
import com.simplemobiletools.commons.helpers.LOWER_ALPHA
|
||||||
import com.simplemobiletools.commons.helpers.SHORT_ANIMATION_DURATION
|
import com.simplemobiletools.commons.helpers.SHORT_ANIMATION_DURATION
|
||||||
|
@ -279,22 +281,35 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
context?.queryCursor(uri, projection) { cursor ->
|
if (isOreoPlus()) {
|
||||||
try {
|
val queryArgs = bundleOf(
|
||||||
val name = cursor.getStringValue(MediaStore.Files.FileColumns.DISPLAY_NAME)
|
ContentResolver.QUERY_ARG_SORT_COLUMNS to arrayOf(MediaStore.Files.FileColumns.DATE_MODIFIED),
|
||||||
if (!showHidden && name.startsWith(".")) {
|
ContentResolver.QUERY_ARG_SORT_DIRECTION to ContentResolver.QUERY_SORT_DIRECTION_DESCENDING
|
||||||
return@queryCursor
|
)
|
||||||
}
|
context?.contentResolver?.query(uri, projection, queryArgs, null)
|
||||||
|
} else {
|
||||||
|
val sortOrder = "${MediaStore.Files.FileColumns.DATE_MODIFIED} DESC"
|
||||||
|
context?.contentResolver?.query(uri, projection, null, null, sortOrder)
|
||||||
|
}?.use { cursor ->
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
val name = cursor.getStringValue(MediaStore.Files.FileColumns.DISPLAY_NAME)
|
||||||
|
if (!showHidden && name.startsWith(".")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
val size = cursor.getLongValue(MediaStore.Files.FileColumns.SIZE)
|
val size = cursor.getLongValue(MediaStore.Files.FileColumns.SIZE)
|
||||||
if (size == 0L) {
|
if (size == 0L) {
|
||||||
return@queryCursor
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA)
|
val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA)
|
||||||
val lastModified = cursor.getLongValue(MediaStore.Files.FileColumns.DATE_MODIFIED) * 1000
|
val lastModified = cursor.getLongValue(MediaStore.Files.FileColumns.DATE_MODIFIED) * 1000
|
||||||
fileDirItems.add(FileDirItem(path, name, false, 0, size, lastModified))
|
fileDirItems.add(FileDirItem(path, name, false, 0, size, lastModified))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|
Loading…
Reference in New Issue