From 5a225f876879a6b664711ae895f38059ff2f8110 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 6 Mar 2016 16:39:12 +0100 Subject: [PATCH] do not do anything we dont have to --- .../gallery/activities/PhotosActivity.java | 41 +++++++++++-------- .../gallery/activities/ViewPagerActivity.java | 25 +++++------ app/src/main/res/values/strings.xml | 2 +- 3 files changed, 37 insertions(+), 31 deletions(-) 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 729c2b5c5..dac087d5a 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/PhotosActivity.java @@ -150,33 +150,38 @@ public class PhotosActivity extends AppCompatActivity Helpers.showToast(this, R.string.deleting); final SparseBooleanArray items = gridView.getCheckedItemPositions(); int cnt = items.size(); - final String[] deletedPaths = new String[cnt]; for (int i = 0; i < cnt; i++) { final int id = items.keyAt(i); final String path = photos.get(id); toBeDeleted.add(path); - deletedPaths[i] = path; } - MediaScannerConnection.scanFile(this, deletedPaths, null, this); + notifyDeletion(cnt); } private void notifyDeletion(int cnt) { - final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout); - final Resources res = getResources(); - final String msg = res.getQuantityString(R.plurals.files_deleted, cnt, cnt); - snackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE); - snackbar.setAction(res.getString(R.string.undo), undoDeletion); - snackbar.setActionTextColor(Color.WHITE); - snackbar.show(); - isSnackbarShown = true; + photos = getPhotos(); + + if (photos.isEmpty()) { + deleteFiles(); + } else { + final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout); + final Resources res = getResources(); + final String msg = res.getQuantityString(R.plurals.files_deleted, cnt, cnt); + snackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE); + snackbar.setAction(res.getString(R.string.undo), undoDeletion); + snackbar.setActionTextColor(Color.WHITE); + snackbar.show(); + isSnackbarShown = true; + updateGridView(); + } } private void deleteFiles() { - if (snackbar == null) - return; + if (snackbar != null) { + snackbar.dismiss(); + } - snackbar.dismiss(); isSnackbarShown = false; for (String delPath : toBeDeleted) { @@ -186,7 +191,7 @@ public class PhotosActivity extends AppCompatActivity } final String[] deletedPaths = toBeDeleted.toArray(new String[toBeDeleted.size()]); - MediaScannerConnection.scanFile(this, deletedPaths, null, null); + MediaScannerConnection.scanFile(this, deletedPaths, null, this); } private View.OnClickListener undoDeletion = new View.OnClickListener() { @@ -195,12 +200,12 @@ public class PhotosActivity extends AppCompatActivity snackbar.dismiss(); isSnackbarShown = false; toBeDeleted.clear(); + photos = getPhotos(); updateGridView(); } }; private void updateGridView() { - photos = getPhotos(); if (!isDirEmpty()) { adapter.updateItems(photos); } @@ -260,8 +265,8 @@ public class PhotosActivity extends AppCompatActivity runOnUiThread(new Runnable() { @Override public void run() { - updateGridView(); - notifyDeletion(toBeDeleted.size()); + if (photos.isEmpty()) + finish(); } }); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index c02ac2347..027e51850 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -112,29 +112,30 @@ public class ViewPagerActivity extends AppCompatActivity } private void notifyDeletion() { - final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout); - final Resources res = getResources(); - snackbar = Snackbar.make(coordinator, res.getString(R.string.file_deleted), Snackbar.LENGTH_INDEFINITE); - snackbar.setAction(res.getString(R.string.undo), undoDeletion); - snackbar.setActionTextColor(Color.WHITE); - snackbar.show(); - isSnackbarShown = true; toBeDeleted = getCurrentFile().getAbsolutePath(); - if (photos.size() == 1) + if (photos.size() <= 1) { deleteFile(); - else + } else { + final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout); + final Resources res = getResources(); + final String curFileName = getCurrentFile().getName() + " "; + snackbar = Snackbar.make(coordinator, curFileName + res.getString(R.string.file_deleted), Snackbar.LENGTH_INDEFINITE); + snackbar.setAction(res.getString(R.string.undo), undoDeletion); + snackbar.setActionTextColor(Color.WHITE); + snackbar.show(); + isSnackbarShown = true; reloadViewPager(); + } } private void deleteFile() { if (toBeDeleted.isEmpty()) return; - if (snackbar == null) - return; + if (snackbar != null) + snackbar.dismiss(); - snackbar.dismiss(); isSnackbarShown = false; final File file = new File(toBeDeleted); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c4db7d16b..caf630520 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,7 +10,7 @@ Could not rename the file File name Extension - File deleted + deleted 1 file deleted