From e4127b61d9adaee3729da9d6aa5b10dfa518d806 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 6 Mar 2016 22:42:55 +0100 Subject: [PATCH] make sure we delete the proper checked folders --- .../gallery/activities/MainActivity.java | 26 ++++++++++++------- .../gallery/activities/PhotosActivity.java | 12 ++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index f2d16ee4a..e6a47e8d9 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -132,13 +132,17 @@ public class MainActivity extends AppCompatActivity Helpers.showToast(this, R.string.deleting); final SparseBooleanArray items = gridView.getCheckedItemPositions(); int cnt = items.size(); + int deletedCnt = 0; for (int i = 0; i < cnt; i++) { - final int id = items.keyAt(i); - final String path = dirs.get(id).getPath(); - toBeDeleted.add(path); + if (items.valueAt(i)) { + final int id = items.keyAt(i); + final String path = dirs.get(id).getPath(); + toBeDeleted.add(path); + deletedCnt++; + } } - notifyDeletion(cnt); + notifyDeletion(deletedCnt); } private void notifyDeletion(int cnt) { @@ -168,13 +172,15 @@ public class MainActivity extends AppCompatActivity final List updatedFiles = new ArrayList<>(); for (String delPath : toBeDeleted) { final File dir = new File(delPath); - final File[] files = dir.listFiles(); - for (File f : files) { - updatedFiles.add(f.getAbsolutePath()); - f.delete(); + if (dir.exists()) { + final File[] files = dir.listFiles(); + for (File f : files) { + updatedFiles.add(f.getAbsolutePath()); + f.delete(); + } + updatedFiles.add(dir.getAbsolutePath()); + dir.delete(); } - updatedFiles.add(dir.getAbsolutePath()); - dir.delete(); } final String[] deletedPaths = updatedFiles.toArray(new String[updatedFiles.size()]); diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java index 2a7c9b96a..9e814d691 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java @@ -149,13 +149,17 @@ public class PhotosActivity extends AppCompatActivity Helpers.showToast(this, R.string.deleting); final SparseBooleanArray items = gridView.getCheckedItemPositions(); int cnt = items.size(); + int deletedCnt = 0; for (int i = 0; i < cnt; i++) { - final int id = items.keyAt(i); - final String path = photos.get(id); - toBeDeleted.add(path); + if (items.valueAt(i)) { + final int id = items.keyAt(i); + final String path = photos.get(id); + toBeDeleted.add(path); + deletedCnt++; + } } - notifyDeletion(cnt); + notifyDeletion(deletedCnt); } private void notifyDeletion(int cnt) {