From a368db9b87a05a97ec4c11b09081ba3641a31f2c Mon Sep 17 00:00:00 2001 From: Doozy Date: Wed, 18 May 2022 18:27:27 +0300 Subject: [PATCH 1/7] [feat] Display item(s) size in delete dialog --- .../pro/activities/ViewPagerActivity.kt | 8 ++++++-- .../gallery/pro/adapters/DirectoryAdapter.kt | 18 ++++++++++++++---- .../gallery/pro/adapters/MediaAdapter.kt | 17 +++++++++++++---- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 72b23be1e..25e0140b6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -1104,7 +1104,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun askConfirmDelete() { - val filename = "\"${getCurrentPath().getFilenameFromPath()}\"" + val path = getCurrentPath() + val fileDirItem = FileDirItem(path, path.getFilenameFromPath(), getIsPathDirectory(path)) + val size = fileDirItem.getProperSize(this, countHidden = true).formatSize() + val filename = "\"${path.getFilenameFromPath()}\"" + val filenameAndSize = "$filename ($size)" val baseString = if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { R.string.move_to_recycle_bin_confirmation @@ -1112,7 +1116,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.string.deletion_confirmation } - val message = String.format(resources.getString(baseString), filename) + val message = String.format(resources.getString(baseString), filenameAndSize) DeleteWithRememberDialog(this, message) { config.tempSkipDeleteConfirmation = it deleteConfirmed() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index bc6ad8279..a12a25179 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -593,11 +593,21 @@ class DirectoryAdapter( return } - val items = if (itemsCnt == 1) { + val itemsAndSize = if (itemsCnt == 1) { + val path = getSelectedPaths().first() + val fileDirItem = FileDirItem(path, path.getFilenameFromPath(), activity.getIsPathDirectory(path)) + val size = fileDirItem.getProperSize(activity, countHidden = true).formatSize() val folder = getSelectedPaths().first().getFilenameFromPath() - "\"$folder\"" + "\"$folder\" ($size)" } else { - resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt) + val paths = getSelectedPaths() + val fileDirItems = ArrayList(paths.size) + paths.forEach { + val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) + fileDirItems.add(fileDirItem) + } + val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() + "${resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)} ($size)" } val fileDirItem = getFirstSelectedItem() ?: return @@ -607,7 +617,7 @@ class DirectoryAdapter( R.string.move_to_recycle_bin_confirmation } - val question = String.format(resources.getString(baseString), items) + val question = String.format(resources.getString(baseString), itemsAndSize) val warning = resources.getQuantityString(R.plurals.delete_warning, itemsCnt, itemsCnt) ConfirmDeleteFolderDialog(activity, question, warning) { deleteFolders() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 2472fbe9f..cbe59f5cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -462,15 +462,24 @@ class MediaAdapter( private fun askConfirmDelete() { val itemsCnt = selectedKeys.size val firstPath = getSelectedPaths().first() - val items = if (itemsCnt == 1) { - "\"${firstPath.getFilenameFromPath()}\"" + val fileDirItem = FileDirItem(firstPath, firstPath.getFilenameFromPath(), activity.getIsPathDirectory(firstPath)) + val size = fileDirItem.getProperSize(activity, countHidden = true).formatSize() + val itemsAndSize = if (itemsCnt == 1) { + "\"${firstPath.getFilenameFromPath()}\" ($size)" } else { - resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt) + val paths = getSelectedPaths() + val fileDirItems = java.util.ArrayList(paths.size) + paths.forEach { + val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) + fileDirItems.add(fileDirItem) + } + val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() + "${resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)} ($size)" } val isRecycleBin = firstPath.startsWith(activity.recycleBinPath) val baseString = if (config.useRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation - val question = String.format(resources.getString(baseString), items) + val question = String.format(resources.getString(baseString), itemsAndSize) DeleteWithRememberDialog(activity, question) { config.tempSkipDeleteConfirmation = it deleteFiles() From fb17549173e5d41560b07152ba9ba6235d66c1ea Mon Sep 17 00:00:00 2001 From: Doozy Date: Thu, 19 May 2022 10:39:57 +0300 Subject: [PATCH 2/7] Code cleanup (post review) --- .../gallery/pro/activities/ViewPagerActivity.kt | 5 ++--- .../gallery/pro/adapters/DirectoryAdapter.kt | 9 +++------ .../gallery/pro/adapters/MediaAdapter.kt | 10 ++++------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index 25e0140b6..4af374bba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -1104,10 +1104,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } private fun askConfirmDelete() { - val path = getCurrentPath() - val fileDirItem = FileDirItem(path, path.getFilenameFromPath(), getIsPathDirectory(path)) + val fileDirItem = File(getCurrentPath()).toFileDirItem(this) val size = fileDirItem.getProperSize(this, countHidden = true).formatSize() - val filename = "\"${path.getFilenameFromPath()}\"" + val filename = "\"${getCurrentPath().getFilenameFromPath()}\"" val filenameAndSize = "$filename ($size)" val baseString = if (config.useRecycleBin && !getCurrentMedium()!!.getIsInRecycleBin()) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index a12a25179..a5a2dd928 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -595,17 +595,14 @@ class DirectoryAdapter( val itemsAndSize = if (itemsCnt == 1) { val path = getSelectedPaths().first() - val fileDirItem = FileDirItem(path, path.getFilenameFromPath(), activity.getIsPathDirectory(path)) + val fileDirItem = File(path).toFileDirItem(activity) val size = fileDirItem.getProperSize(activity, countHidden = true).formatSize() - val folder = getSelectedPaths().first().getFilenameFromPath() + val folder = path.getFilenameFromPath() "\"$folder\" ($size)" } else { val paths = getSelectedPaths() val fileDirItems = ArrayList(paths.size) - paths.forEach { - val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) - fileDirItems.add(fileDirItem) - } + paths.forEach { fileDirItems.add(File(it).toFileDirItem(activity)) } val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() "${resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)} ($size)" } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index cbe59f5cc..b21ab363d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -38,6 +38,7 @@ import kotlinx.android.synthetic.main.video_item_grid.view.media_item_holder import kotlinx.android.synthetic.main.video_item_grid.view.medium_check import kotlinx.android.synthetic.main.video_item_grid.view.medium_name import kotlinx.android.synthetic.main.video_item_grid.view.medium_thumbnail +import java.io.File class MediaAdapter( activity: BaseSimpleActivity, var media: ArrayList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, @@ -462,17 +463,14 @@ class MediaAdapter( private fun askConfirmDelete() { val itemsCnt = selectedKeys.size val firstPath = getSelectedPaths().first() - val fileDirItem = FileDirItem(firstPath, firstPath.getFilenameFromPath(), activity.getIsPathDirectory(firstPath)) + val fileDirItem = File(firstPath).toFileDirItem(activity) val size = fileDirItem.getProperSize(activity, countHidden = true).formatSize() val itemsAndSize = if (itemsCnt == 1) { "\"${firstPath.getFilenameFromPath()}\" ($size)" } else { val paths = getSelectedPaths() - val fileDirItems = java.util.ArrayList(paths.size) - paths.forEach { - val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) - fileDirItems.add(fileDirItem) - } + val fileDirItems = ArrayList(paths.size) + paths.forEach { fileDirItems.add(File(it).toFileDirItem(activity)) } val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() "${resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)} ($size)" } From 914d97c23180a506c0c92314a9ed1f844b410075 Mon Sep 17 00:00:00 2001 From: Doozy Date: Thu, 19 May 2022 10:55:26 +0300 Subject: [PATCH 3/7] Changes for readability --- .../gallery/pro/adapters/DirectoryAdapter.kt | 5 ++++- .../simplemobiletools/gallery/pro/adapters/MediaAdapter.kt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index a5a2dd928..319c2008d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -602,7 +602,10 @@ class DirectoryAdapter( } else { val paths = getSelectedPaths() val fileDirItems = ArrayList(paths.size) - paths.forEach { fileDirItems.add(File(it).toFileDirItem(activity)) } + paths.forEach { + val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) + fileDirItems.add(fileDirItem) + } val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() "${resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)} ($size)" } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index b21ab363d..7d4ca81ca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -470,7 +470,10 @@ class MediaAdapter( } else { val paths = getSelectedPaths() val fileDirItems = ArrayList(paths.size) - paths.forEach { fileDirItems.add(File(it).toFileDirItem(activity)) } + paths.forEach { + val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) + fileDirItems.add(fileDirItem) + } val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() "${resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)} ($size)" } From 6080191e1a78f819310f507b606a6b96bdb81f30 Mon Sep 17 00:00:00 2001 From: Doozy Date: Thu, 19 May 2022 10:58:37 +0300 Subject: [PATCH 4/7] Changed back to File extension --- .../simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt | 2 +- .../com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 319c2008d..b865104ae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -603,7 +603,7 @@ class DirectoryAdapter( val paths = getSelectedPaths() val fileDirItems = ArrayList(paths.size) paths.forEach { - val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) + val fileDirItem = File(it).toFileDirItem(activity) fileDirItems.add(fileDirItem) } val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index 7d4ca81ca..f71192bda 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -471,7 +471,7 @@ class MediaAdapter( val paths = getSelectedPaths() val fileDirItems = ArrayList(paths.size) paths.forEach { - val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) + val fileDirItem = File(it).toFileDirItem(activity) fileDirItems.add(fileDirItem) } val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() From 33c1ddd7618b68d94d1197f00e9d48cc9d532a63 Mon Sep 17 00:00:00 2001 From: Doozy Date: Thu, 19 May 2022 11:26:09 +0300 Subject: [PATCH 5/7] Changes for readability --- .../simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt | 3 ++- .../com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index b865104ae..1cf702833 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -607,7 +607,8 @@ class DirectoryAdapter( fileDirItems.add(fileDirItem) } val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() - "${resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)} ($size)" + val deleteItemsString = resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt) + "$deleteItemsString ($size)" } val fileDirItem = getFirstSelectedItem() ?: return diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index f71192bda..754064e29 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -475,7 +475,8 @@ class MediaAdapter( fileDirItems.add(fileDirItem) } val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() - "${resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)} ($size)" + val deleteItemsString = resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt) + "$deleteItemsString ($size)" } val isRecycleBin = firstPath.startsWith(activity.recycleBinPath) From 1349d4c6e009660b72fa2a8a6fe264e9d713fdef Mon Sep 17 00:00:00 2001 From: Doozy Date: Mon, 23 May 2022 11:24:41 +0300 Subject: [PATCH 6/7] [Removed] showing item size for folder deletion --- .../gallery/pro/adapters/DirectoryAdapter.kt | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 1cf702833..6a51f9c1f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -592,23 +592,11 @@ class DirectoryAdapter( } return } - - val itemsAndSize = if (itemsCnt == 1) { - val path = getSelectedPaths().first() - val fileDirItem = File(path).toFileDirItem(activity) - val size = fileDirItem.getProperSize(activity, countHidden = true).formatSize() - val folder = path.getFilenameFromPath() - "\"$folder\" ($size)" + val items = if (itemsCnt == 1) { + val folder = getSelectedPaths().first().getFilenameFromPath() + "\"$folder\"" } else { - val paths = getSelectedPaths() - val fileDirItems = ArrayList(paths.size) - paths.forEach { - val fileDirItem = File(it).toFileDirItem(activity) - fileDirItems.add(fileDirItem) - } - val size = fileDirItems.sumByLong { it.getProperSize(activity, countHidden = true) }.formatSize() - val deleteItemsString = resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt) - "$deleteItemsString ($size)" + resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt) } val fileDirItem = getFirstSelectedItem() ?: return @@ -618,7 +606,7 @@ class DirectoryAdapter( R.string.move_to_recycle_bin_confirmation } - val question = String.format(resources.getString(baseString), itemsAndSize) + val question = String.format(resources.getString(baseString), items) val warning = resources.getQuantityString(R.plurals.delete_warning, itemsCnt, itemsCnt) ConfirmDeleteFolderDialog(activity, question, warning) { deleteFolders() From 4ac8c42e9c5182ea5480b176a6d433857b4dab59 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Mon, 23 May 2022 22:08:42 +0200 Subject: [PATCH 7/7] adding a newline --- .../simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 6a51f9c1f..bc6ad8279 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -592,6 +592,7 @@ class DirectoryAdapter( } return } + val items = if (itemsCnt == 1) { val folder = getSelectedPaths().first().getFilenameFromPath() "\"$folder\""