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++) {
if (items.valueAt(i)) {
final int id = items.keyAt(i); final int id = items.keyAt(i);
final String path = dirs.get(id).getPath(); final String path = dirs.get(id).getPath();
toBeDeleted.add(path); toBeDeleted.add(path);
deletedCnt++;
}
} }
notifyDeletion(cnt); notifyDeletion(deletedCnt);
} }
private void notifyDeletion(int cnt) { private void notifyDeletion(int cnt) {
@ -168,6 +172,7 @@ 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);
if (dir.exists()) {
final File[] files = dir.listFiles(); final File[] files = dir.listFiles();
for (File f : files) { for (File f : files) {
updatedFiles.add(f.getAbsolutePath()); updatedFiles.add(f.getAbsolutePath());
@ -176,6 +181,7 @@ public class MainActivity extends AppCompatActivity
updatedFiles.add(dir.getAbsolutePath()); updatedFiles.add(dir.getAbsolutePath());
dir.delete(); dir.delete();
} }
}
final String[] deletedPaths = updatedFiles.toArray(new String[updatedFiles.size()]); final String[] deletedPaths = updatedFiles.toArray(new String[updatedFiles.size()]);
MediaScannerConnection.scanFile(this, deletedPaths, null, null); MediaScannerConnection.scanFile(this, deletedPaths, null, null);

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++) {
if (items.valueAt(i)) {
final int id = items.keyAt(i); final int id = items.keyAt(i);
final String path = photos.get(id); final String path = photos.get(id);
toBeDeleted.add(path); toBeDeleted.add(path);
deletedCnt++;
}
} }
notifyDeletion(cnt); notifyDeletion(deletedCnt);
} }
private void notifyDeletion(int cnt) { private void notifyDeletion(int cnt) {