diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 9db0eb762..5ec35837e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -325,17 +325,20 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View val curPath = cursor.getString(pathIndex) ?: continue if (curPath != mToBeDeleted && curPath != mBeingDeleted) { val file = File(curPath) - if (file.exists()) { - if (file.parent != mDirectory) - continue + val size = cursor.getLongValue(MediaStore.Images.Media.SIZE) - val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) - val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) - val size = cursor.getLongValue(MediaStore.Images.Media.SIZE) - media.add(Medium(name, curPath, i == 1, timestamp, size)) - } else { + if (size == 0L) { invalidFiles.add(file) + continue } + + // exclude images of subdirectories + if (file.parent != mDirectory) + continue + + val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) + val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) + media.add(Medium(name, curPath, i == 1, timestamp, size)) } } while (cursor.moveToNext()) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index e2c7664bc..c33a834aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -50,18 +50,19 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va do { val fullPath = cursor.getString(pathIndex) ?: continue val file = File(fullPath) - val parentDir = file.parent + val size = cursor.getLongValue(MediaStore.Images.Media.SIZE) - if (!file.exists() || file.length() == 0L) { + if (size == 0L) { invalidFiles.add(file) continue } + val parentDir = file.parent if (directories.containsKey(parentDir)) { val directory: Directory = directories[parentDir]!! val newImageCnt = directory.mediaCnt + 1 directory.mediaCnt = newImageCnt - directory.addSize(file.length()) + directory.addSize(size) } else if (!mToBeDeleted.contains(parentDir)) { var dirName = context.getHumanizedFilename(parentDir) if (mConfig.getIsFolderHidden(parentDir)) { @@ -69,7 +70,6 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va } val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) - val size = cursor.getLongValue(MediaStore.Images.Media.SIZE) directories.put(parentDir, Directory(parentDir, fullPath, dirName, 1, timestamp, size)) } } while (cursor.moveToNext()) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 98d8cbf2e..8ffaa46c7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -49,17 +49,20 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo val curPath = cursor.getString(pathIndex) ?: continue if (!mToBeDeleted.contains(curPath)) { val file = File(curPath) - if (file.exists()) { - if (file.parent != mPath) - continue + val size = cursor.getLongValue(MediaStore.Images.Media.SIZE) - val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) - val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) - val size = cursor.getLongValue(MediaStore.Images.Media.SIZE) - media.add(Medium(name, curPath, i == 1, timestamp, size)) - } else { + if (size == 0L) { invalidFiles.add(file) + continue } + + // exclude images of subdirectories + if (file.parent != mPath) + continue + + val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) + val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED) + media.add(Medium(name, curPath, i == 1, timestamp, size)) } } while (cursor.moveToNext()) }