do not do anything we dont have to
This commit is contained in:
parent
3f562513c0
commit
5a225f8768
3 changed files with 37 additions and 31 deletions
|
@ -150,33 +150,38 @@ 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();
|
||||||
final String[] deletedPaths = new String[cnt];
|
|
||||||
for (int i = 0; i < cnt; i++) {
|
for (int i = 0; i < cnt; 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);
|
||||||
deletedPaths[i] = path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaScannerConnection.scanFile(this, deletedPaths, null, this);
|
notifyDeletion(cnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyDeletion(int cnt) {
|
private void notifyDeletion(int cnt) {
|
||||||
final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
|
photos = getPhotos();
|
||||||
final Resources res = getResources();
|
|
||||||
final String msg = res.getQuantityString(R.plurals.files_deleted, cnt, cnt);
|
if (photos.isEmpty()) {
|
||||||
snackbar = Snackbar.make(coordinator, msg, Snackbar.LENGTH_INDEFINITE);
|
deleteFiles();
|
||||||
snackbar.setAction(res.getString(R.string.undo), undoDeletion);
|
} else {
|
||||||
snackbar.setActionTextColor(Color.WHITE);
|
final CoordinatorLayout coordinator = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
|
||||||
snackbar.show();
|
final Resources res = getResources();
|
||||||
isSnackbarShown = true;
|
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() {
|
private void deleteFiles() {
|
||||||
if (snackbar == null)
|
if (snackbar != null) {
|
||||||
return;
|
snackbar.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
snackbar.dismiss();
|
|
||||||
isSnackbarShown = false;
|
isSnackbarShown = false;
|
||||||
|
|
||||||
for (String delPath : toBeDeleted) {
|
for (String delPath : toBeDeleted) {
|
||||||
|
@ -186,7 +191,7 @@ public class PhotosActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] deletedPaths = toBeDeleted.toArray(new String[toBeDeleted.size()]);
|
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() {
|
private View.OnClickListener undoDeletion = new View.OnClickListener() {
|
||||||
|
@ -195,12 +200,12 @@ public class PhotosActivity extends AppCompatActivity
|
||||||
snackbar.dismiss();
|
snackbar.dismiss();
|
||||||
isSnackbarShown = false;
|
isSnackbarShown = false;
|
||||||
toBeDeleted.clear();
|
toBeDeleted.clear();
|
||||||
|
photos = getPhotos();
|
||||||
updateGridView();
|
updateGridView();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void updateGridView() {
|
private void updateGridView() {
|
||||||
photos = getPhotos();
|
|
||||||
if (!isDirEmpty()) {
|
if (!isDirEmpty()) {
|
||||||
adapter.updateItems(photos);
|
adapter.updateItems(photos);
|
||||||
}
|
}
|
||||||
|
@ -260,8 +265,8 @@ public class PhotosActivity extends AppCompatActivity
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
updateGridView();
|
if (photos.isEmpty())
|
||||||
notifyDeletion(toBeDeleted.size());
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,29 +112,30 @@ public class ViewPagerActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyDeletion() {
|
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();
|
toBeDeleted = getCurrentFile().getAbsolutePath();
|
||||||
|
|
||||||
if (photos.size() == 1)
|
if (photos.size() <= 1) {
|
||||||
deleteFile();
|
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();
|
reloadViewPager();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteFile() {
|
private void deleteFile() {
|
||||||
if (toBeDeleted.isEmpty())
|
if (toBeDeleted.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (snackbar == null)
|
if (snackbar != null)
|
||||||
return;
|
snackbar.dismiss();
|
||||||
|
|
||||||
snackbar.dismiss();
|
|
||||||
isSnackbarShown = false;
|
isSnackbarShown = false;
|
||||||
|
|
||||||
final File file = new File(toBeDeleted);
|
final File file = new File(toBeDeleted);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<string name="rename_error">Could not rename the file</string>
|
<string name="rename_error">Could not rename the file</string>
|
||||||
<string name="file_name">File name</string>
|
<string name="file_name">File name</string>
|
||||||
<string name="extension">Extension</string>
|
<string name="extension">Extension</string>
|
||||||
<string name="file_deleted">File deleted</string>
|
<string name="file_deleted">deleted</string>
|
||||||
|
|
||||||
<plurals name="files_deleted">
|
<plurals name="files_deleted">
|
||||||
<item quantity="one">1 file deleted</item>
|
<item quantity="one">1 file deleted</item>
|
||||||
|
|
Loading…
Reference in a new issue