couple more checks to prevent displaying invalid images
This commit is contained in:
parent
c8e77e5362
commit
4813a2d5ee
|
@ -132,6 +132,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
final String[] columns = {MediaStore.Images.Media.DATA};
|
final String[] columns = {MediaStore.Images.Media.DATA};
|
||||||
final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
|
final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
|
||||||
final Cursor cursor = getContentResolver().query(uri, columns, null, null, order);
|
final Cursor cursor = getContentResolver().query(uri, columns, null, null, order);
|
||||||
|
final List<String> invalidFiles = new ArrayList<>();
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
|
@ -140,6 +141,11 @@ public class MainActivity extends AppCompatActivity
|
||||||
final File file = new File(path);
|
final File file = new File(path);
|
||||||
final String fileDir = file.getParent();
|
final String fileDir = file.getParent();
|
||||||
|
|
||||||
|
if (!file.exists()) {
|
||||||
|
invalidFiles.add(file.getAbsolutePath());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (directories.containsKey(fileDir)) {
|
if (directories.containsKey(fileDir)) {
|
||||||
final Directory directory = directories.get(fileDir);
|
final Directory directory = directories.get(fileDir);
|
||||||
final int newImageCnt = directory.getPhotoCnt() + 1;
|
final int newImageCnt = directory.getPhotoCnt() + 1;
|
||||||
|
@ -152,6 +158,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]);
|
||||||
|
MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null);
|
||||||
|
|
||||||
return directories;
|
return directories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,10 @@ public class PhotosActivity extends AppCompatActivity
|
||||||
do {
|
do {
|
||||||
final String curPath = cursor.getString(pathIndex);
|
final String curPath = cursor.getString(pathIndex);
|
||||||
if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) {
|
if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) {
|
||||||
myPhotos.add(cursor.getString(pathIndex));
|
final File file = new File(curPath);
|
||||||
|
if (file.exists()) {
|
||||||
|
myPhotos.add(cursor.getString(pathIndex));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
Loading…
Reference in New Issue