mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 12:38:00 +01:00
couple more checks to prevent displaying invalid images
This commit is contained in:
parent
c8e77e5362
commit
4813a2d5ee
2 changed files with 13 additions and 1 deletions
|
@ -132,6 +132,7 @@ public class MainActivity extends AppCompatActivity
|
|||
final String[] columns = {MediaStore.Images.Media.DATA};
|
||||
final String order = MediaStore.Images.Media.DATE_MODIFIED + " DESC";
|
||||
final Cursor cursor = getContentResolver().query(uri, columns, null, null, order);
|
||||
final List<String> invalidFiles = new ArrayList<>();
|
||||
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
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 String fileDir = file.getParent();
|
||||
|
||||
if (!file.exists()) {
|
||||
invalidFiles.add(file.getAbsolutePath());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (directories.containsKey(fileDir)) {
|
||||
final Directory directory = directories.get(fileDir);
|
||||
final int newImageCnt = directory.getPhotoCnt() + 1;
|
||||
|
@ -152,6 +158,9 @@ public class MainActivity extends AppCompatActivity
|
|||
cursor.close();
|
||||
}
|
||||
|
||||
final String[] invalids = invalidFiles.toArray(new String[invalidFiles.size()]);
|
||||
MediaScannerConnection.scanFile(getApplicationContext(), invalids, null, null);
|
||||
|
||||
return directories;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,8 +138,11 @@ public class PhotosActivity extends AppCompatActivity
|
|||
do {
|
||||
final String curPath = cursor.getString(pathIndex);
|
||||
if (curPath.matches(pattern) && !toBeDeleted.contains(curPath)) {
|
||||
final File file = new File(curPath);
|
||||
if (file.exists()) {
|
||||
myPhotos.add(cursor.getString(pathIndex));
|
||||
}
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
cursor.close();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue