make sure we delete the proper checked folders

This commit is contained in:
tibbi 2016-03-06 22:42:55 +01:00
parent b880912ecb
commit e4127b61d9
2 changed files with 24 additions and 14 deletions

View file

@ -132,13 +132,17 @@ public class MainActivity extends AppCompatActivity
Helpers.showToast(this, R.string.deleting); Helpers.showToast(this, R.string.deleting);
final SparseBooleanArray items = gridView.getCheckedItemPositions(); final SparseBooleanArray items = gridView.getCheckedItemPositions();
int cnt = items.size(); int cnt = items.size();
int deletedCnt = 0;
for (int i = 0; i < cnt; i++) { for (int i = 0; i < cnt; i++) {
final int id = items.keyAt(i); if (items.valueAt(i)) {
final String path = dirs.get(id).getPath(); final int id = items.keyAt(i);
toBeDeleted.add(path); final String path = dirs.get(id).getPath();
toBeDeleted.add(path);
deletedCnt++;
}
} }
notifyDeletion(cnt); notifyDeletion(deletedCnt);
} }
private void notifyDeletion(int cnt) { private void notifyDeletion(int cnt) {
@ -168,13 +172,15 @@ public class MainActivity extends AppCompatActivity
final List<String> updatedFiles = new ArrayList<>(); final List<String> updatedFiles = new ArrayList<>();
for (String delPath : toBeDeleted) { for (String delPath : toBeDeleted) {
final File dir = new File(delPath); final File dir = new File(delPath);
final File[] files = dir.listFiles(); if (dir.exists()) {
for (File f : files) { final File[] files = dir.listFiles();
updatedFiles.add(f.getAbsolutePath()); for (File f : files) {
f.delete(); 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()]); final String[] deletedPaths = updatedFiles.toArray(new String[updatedFiles.size()]);

View file

@ -149,13 +149,17 @@ public class PhotosActivity extends AppCompatActivity
Helpers.showToast(this, R.string.deleting); Helpers.showToast(this, R.string.deleting);
final SparseBooleanArray items = gridView.getCheckedItemPositions(); final SparseBooleanArray items = gridView.getCheckedItemPositions();
int cnt = items.size(); int cnt = items.size();
int deletedCnt = 0;
for (int i = 0; i < cnt; i++) { for (int i = 0; i < cnt; i++) {
final int id = items.keyAt(i); if (items.valueAt(i)) {
final String path = photos.get(id); final int id = items.keyAt(i);
toBeDeleted.add(path); final String path = photos.get(id);
toBeDeleted.add(path);
deletedCnt++;
}
} }
notifyDeletion(cnt); notifyDeletion(deletedCnt);
} }
private void notifyDeletion(int cnt) { private void notifyDeletion(int cnt) {