diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index cc63e13a..8a11354d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -28,8 +28,11 @@ import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.extensions.config import kotlinx.android.synthetic.main.list_item.view.* -import java.io.File +import java.io.* import java.util.* +import java.util.zip.ZipEntry +import java.util.zip.ZipOutputStream + class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList, val listener: ItemOperationsListener?, val itemClick: (FileDirItem) -> Unit) : RecyclerView.Adapter() { @@ -88,6 +91,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList shareFiles() R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_move_to -> copyMoveTo(false) + R.id.cab_compress -> compressSelection() R.id.cab_select_all -> selectAll() R.id.cab_delete -> askConfirmDelete() else -> return false @@ -197,6 +201,44 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList, targetPath: String) { + val BUFFER_SIZE = 8192 + var origin: BufferedInputStream? + val out = ZipOutputStream(BufferedOutputStream(FileOutputStream(targetPath))) + try { + val data = ByteArray(BUFFER_SIZE) + + for (i in paths.indices) { + val fi = FileInputStream(paths[i]) + origin = BufferedInputStream(fi, BUFFER_SIZE) + try { + val entry = ZipEntry(paths[i].substring(paths[i].lastIndexOf("/") + 1)) + out.putNextEntry(entry) + var count = origin.read(data, 0, BUFFER_SIZE) + while (count != -1) { + out.write(data, 0, count) + count = origin.read(data, 0, BUFFER_SIZE) + } + } finally { + origin.close() + } + } + } finally { + out.close() + } + } + fun selectAll() { val cnt = mItems.size for (i in 0 until cnt) { diff --git a/app/src/main/res/menu/cab.xml b/app/src/main/res/menu/cab.xml index 050636d5..00911d42 100644 --- a/app/src/main/res/menu/cab.xml +++ b/app/src/main/res/menu/cab.xml @@ -24,6 +24,10 @@ android:id="@+id/cab_move_to" android:title="@string/move_to" app:showAsAction="never"/> +