diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt index 52d2d0a1..80899fd0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MimeTypesActivity.kt @@ -11,11 +11,13 @@ import androidx.core.view.MenuItemCompat import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.VIEW_TYPE_GRID import com.simplemobiletools.commons.helpers.ensureBackgroundThread +import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.dialogs.ChangeSortingDialog import com.simplemobiletools.filemanager.pro.dialogs.ChangeViewTypeDialog import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.helpers.* +import com.simplemobiletools.filemanager.pro.models.ListItem import java.util.* class MimeTypesActivity : SimpleActivity() { @@ -44,7 +46,11 @@ class MimeTypesActivity : SimpleActivity() { ) ensureBackgroundThread { - getProperFilePaths { paths -> + getProperFileDirItems { fileDirItems -> + FileDirItem.sorting = config.getFolderSorting(currentMimeType) + fileDirItems.sort() + val listItems = getListItemsFromFileDirItems(fileDirItems) + runOnUiThread { } @@ -97,12 +103,15 @@ class MimeTypesActivity : SimpleActivity() { return true } - private fun getProperFilePaths(callback: (ArrayList) -> Unit) { - val filePaths = ArrayList() + private fun getProperFileDirItems(callback: (ArrayList) -> Unit) { + val fileDirItems = ArrayList() val uri = MediaStore.Files.getContentUri("external") val projection = arrayOf( MediaStore.Files.FileColumns.MIME_TYPE, - MediaStore.Files.FileColumns.DATA + MediaStore.Files.FileColumns.DATA, + MediaStore.Files.FileColumns.DISPLAY_NAME, + MediaStore.Files.FileColumns.SIZE, + MediaStore.Files.FileColumns.DATE_MODIFIED ) try { @@ -110,32 +119,35 @@ class MimeTypesActivity : SimpleActivity() { try { val fullMimetype = cursor.getStringValue(MediaStore.Files.FileColumns.MIME_TYPE)?.lowercase(Locale.getDefault()) ?: return@queryCursor val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA) + val name = cursor.getStringValue(MediaStore.Files.FileColumns.DISPLAY_NAME) + val size = cursor.getLongValue(MediaStore.Files.FileColumns.SIZE) + val lastModified = cursor.getLongValue(MediaStore.Files.FileColumns.DATE_MODIFIED) * 1000 val mimetype = fullMimetype.substringBefore("/") when (currentMimeType) { IMAGES -> { if (mimetype == "image") { - filePaths.add(path) + fileDirItems.add(FileDirItem(path, name, false, 0, size, lastModified)) } } VIDEOS -> { if (mimetype == "video") { - filePaths.add(path) + fileDirItems.add(FileDirItem(path, name, false, 0, size, lastModified)) } } AUDIO -> { if (mimetype == "audio" || extraAudioMimeTypes.contains(fullMimetype)) { - filePaths.add(path) + fileDirItems.add(FileDirItem(path, name, false, 0, size, lastModified)) } } DOCUMENTS -> { if (mimetype == "text" || extraDocumentMimeTypes.contains(fullMimetype)) { - filePaths.add(path) + fileDirItems.add(FileDirItem(path, name, false, 0, size, lastModified)) } } ARCHIVES -> { if (archiveMimeTypes.contains(fullMimetype)) { - filePaths.add(path) + fileDirItems.add(FileDirItem(path, name, false, 0, size, lastModified)) } } } @@ -146,7 +158,16 @@ class MimeTypesActivity : SimpleActivity() { showErrorToast(e) } - callback(filePaths) + callback(fileDirItems) + } + + private fun getListItemsFromFileDirItems(fileDirItems: ArrayList): ArrayList { + val listItems = ArrayList() + fileDirItems.forEach { + val listItem = ListItem(it.path, it.name, false, 0, it.size, it.modified, false) + listItems.add(listItem) + } + return listItems } private fun setupSearch(menu: Menu) { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt index 00ab9431..6250d79b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/models/ListItem.kt @@ -2,5 +2,6 @@ package com.simplemobiletools.filemanager.pro.models import com.simplemobiletools.commons.models.FileDirItem +// isSectionTitle is used only at search results for showing the current folders path data class ListItem(val mPath: String, val mName: String = "", var mIsDirectory: Boolean = false, var mChildren: Int = 0, var mSize: Long = 0L, var mModified: Long = 0L, var isSectionTitle: Boolean) : FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize, mModified)