add some checks to avoid displaying nonexistant files
This commit is contained in:
parent
f548ed833a
commit
34d015734e
3 changed files with 42 additions and 31 deletions
|
@ -212,24 +212,26 @@ public class MediaActivity extends SimpleActivity
|
||||||
final Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
|
final Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
|
||||||
final String pattern = Pattern.quote(mPath) + "/[^/]*";
|
final String pattern = Pattern.quote(mPath) + "/[^/]*";
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null) {
|
||||||
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
final String curPath = cursor.getString(pathIndex);
|
do {
|
||||||
if (curPath == null)
|
final String curPath = cursor.getString(pathIndex);
|
||||||
continue;
|
if (curPath == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (curPath.matches(pattern) && !mToBeDeleted.contains(curPath)) {
|
if (curPath.matches(pattern) && !mToBeDeleted.contains(curPath)) {
|
||||||
final File file = new File(curPath);
|
final File file = new File(curPath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED);
|
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED);
|
||||||
final long timestamp = cursor.getLong(dateIndex);
|
final long timestamp = cursor.getLong(dateIndex);
|
||||||
media.add(new Medium(file.getName(), curPath, (i == 1), timestamp, file.length()));
|
media.add(new Medium(file.getName(), curPath, (i == 1), timestamp, file.length()));
|
||||||
} else {
|
} else {
|
||||||
invalidFiles.add(file);
|
invalidFiles.add(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (cursor.moveToNext());
|
||||||
} while (cursor.moveToNext());
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -361,6 +361,7 @@ public class ViewPagerActivity extends SimpleActivity
|
||||||
|
|
||||||
private List<Medium> getMedia() {
|
private List<Medium> getMedia() {
|
||||||
final List<Medium> media = new ArrayList<>();
|
final List<Medium> media = new ArrayList<>();
|
||||||
|
final ArrayList<File> invalidFiles = new ArrayList<>();
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
|
@ -372,26 +373,35 @@ public class ViewPagerActivity extends SimpleActivity
|
||||||
final Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
|
final Cursor cursor = getContentResolver().query(uri, columns, where, args, null);
|
||||||
final String pattern = Pattern.quote(mDirectory) + "/[^/]*";
|
final String pattern = Pattern.quote(mDirectory) + "/[^/]*";
|
||||||
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null) {
|
||||||
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
if (cursor.moveToFirst()) {
|
||||||
do {
|
final int pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
|
||||||
final String curPath = cursor.getString(pathIndex);
|
do {
|
||||||
if (curPath == null)
|
final String curPath = cursor.getString(pathIndex);
|
||||||
continue;
|
if (curPath == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (curPath.matches(pattern) && !curPath.equals(mToBeDeleted) && !curPath.equals(mBeingDeleted)) {
|
final File file = new File(curPath);
|
||||||
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED);
|
if (!file.exists()) {
|
||||||
final long timestamp = cursor.getLong(dateIndex);
|
invalidFiles.add(file);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
final int sizeIndex = cursor.getColumnIndex(MediaStore.Images.Media.SIZE);
|
if (curPath.matches(pattern) && !curPath.equals(mToBeDeleted) && !curPath.equals(mBeingDeleted)) {
|
||||||
final long size = cursor.getLong(sizeIndex);
|
final int dateIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED);
|
||||||
media.add(new Medium("", curPath, i == 1, timestamp, size));
|
final long timestamp = cursor.getLong(dateIndex);
|
||||||
}
|
|
||||||
} while (cursor.moveToNext());
|
final int sizeIndex = cursor.getColumnIndex(MediaStore.Images.Media.SIZE);
|
||||||
|
final long size = cursor.getLong(sizeIndex);
|
||||||
|
media.add(new Medium(file.getName(), curPath, i == 1, timestamp, size));
|
||||||
|
}
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils.Companion.scanFiles(getApplicationContext(), invalidFiles);
|
||||||
Medium.Companion.setSorting(mConfig.getSorting());
|
Medium.Companion.setSorting(mConfig.getSorting());
|
||||||
Collections.sort(media);
|
Collections.sort(media);
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
|
@ -44,7 +44,6 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
|
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
|
|
||||||
val pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
|
val pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
|
||||||
do {
|
do {
|
||||||
val fullPath: String = cursor.getString(pathIndex) ?: continue
|
val fullPath: String = cursor.getString(pathIndex) ?: continue
|
||||||
|
|
Loading…
Reference in a new issue