show a Decompress actionmenu button when a selected file is a zip file
This commit is contained in:
parent
e3def060d8
commit
bc3b6ac70a
3 changed files with 22 additions and 2 deletions
|
@ -25,6 +25,7 @@ import com.simplemobiletools.filemanager.R
|
|||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||
import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
|
||||
import com.simplemobiletools.filemanager.extensions.config
|
||||
import com.simplemobiletools.filemanager.extensions.isZipFile
|
||||
import kotlinx.android.synthetic.main.list_item.view.*
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
|
@ -94,6 +95,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||
R.id.cab_copy_to -> copyMoveTo(true)
|
||||
R.id.cab_move_to -> copyMoveTo(false)
|
||||
R.id.cab_compress -> compressSelection()
|
||||
R.id.cab_decompress -> decompressSelection()
|
||||
R.id.cab_select_all -> selectAll()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
else -> return false
|
||||
|
@ -109,8 +111,8 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||
}
|
||||
|
||||
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
|
||||
val menuItem = menu.findItem(R.id.cab_rename)
|
||||
menuItem.isVisible = selectedPositions.size <= 1
|
||||
menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size <= 1
|
||||
menu.findItem(R.id.cab_decompress).isVisible = getSelectedMedia().map { it.path }.any { it.isZipFile() }
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -233,6 +235,17 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||
}
|
||||
}
|
||||
|
||||
private fun decompressSelection() {
|
||||
if (selectedPositions.isEmpty())
|
||||
return
|
||||
|
||||
val firstPath = mItems[selectedPositions.first()].path
|
||||
activity.handleSAFDialog(File(firstPath)) {
|
||||
activity.toast(R.string.decompressing)
|
||||
val paths = selectedPositions.map { mItems[it].path }.filter { it.isZipFile() }
|
||||
}
|
||||
}
|
||||
|
||||
fun zipPaths(sourcePaths: List<String>, targetPath: String): Boolean {
|
||||
val queue = LinkedList<File>()
|
||||
val out = FileOutputStream(File(targetPath))
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package com.simplemobiletools.filemanager.extensions
|
||||
|
||||
fun String.isZipFile() = endsWith(".zip", true)
|
|
@ -28,6 +28,10 @@
|
|||
android:id="@+id/cab_compress"
|
||||
android:title="@string/compress"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/cab_decompress"
|
||||
android:title="@string/decompress"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/cab_select_all"
|
||||
android:icon="@drawable/ic_select_all"
|
||||
|
|
Loading…
Reference in a new issue