mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-01-30 02:05:00 +01:00
adding an initial version of the decompressing activity
This commit is contained in:
parent
445080a77b
commit
72a10cc917
@ -73,6 +73,16 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activities.DecompressActivity"
|
||||
android:label="@string/decompress">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data android:mimeType="application/zip" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/settings"
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.simplemobiletools.filemanager.pro.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.commons.extensions.getFilenameFromPath
|
||||
import com.simplemobiletools.commons.extensions.getRealPathFromURI
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import com.simplemobiletools.filemanager.pro.R
|
||||
import com.simplemobiletools.filemanager.pro.adapters.ItemsAdapter
|
||||
import com.simplemobiletools.filemanager.pro.models.ListItem
|
||||
import kotlinx.android.synthetic.main.activity_decompress.*
|
||||
import java.io.BufferedInputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
class DecompressActivity : SimpleActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_decompress)
|
||||
val uri = intent.data
|
||||
if (uri == null) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return
|
||||
}
|
||||
|
||||
getRealPathFromURI(uri)?.apply {
|
||||
title = getFilenameFromPath()
|
||||
}
|
||||
|
||||
try {
|
||||
val listItems = getListItems(uri)
|
||||
ItemsAdapter(this, listItems, null, decompress_list, false, null) {
|
||||
}.apply {
|
||||
decompress_list.adapter = this
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun getListItems(uri: Uri): ArrayList<ListItem> {
|
||||
val listItems = ArrayList<ListItem>()
|
||||
val inputStream = contentResolver.openInputStream(uri)
|
||||
val zipInputStream = ZipInputStream(BufferedInputStream(inputStream))
|
||||
var zipEntry: ZipEntry?
|
||||
while (true) {
|
||||
zipEntry = zipInputStream.nextEntry
|
||||
|
||||
if (zipEntry == null) {
|
||||
break
|
||||
}
|
||||
|
||||
val lastModified = if (isOreoPlus()) zipEntry.lastModifiedTime.toMillis() else 0
|
||||
val listItem = ListItem(zipEntry.name, zipEntry.name, zipEntry.isDirectory, 0, 0L, lastModified, false)
|
||||
listItems.add(listItem)
|
||||
}
|
||||
return listItems
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ import java.util.zip.ZipFile
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
class ItemsAdapter(activity: SimpleActivity, var listItems: MutableList<ListItem>, val listener: ItemOperationsListener?, recyclerView: MyRecyclerView,
|
||||
val isPickMultipleIntent: Boolean, fastScroller: FastScroller, itemClick: (Any) -> Unit) :
|
||||
val isPickMultipleIntent: Boolean, fastScroller: FastScroller?, itemClick: (Any) -> Unit) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private val TYPE_FILE_DIR = 1
|
||||
|
@ -3,5 +3,4 @@ package com.simplemobiletools.filemanager.pro.models
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
|
||||
data class ListItem(val mPath: String, val mName: String = "", var mIsDirectory: Boolean = false, var mChildren: Int = 0, var mSize: Long = 0L, var mModified: Long = 0L,
|
||||
var isSectionTitle: Boolean)
|
||||
: FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize, mModified)
|
||||
var isSectionTitle: Boolean) : FileDirItem(mPath, mName, mIsDirectory, mChildren, mSize, mModified)
|
||||
|
16
app/src/main/res/layout/activity_decompress.xml
Normal file
16
app/src/main/res/layout/activity_decompress.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/decompress_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/decompress_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user