From a89aa0aa0c01c20c28defc49f28457355b9267f2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 28 May 2020 10:50:26 +0200 Subject: [PATCH] show the proper files at Decompress Activity --- .../pro/activities/DecompressActivity.kt | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/DecompressActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/DecompressActivity.kt index 5837106f..bccef7a4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/DecompressActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/DecompressActivity.kt @@ -19,6 +19,7 @@ import java.util.zip.ZipEntry import java.util.zip.ZipInputStream class DecompressActivity : SimpleActivity() { + private val allFiles = ArrayList() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -33,9 +34,13 @@ class DecompressActivity : SimpleActivity() { title = realPath?.getFilenameFromPath() ?: uri.toString().getFilenameFromPath() try { - val listItems = getListItems(uri) - val adapter = DecompressItemsAdapter(this, listItems, decompress_list) { } - decompress_list.adapter = adapter + fillAllListItems(uri) + val listItems = getFolderItems("") + DecompressItemsAdapter(this, listItems, decompress_list) { + + }.apply { + decompress_list.adapter = this + } } catch (e: Exception) { showErrorToast(e) } @@ -100,9 +105,20 @@ class DecompressActivity : SimpleActivity() { } } + private fun getFolderItems(parent: String): ArrayList { + return allFiles.filter { + val fileParent = if (it.path.contains("/")) { + it.path.getParentPath() + } else { + "" + } + + fileParent == parent + }.toMutableList() as ArrayList + } + @SuppressLint("NewApi") - private fun getListItems(uri: Uri): ArrayList { - val listItems = ArrayList() + private fun fillAllListItems(uri: Uri) { val inputStream = contentResolver.openInputStream(uri) val zipInputStream = ZipInputStream(BufferedInputStream(inputStream)) var zipEntry: ZipEntry? @@ -113,14 +129,9 @@ class DecompressActivity : SimpleActivity() { break } - if (!zipEntry.isDirectory && zipEntry.name.contains("/")) { - continue - } - val lastModified = if (isOreoPlus()) zipEntry.lastModifiedTime.toMillis() else 0 - val listItem = ListItem(zipEntry.name.removeSuffix("/"), zipEntry.name.removeSuffix("/"), zipEntry.isDirectory, 0, 0L, lastModified, false) - listItems.add(listItem) + val listItem = ListItem(zipEntry.name.removeSuffix("/"), zipEntry.name.removeSuffix("/").getFilenameFromPath(), zipEntry.isDirectory, 0, 0L, lastModified, false) + allFiles.add(listItem) } - return listItems } }