mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-17 04:10:39 +01:00
adding initial implementation of file decompressing
This commit is contained in:
parent
f76a60d572
commit
e27841dbea
@ -7,6 +7,7 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||||
import com.simplemobiletools.filemanager.pro.R
|
import com.simplemobiletools.filemanager.pro.R
|
||||||
import com.simplemobiletools.filemanager.pro.adapters.DecompressItemsAdapter
|
import com.simplemobiletools.filemanager.pro.adapters.DecompressItemsAdapter
|
||||||
@ -33,11 +34,8 @@ class DecompressActivity : SimpleActivity() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val listItems = getListItems(uri)
|
val listItems = getListItems(uri)
|
||||||
DecompressItemsAdapter(this, listItems, decompress_list) {
|
val adapter = DecompressItemsAdapter(this, listItems, decompress_list) { }
|
||||||
|
decompress_list.adapter = adapter
|
||||||
}.apply {
|
|
||||||
decompress_list.adapter = this
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
}
|
}
|
||||||
@ -59,8 +57,46 @@ class DecompressActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun decompressFiles() {
|
private fun decompressFiles() {
|
||||||
val defaultFolder = getRealPathFromURI(intent.data!!) ?: internalStoragePath
|
val defaultFolder = getRealPathFromURI(intent.data!!) ?: internalStoragePath
|
||||||
FilePickerDialog(this, defaultFolder, false, config.showHidden, true, true) {
|
FilePickerDialog(this, defaultFolder, false, config.showHidden, true, true) { destination ->
|
||||||
|
handleSAFDialog(destination) {
|
||||||
|
if (it) {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
decompressTo(destination)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun decompressTo(destination: String) {
|
||||||
|
try {
|
||||||
|
val inputStream = contentResolver.openInputStream(intent.data!!)
|
||||||
|
val zipInputStream = ZipInputStream(BufferedInputStream(inputStream!!))
|
||||||
|
val buffer = ByteArray(1024)
|
||||||
|
|
||||||
|
zipInputStream.use {
|
||||||
|
while (true) {
|
||||||
|
val entry = zipInputStream.nextEntry ?: break
|
||||||
|
val newPath = "$destination/${entry.name}"
|
||||||
|
val fos = getFileOutputStreamSync(newPath, newPath.getMimeType())
|
||||||
|
|
||||||
|
var count: Int
|
||||||
|
while (true) {
|
||||||
|
count = zipInputStream.read(buffer)
|
||||||
|
if (count == -1) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
fos!!.write(buffer, 0, count)
|
||||||
|
}
|
||||||
|
fos!!.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
toast(R.string.decompression_successful)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
showErrorToast(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user