@@ -20,24 +20,32 @@ import java.util.zip.ZipInputStream
2020
2121class DecompressActivity : SimpleActivity () {
2222 private val allFiles = ArrayList <ListItem >()
23+ private var currentPath = " "
24+ private var uri: Uri ? = null
2325
2426 override fun onCreate (savedInstanceState : Bundle ? ) {
2527 super .onCreate(savedInstanceState)
2628 setContentView(R .layout.activity_decompress)
27- val uri = intent.data
29+ uri = intent.data
2830 if (uri == null ) {
2931 toast(R .string.unknown_error_occurred)
3032 return
3133 }
3234
33- val realPath = getRealPathFromURI(uri)
35+ val realPath = getRealPathFromURI(uri!! )
3436 title = realPath?.getFilenameFromPath() ? : uri.toString().getFilenameFromPath()
37+ fillAllListItems(uri!! )
38+ updateCurrentPath(" " )
39+ }
3540
41+ private fun updateCurrentPath (path : String ) {
42+ currentPath = path
3643 try {
37- fillAllListItems(uri)
38- val listItems = getFolderItems(" " )
44+ val listItems = getFolderItems(currentPath)
3945 DecompressItemsAdapter (this , listItems, decompress_list) {
40-
46+ if ((it as ListItem ).isDirectory) {
47+ updateCurrentPath(it.path)
48+ }
4149 }.apply {
4250 decompress_list.adapter = this
4351 }
@@ -60,8 +68,17 @@ class DecompressActivity : SimpleActivity() {
6068 return true
6169 }
6270
71+ override fun onBackPressed () {
72+ if (currentPath.isEmpty()) {
73+ super .onBackPressed()
74+ } else {
75+ val newPath = if (currentPath.contains(" /" )) currentPath.getParentPath() else " "
76+ updateCurrentPath(newPath)
77+ }
78+ }
79+
6380 private fun decompressFiles () {
64- val defaultFolder = getRealPathFromURI(intent.data !! ) ? : internalStoragePath
81+ val defaultFolder = getRealPathFromURI(uri !! ) ? : internalStoragePath
6582 FilePickerDialog (this , defaultFolder, false , config.showHidden, true , true ) { destination ->
6683 handleSAFDialog(destination) {
6784 if (it) {
@@ -75,7 +92,7 @@ class DecompressActivity : SimpleActivity() {
7592
7693 private fun decompressTo (destination : String ) {
7794 try {
78- val inputStream = contentResolver.openInputStream(intent.data !! )
95+ val inputStream = contentResolver.openInputStream(uri !! )
7996 val zipInputStream = ZipInputStream (BufferedInputStream (inputStream!! ))
8097 val buffer = ByteArray (1024 )
8198
@@ -114,7 +131,7 @@ class DecompressActivity : SimpleActivity() {
114131 }
115132
116133 fileParent == parent
117- }.toMutableList() as ArrayList <ListItem >
134+ }.sortedWith(compareBy({ ! it.isDirectory }, { it.mName })). toMutableList() as ArrayList <ListItem >
118135 }
119136
120137 @SuppressLint(" NewApi" )
@@ -130,7 +147,8 @@ class DecompressActivity : SimpleActivity() {
130147 }
131148
132149 val lastModified = if (isOreoPlus()) zipEntry.lastModifiedTime.toMillis() else 0
133- val listItem = ListItem (zipEntry.name.removeSuffix(" /" ), zipEntry.name.removeSuffix(" /" ).getFilenameFromPath(), zipEntry.isDirectory, 0 , 0L , lastModified, false )
150+ val filename = zipEntry.name.removeSuffix(" /" )
151+ val listItem = ListItem (filename, filename.getFilenameFromPath(), zipEntry.isDirectory, 0 , 0L , lastModified, false )
134152 allFiles.add(listItem)
135153 }
136154 }
0 commit comments