|
|
@@ -98,6 +98,8 @@ import org.fossify.filemanager.databinding.ItemFileDirListBinding
|
|
|
import org.fossify.filemanager.databinding.ItemFileGridBinding
|
|
|
import org.fossify.filemanager.databinding.ItemSectionBinding
|
|
|
import org.fossify.filemanager.dialogs.CompressAsDialog
|
|
|
+import org.fossify.filemanager.dialogs.FileOperationProgressDialog
|
|
|
+import org.fossify.filemanager.dialogs.PasswordConfirmationDialog
|
|
|
import org.fossify.filemanager.extensions.config
|
|
|
import org.fossify.filemanager.extensions.isPathOnRoot
|
|
|
import org.fossify.filemanager.extensions.isZipFile
|
|
|
@@ -238,10 +240,12 @@ class ItemsAdapter(
|
|
|
override fun onActionModeCreated() {
|
|
|
swipeRefreshLayout?.isRefreshing = false
|
|
|
swipeRefreshLayout?.isEnabled = false
|
|
|
+ notifyDataSetChanged()
|
|
|
}
|
|
|
|
|
|
override fun onActionModeDestroyed() {
|
|
|
swipeRefreshLayout?.isEnabled = config.enablePullToRefresh
|
|
|
+ notifyDataSetChanged()
|
|
|
}
|
|
|
|
|
|
override fun getItemViewType(position: Int): Int {
|
|
|
@@ -692,10 +696,14 @@ class ItemsAdapter(
|
|
|
return@handleSAFDialog
|
|
|
}
|
|
|
|
|
|
- EnterPasswordDialog(activity, { password ->
|
|
|
- activity.toast(R.string.encrypting)
|
|
|
+ PasswordConfirmationDialog(activity) { password ->
|
|
|
+ val progressDialog = FileOperationProgressDialog(activity, R.string.encrypting)
|
|
|
+ progressDialog.start()
|
|
|
ensureBackgroundThread {
|
|
|
- val counts = encryptItems(selected, password)
|
|
|
+ val counts = encryptItems(selected, password) { fileName, fileIndex, fileCount, processed, total ->
|
|
|
+ progressDialog.update(fileName, fileIndex, fileCount, processed, total)
|
|
|
+ }
|
|
|
+ progressDialog.finish()
|
|
|
activity.runOnUiThread {
|
|
|
when {
|
|
|
counts.failed > 0 -> activity.toast(R.string.encryption_failed)
|
|
|
@@ -706,9 +714,7 @@ class ItemsAdapter(
|
|
|
finishActMode()
|
|
|
}
|
|
|
}
|
|
|
- }, {
|
|
|
- // user canceled the password prompt
|
|
|
- })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -730,9 +736,13 @@ class ItemsAdapter(
|
|
|
}
|
|
|
|
|
|
EnterPasswordDialog(activity, { password ->
|
|
|
- activity.toast(R.string.decrypting)
|
|
|
+ val progressDialog = FileOperationProgressDialog(activity, R.string.decrypting)
|
|
|
+ progressDialog.start()
|
|
|
ensureBackgroundThread {
|
|
|
- val counts = decryptItems(selected, password)
|
|
|
+ val counts = decryptItems(selected, password) { fileName, fileIndex, fileCount, processed, total ->
|
|
|
+ progressDialog.update(fileName, fileIndex, fileCount, processed, total)
|
|
|
+ }
|
|
|
+ progressDialog.finish()
|
|
|
activity.runOnUiThread {
|
|
|
when {
|
|
|
counts.failed > 0 -> activity.toast(R.string.decryption_failed)
|
|
|
@@ -750,57 +760,68 @@ class ItemsAdapter(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun encryptItems(items: List<FileDirItem>, password: String): EncDecCounts {
|
|
|
- var ok = 0
|
|
|
- var skipped = 0
|
|
|
- var failed = 0
|
|
|
- items.forEach { item ->
|
|
|
- val files = if (item.isDirectory) {
|
|
|
+ private fun encryptItems(
|
|
|
+ items: List<FileDirItem>,
|
|
|
+ password: String,
|
|
|
+ onProgress: (String, Int, Int, Long, Long) -> Unit = { _, _, _, _, _ -> }
|
|
|
+ ): EncDecCounts {
|
|
|
+ val allFiles = items.flatMap { item ->
|
|
|
+ if (item.isDirectory) {
|
|
|
File(item.path).walkTopDown().filter { it.isFile }.toList()
|
|
|
} else {
|
|
|
listOf(File(item.path))
|
|
|
}
|
|
|
- files.forEach { f ->
|
|
|
- try {
|
|
|
- if (f.exists() && f.length() > 0L) {
|
|
|
- CryptoHelper.encryptFile(f, password)
|
|
|
- ok++
|
|
|
- } else {
|
|
|
- skipped++
|
|
|
+ }
|
|
|
+ var ok = 0
|
|
|
+ var skipped = 0
|
|
|
+ var failed = 0
|
|
|
+ allFiles.forEachIndexed { index, f ->
|
|
|
+ try {
|
|
|
+ if (f.exists() && f.length() > 0L) {
|
|
|
+ CryptoHelper.encryptFile(f, password) { processed, total ->
|
|
|
+ onProgress(f.name, index + 1, allFiles.size, processed, total)
|
|
|
}
|
|
|
- } catch (e: AlreadyEncryptedException) {
|
|
|
+ ok++
|
|
|
+ } else {
|
|
|
skipped++
|
|
|
- } catch (e: Exception) {
|
|
|
- failed++
|
|
|
}
|
|
|
+ } catch (e: AlreadyEncryptedException) {
|
|
|
+ skipped++
|
|
|
+ } catch (e: Exception) {
|
|
|
+ failed++
|
|
|
}
|
|
|
}
|
|
|
return EncDecCounts(ok, skipped, failed)
|
|
|
}
|
|
|
|
|
|
- private fun decryptItems(items: List<FileDirItem>, password: String): EncDecCounts {
|
|
|
- var ok = 0
|
|
|
- var skipped = 0
|
|
|
- var failed = 0
|
|
|
- items.forEach { item ->
|
|
|
+ private fun decryptItems(
|
|
|
+ items: List<FileDirItem>,
|
|
|
+ password: String,
|
|
|
+ onProgress: (String, Int, Int, Long, Long) -> Unit = { _, _, _, _, _ -> }
|
|
|
+ ): EncDecCounts {
|
|
|
+ val allFiles = items.flatMap { item ->
|
|
|
val files = if (item.isDirectory) {
|
|
|
- File(item.path).walkTopDown()
|
|
|
- .filter { it.isFile && it.name.endsWith(CryptoHelper.LOCKED_SUFFIX) }
|
|
|
- .toList()
|
|
|
+ File(item.path).walkTopDown().filter { it.isFile }.toList()
|
|
|
} else {
|
|
|
listOf(File(item.path))
|
|
|
}
|
|
|
- files.forEach { f ->
|
|
|
- if (!CryptoHelper.isEncrypted(f)) {
|
|
|
- skipped++
|
|
|
- return@forEach
|
|
|
- }
|
|
|
- try {
|
|
|
- CryptoHelper.decryptFile(f, password)
|
|
|
- ok++
|
|
|
- } catch (e: Exception) {
|
|
|
- failed++
|
|
|
+ files.filter { it.exists() && it.name.endsWith(CryptoHelper.LOCKED_SUFFIX) }
|
|
|
+ }
|
|
|
+ var ok = 0
|
|
|
+ var skipped = 0
|
|
|
+ var failed = 0
|
|
|
+ allFiles.forEachIndexed { index, f ->
|
|
|
+ if (!CryptoHelper.isEncrypted(f)) {
|
|
|
+ skipped++
|
|
|
+ return@forEachIndexed
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ CryptoHelper.decryptFile(f, password) { processed, total ->
|
|
|
+ onProgress(f.name, index + 1, allFiles.size, processed, total)
|
|
|
}
|
|
|
+ ok++
|
|
|
+ } catch (e: Exception) {
|
|
|
+ failed++
|
|
|
}
|
|
|
}
|
|
|
return EncDecCounts(ok, skipped, failed)
|
|
|
@@ -1205,10 +1226,23 @@ class ItemsAdapter(
|
|
|
itemDate?.setTextColor(textColor)
|
|
|
itemDate?.setTextSize(TypedValue.COMPLEX_UNIT_PX, smallerFontSize)
|
|
|
|
|
|
- itemCheck?.beVisibleIf(isSelected)
|
|
|
- if (isSelected) {
|
|
|
- itemCheck?.background?.applyColorFilter(properPrimaryColor)
|
|
|
- itemCheck?.applyColorFilter(contrastColor)
|
|
|
+ val inSelectionMode = selectedKeys.isNotEmpty()
|
|
|
+ itemCheck?.apply {
|
|
|
+ when {
|
|
|
+ !inSelectionMode -> beGone()
|
|
|
+ isSelected -> {
|
|
|
+ beVisible()
|
|
|
+ background?.applyColorFilter(properPrimaryColor)
|
|
|
+ applyColorFilter(contrastColor)
|
|
|
+ imageAlpha = 255
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ beVisible()
|
|
|
+ background?.applyColorFilter(0x40FFFFFF)
|
|
|
+ applyColorFilter(0x00FFFFFF)
|
|
|
+ imageAlpha = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (!isListViewType && !listItem.isDirectory) {
|
|
|
@@ -1446,7 +1480,7 @@ class ItemsAdapter(
|
|
|
override val itemIcon: ImageView = binding.itemIcon
|
|
|
override val itemDetails: TextView = binding.itemDetails
|
|
|
override val itemDate: TextView = binding.itemDate
|
|
|
- override val itemCheck: ImageView? = null
|
|
|
+ override val itemCheck: ImageView = binding.itemCheck
|
|
|
override val itemSection: TextView? = null
|
|
|
|
|
|
override fun getRoot(): View = binding.root
|
|
|
@@ -1470,7 +1504,7 @@ class ItemsAdapter(
|
|
|
override val itemIcon: ImageView = binding.itemIcon
|
|
|
override val itemDetails: TextView? = null
|
|
|
override val itemDate: TextView? = null
|
|
|
- override val itemCheck: ImageView? = null
|
|
|
+ override val itemCheck: ImageView = binding.itemCheck
|
|
|
override val itemSection: TextView? = null
|
|
|
|
|
|
override fun getRoot(): View = binding.root
|