diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.kt b/app/src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.kt index d43085d6ac99..0c90fb707e5b 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.kt +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.kt @@ -89,14 +89,24 @@ class GallerySearchTask( private fun handleSuccess(operationResult: RemoteOperationResult<*>): Result { val remoteFiles = operationResult.data.filterIsInstance() val lastTimestamp = findLastTimestamp(remoteFiles) - val emptySearch = parseMedia(lastTimestamp, endDate, remoteFiles) + parseMedia(lastTimestamp, endDate, remoteFiles) + val emptySearch = remoteFiles.isEmpty() return Result(operationResult.code, emptySearch, lastTimestamp) } private fun findLastTimestamp(remoteFiles: List): Long = remoteFiles.lastOrNull()?.modifiedTimestamp?.div(MILLIS_PER_SECOND) ?: NO_TIMESTAMP - private fun parseMedia(startDate: Long, endDate: Long, remoteFiles: List): Boolean { + /** + * Sync local media files with theirs remote counterparts for the provided timespan (downloads missing, + * deletes removed ones, updates metadata). + * + * @param startDate start of timespan + * @param endDate end of timespan + * @param remoteFiles list of remote files in the folder. Only ones in the provided timespan are taken into + * consideration. + */ + private fun parseMedia(startDate: Long, endDate: Long, remoteFiles: List) { val localFiles = storageManager.getGalleryItems(startDate * MILLIS_PER_SECOND, endDate * MILLIS_PER_SECOND) if (BuildConfig.DEBUG) { @@ -149,8 +159,6 @@ class GallerySearchTask( " deleted: $filesDeleted unchanged: $unchangedFiles" ) } - - return filesAdded <= 0 && filesUpdated <= 0 && filesDeleted <= 0 } private fun enrichFromLocalStorage(file: RemoteFile) {