mirror of
https://github.com/FossifyOrg/File-Manager.git
synced 2026-03-05 23:19:11 -05:00
Merge pull request #66 from FossifyOrg/fix_various_anrs
Fix various ANRs
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package org.fossify.filemanager.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import net.lingala.zip4j.exception.ZipException
|
||||
@@ -76,11 +75,6 @@ class DecompressActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupFilesList() {
|
||||
fillAllListItems(uri!!)
|
||||
updateCurrentPath("")
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (currentPath.isEmpty()) {
|
||||
super.onBackPressed()
|
||||
@@ -90,10 +84,24 @@ class DecompressActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupFilesList() {
|
||||
fillAllListItems(uri!!) {
|
||||
updateCurrentPath("")
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCurrentPath(path: String) {
|
||||
currentPath = path
|
||||
try {
|
||||
val listItems = getFolderItems(currentPath)
|
||||
updateAdapter(listItems = listItems)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAdapter(listItems: MutableList<ListItem>) {
|
||||
runOnUiThread {
|
||||
DecompressItemsAdapter(this, listItems, binding.decompressList) {
|
||||
if ((it as ListItem).isDirectory) {
|
||||
updateCurrentPath(it.path)
|
||||
@@ -101,14 +109,20 @@ class DecompressActivity : SimpleActivity() {
|
||||
}.apply {
|
||||
binding.decompressList.adapter = this
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun decompressFiles() {
|
||||
val defaultFolder = getRealPathFromURI(uri!!) ?: internalStoragePath
|
||||
FilePickerDialog(this, defaultFolder, false, config.showHidden, true, true, showFavoritesButton = true) { destination ->
|
||||
FilePickerDialog(
|
||||
activity = this,
|
||||
currPath = defaultFolder,
|
||||
pickFile = false,
|
||||
showHidden = config.showHidden,
|
||||
showFAB = true,
|
||||
canAddShowHiddenButton = true,
|
||||
showFavoritesButton = true
|
||||
) { destination ->
|
||||
handleSAFDialog(destination) {
|
||||
if (it) {
|
||||
ensureBackgroundThread {
|
||||
@@ -183,13 +197,12 @@ class DecompressActivity : SimpleActivity() {
|
||||
}.sortedWith(compareBy({ !it.isDirectory }, { it.mName })).toMutableList() as ArrayList<ListItem>
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun fillAllListItems(uri: Uri) {
|
||||
private fun fillAllListItems(uri: Uri, callback: () -> Unit) = ensureBackgroundThread {
|
||||
val inputStream = try {
|
||||
contentResolver.openInputStream(uri)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
return
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
val zipInputStream = ZipInputStream(BufferedInputStream(inputStream))
|
||||
@@ -206,9 +219,11 @@ class DecompressActivity : SimpleActivity() {
|
||||
toast(getString(R.string.invalid_password))
|
||||
passwordDialog?.clearPassword()
|
||||
} else {
|
||||
askForPassword()
|
||||
runOnUiThread {
|
||||
askForPassword()
|
||||
}
|
||||
}
|
||||
return
|
||||
return@ensureBackgroundThread
|
||||
} else {
|
||||
break
|
||||
}
|
||||
@@ -220,12 +235,39 @@ class DecompressActivity : SimpleActivity() {
|
||||
break
|
||||
}
|
||||
|
||||
// Show progress bar only after password dialog is dismissed.
|
||||
runOnUiThread {
|
||||
if (binding.progressIndicator.isGone()) {
|
||||
binding.progressIndicator.show()
|
||||
}
|
||||
}
|
||||
|
||||
if (passwordDialog != null) {
|
||||
passwordDialog?.dismiss(notify = false)
|
||||
passwordDialog = null
|
||||
}
|
||||
|
||||
val lastModified = if (isOreoPlus()) zipEntry.lastModifiedTime else 0
|
||||
val filename = zipEntry.fileName.removeSuffix("/")
|
||||
val listItem = ListItem(filename, filename.getFilenameFromPath(), zipEntry.isDirectory, 0, 0L, lastModified, false, false)
|
||||
allFiles.add(listItem)
|
||||
allFiles.add(
|
||||
ListItem(
|
||||
mPath = filename,
|
||||
mName = filename.getFilenameFromPath(),
|
||||
mIsDirectory = zipEntry.isDirectory,
|
||||
mChildren = 0,
|
||||
mSize = 0L,
|
||||
mModified = lastModified,
|
||||
isSectionTitle = false,
|
||||
isGridTypeDivider = false
|
||||
)
|
||||
)
|
||||
}
|
||||
passwordDialog?.dismiss(notify = false)
|
||||
|
||||
runOnUiThread {
|
||||
binding.progressIndicator.hide()
|
||||
}
|
||||
|
||||
callback()
|
||||
}
|
||||
|
||||
private fun askForPassword() {
|
||||
|
||||
@@ -131,7 +131,7 @@ class DecompressItemsAdapter(activity: SimpleActivity, var listItems: MutableLis
|
||||
}
|
||||
|
||||
private fun initDrawables() {
|
||||
folderDrawable = resources.getColoredDrawableWithColor(R.drawable.ic_folder_vector, textColor)
|
||||
folderDrawable = resources.getColoredDrawableWithColor(R.drawable.ic_folder_vector, properPrimaryColor)
|
||||
folderDrawable.alpha = 180
|
||||
fileDrawable = resources.getDrawable(R.drawable.ic_file_generic)
|
||||
fileDrawables = getFilePlaceholderDrawables(activity)
|
||||
|
||||
@@ -57,8 +57,14 @@ import java.util.LinkedList
|
||||
import java.util.Locale
|
||||
|
||||
class ItemsAdapter(
|
||||
activity: SimpleActivity, var listItems: MutableList<ListItem>, val listener: ItemOperationsListener?, recyclerView: MyRecyclerView,
|
||||
val isPickMultipleIntent: Boolean, val swipeRefreshLayout: SwipeRefreshLayout?, canHaveIndividualViewType: Boolean = true, itemClick: (Any) -> Unit
|
||||
activity: SimpleActivity,
|
||||
var listItems: MutableList<ListItem>,
|
||||
private val listener: ItemOperationsListener?,
|
||||
recyclerView: MyRecyclerView,
|
||||
private val isPickMultipleIntent: Boolean,
|
||||
private val swipeRefreshLayout: SwipeRefreshLayout?,
|
||||
canHaveIndividualViewType: Boolean = true,
|
||||
itemClick: (Any) -> Unit,
|
||||
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate {
|
||||
|
||||
private lateinit var fileDrawable: Drawable
|
||||
@@ -401,12 +407,12 @@ class ItemsAdapter(
|
||||
val firstFile = files[0]
|
||||
val source = firstFile.getParentPath()
|
||||
FilePickerDialog(
|
||||
activity,
|
||||
activity.getDefaultCopyDestinationPath(config.shouldShowHidden(), source),
|
||||
false,
|
||||
config.shouldShowHidden(),
|
||||
true,
|
||||
true,
|
||||
activity = activity,
|
||||
currPath = activity.getDefaultCopyDestinationPath(config.shouldShowHidden(), source),
|
||||
pickFile = false,
|
||||
showHidden = config.shouldShowHidden(),
|
||||
showFAB = true,
|
||||
canAddShowHiddenButton = true,
|
||||
showFavoritesButton = true
|
||||
) {
|
||||
config.lastCopyPath = it
|
||||
@@ -749,28 +755,32 @@ class ItemsAdapter(
|
||||
return
|
||||
}
|
||||
|
||||
activity.handleSAFDialog(SAFPath) {
|
||||
if (!it) {
|
||||
activity.handleSAFDialog(SAFPath) { granted ->
|
||||
if (!granted) {
|
||||
return@handleSAFDialog
|
||||
}
|
||||
|
||||
val files = ArrayList<FileDirItem>(selectedKeys.size)
|
||||
val positions = ArrayList<Int>()
|
||||
selectedKeys.forEach {
|
||||
config.removeFavorite(getItemWithKey(it)?.path ?: "")
|
||||
val key = it
|
||||
val position = listItems.indexOfFirst { it.path.hashCode() == key }
|
||||
if (position != -1) {
|
||||
positions.add(position)
|
||||
files.add(listItems[position])
|
||||
}
|
||||
}
|
||||
|
||||
positions.sortDescending()
|
||||
removeSelectedItems(positions)
|
||||
listener?.deleteFiles(files)
|
||||
positions.forEach {
|
||||
listItems.removeAt(it)
|
||||
ensureBackgroundThread {
|
||||
selectedKeys.forEach { key ->
|
||||
config.removeFavorite(getItemWithKey(key)?.path ?: "")
|
||||
val position = listItems.indexOfFirst { it.path.hashCode() == key }
|
||||
if (position != -1) {
|
||||
positions.add(position)
|
||||
files.add(listItems[position])
|
||||
}
|
||||
}
|
||||
|
||||
positions.sortDescending()
|
||||
activity.runOnUiThread {
|
||||
removeSelectedItems(positions)
|
||||
listener?.deleteFiles(files)
|
||||
positions.forEach {
|
||||
listItems.removeAt(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,12 @@
|
||||
app:layoutManager="org.fossify.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
android:id="@+id/progress_indicator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
Reference in New Issue
Block a user