Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,24 @@ class GallerySearchTask(
private fun handleSuccess(operationResult: RemoteOperationResult<*>): Result {
val remoteFiles = operationResult.data.filterIsInstance<RemoteFile>()
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<RemoteFile>): Long =
remoteFiles.lastOrNull()?.modifiedTimestamp?.div(MILLIS_PER_SECOND) ?: NO_TIMESTAMP

private fun parseMedia(startDate: Long, endDate: Long, remoteFiles: List<RemoteFile>): 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<RemoteFile>) {
val localFiles = storageManager.getGalleryItems(startDate * MILLIS_PER_SECOND, endDate * MILLIS_PER_SECOND)

if (BuildConfig.DEBUG) {
Expand Down Expand Up @@ -149,8 +159,6 @@ class GallerySearchTask(
" deleted: $filesDeleted unchanged: $unchangedFiles"
)
}

return filesAdded <= 0 && filesUpdated <= 0 && filesDeleted <= 0
}

private fun enrichFromLocalStorage(file: RemoteFile) {
Expand Down
Loading