diff --git a/app/src/main/java/com/nextcloud/client/database/dao/FileDao.kt b/app/src/main/java/com/nextcloud/client/database/dao/FileDao.kt index 21a7e34d7032..042f9b819781 100644 --- a/app/src/main/java/com/nextcloud/client/database/dao/FileDao.kt +++ b/app/src/main/java/com/nextcloud/client/database/dao/FileDao.kt @@ -48,8 +48,8 @@ interface FileDao { fun getFolderContent(parentId: Long): List @Query( - "SELECT * FROM filelist WHERE modified >= :startDate" + - " AND modified < :endDate" + + "SELECT * FROM filelist WHERE created >= :startDate" + + " AND created < :endDate" + " AND (content_type LIKE 'image/%' OR content_type LIKE 'video/%')" + " AND file_owner = :fileOwner" + " ORDER BY ${ProviderTableMeta.FILE_DEFAULT_SORT_ORDER}" diff --git a/app/src/main/java/com/nextcloud/client/database/entity/FileEntity.kt b/app/src/main/java/com/nextcloud/client/database/entity/FileEntity.kt index b6a4aea7be06..3e2cc0f21983 100644 --- a/app/src/main/java/com/nextcloud/client/database/entity/FileEntity.kt +++ b/app/src/main/java/com/nextcloud/client/database/entity/FileEntity.kt @@ -43,7 +43,7 @@ data class FileEntity( @ColumnInfo(name = ProviderTableMeta.FILE_PARENT) val parent: Long?, @ColumnInfo(name = ProviderTableMeta.FILE_CREATION) - val creation: Long?, + val created: Long?, @ColumnInfo(name = ProviderTableMeta.FILE_MODIFIED) val modified: Long?, @ColumnInfo(name = ProviderTableMeta.FILE_CONTENT_TYPE) diff --git a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index 514d1b031eef..cbdb66f6056c 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -893,7 +893,7 @@ private OCFile createFileInstance(FileEntity fileEntity) { } } ocFile.setFileLength(nullToZero(fileEntity.getContentLength())); - ocFile.setCreationTimestamp(nullToZero(fileEntity.getCreation())); + ocFile.setCreationTimestamp(nullToZero(fileEntity.getCreated())); ocFile.setModificationTimestamp(nullToZero(fileEntity.getModified())); ocFile.setModificationTimestampAtLastSyncForData(nullToZero(fileEntity.getModifiedAtLastSyncForData())); ocFile.setLastSyncDateForProperties(nullToZero(fileEntity.getLastSyncDate())); diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.java index 830273d97e78..610d59f346e3 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.java @@ -121,12 +121,6 @@ protected void onPostExecute(GallerySearchTask.Result result) { photoFragment.setLoading(false); photoFragment.searchCompleted(result.emptySearch, result.lastTimestamp); - - if (result.success && photoFragment.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { - photoFragment.showAllGalleryItems(); - } else { - photoFragment.setEmptyListMessage(SearchType.GALLERY_SEARCH); - } } } @@ -146,52 +140,40 @@ private boolean parseMedia(long startDate, long endDate, List remoteFile Map localFilesMap = RefreshFolderOperation.prefillLocalFilesMap(null, storageManager.getGalleryItems(startDate * 1000L, endDate * 1000L)); - List filesToAdd = new ArrayList<>(); - List filesToUpdate = new ArrayList<>(); + long filesAdded = 0, filesUpdated = 0, filesDeleted = 0, unchangedFiles = 0; - OCFile localFile; for (Object file : remoteFiles) { OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) file); - - localFile = localFilesMap.remove(ocFile.getRemotePath()); + OCFile localFile = localFilesMap.remove(ocFile.getRemotePath()); if (localFile == null) { // add new file - filesToAdd.add(ocFile); + storageManager.saveFile(ocFile); + filesAdded++; } else if (!localFile.getEtag().equals(ocFile.getEtag())) { // update file ocFile.setLastSyncDateForData(System.currentTimeMillis()); - filesToUpdate.add(ocFile); + storageManager.saveFile(ocFile); + filesUpdated++; + } else { + unchangedFiles++; } } - // add new files - for (OCFile file : filesToAdd) { - storageManager.saveFile(file); - } - - // update existing files - for (OCFile file : filesToUpdate) { - storageManager.saveFile(file); - } - // existing files to remove + filesDeleted = localFilesMap.values().size(); + for (OCFile file : localFilesMap.values()) { storageManager.removeFile(file, true, true); } Log_OC.d(this, "Gallery search result:" + - " new: " + filesToAdd.size() + - " updated: " + filesToUpdate.size() + - " deleted: " + localFilesMap.size()); - - return didNotFindNewResults(filesToAdd, filesToUpdate, localFilesMap.values()); - } + " new: " + filesAdded + + " updated: " + filesUpdated + + " deleted: " + filesDeleted + + " unchanged: " + unchangedFiles); - private boolean didNotFindNewResults(List filesToAdd, - List filesToUpdate, - Collection filesToRemove) { - return filesToAdd.isEmpty() && filesToUpdate.isEmpty() && filesToRemove.isEmpty(); + return (filesAdded + filesUpdated + filesDeleted + unchangedFiles > 0) ? false : true; } public static class Result { diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java index 8e9c3edf75a0..6afa550d0aeb 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java @@ -232,16 +232,17 @@ private void searchAndDisplay() { @SuppressLint("NotifyDataSetChanged") public void searchCompleted(boolean emptySearch, long lastTimeStamp) { photoSearchQueryRunning = false; - mAdapter.notifyDataSetChanged(); - if (mAdapter.isEmpty()) { + if (emptySearch && mAdapter.isEmpty()) { setEmptyListMessage(SearchType.GALLERY_SEARCH); + return; } - - if (emptySearch && mAdapter.getItemCount() > 0) { - Log_OC.d(this, "End gallery search"); + if(!emptySearch) { + mAdapter.notifyDataSetChanged(); + this.showAllGalleryItems(); return; } + if (daySpan == 30) { daySpan = 90; } else if (daySpan == 90) {