From 34946a0e61607a9e4cc397465af38fa957052c6a Mon Sep 17 00:00:00 2001 From: eraser2021999 Date: Fri, 20 Jan 2023 21:24:03 +0200 Subject: [PATCH 1/2] #10882 Slow Media Tab View Signed-off-by: eraser2021999 Fixed unresponsiveness of the Media Tab (Photo Gallery) - more fluent scrolling. - implemented query search via created column and not modified to avoid cases when an older modified photo is display wrongly in the chronology; - changed some logic in media loading to improve the loading speed of the gallery; Not fixed: - some issue with selecting a custom folder as gallery folder, I'm unsure if it worked correctly or not since the application crashed a lot; - some UI issues with the gallery display rectangles; --- .../nextcloud/client/database/dao/FileDao.kt | 4 +- .../client/database/entity/FileEntity.kt | 2 +- .../datamodel/FileDataStorageManager.java | 2 +- .../ui/asynctasks/GallerySearchTask.java | 47 ++++++------------- .../android/ui/fragment/GalleryFragment.java | 11 +++-- 5 files changed, 24 insertions(+), 42 deletions(-) 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..0c241830873c 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,39 @@ 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); + filesAdded++; } else if (!localFile.getEtag().equals(ocFile.getEtag())) { // update file ocFile.setLastSyncDateForData(System.currentTimeMillis()); - filesToUpdate.add(ocFile); + filesUpdated++; + } else { + unchangedFiles++; } - } - - // add new files - for (OCFile file : filesToAdd) { - storageManager.saveFile(file); - } - - // update existing files - for (OCFile file : filesToUpdate) { - storageManager.saveFile(file); + storageManager.saveFile(ocFile); } // 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) { From 5c5729ffe658478aa99123b0be9cb512efb60348 Mon Sep 17 00:00:00 2001 From: eraser2021999 Date: Fri, 20 Jan 2023 21:58:04 +0200 Subject: [PATCH 2/2] Fixed typo Signed-off-by: eraser2021999 bcoticopol@gmail.com --- .../com/owncloud/android/ui/asynctasks/GallerySearchTask.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 0c241830873c..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 @@ -148,15 +148,16 @@ private boolean parseMedia(long startDate, long endDate, List remoteFile if (localFile == null) { // add new file + storageManager.saveFile(ocFile); filesAdded++; } else if (!localFile.getEtag().equals(ocFile.getEtag())) { // update file ocFile.setLastSyncDateForData(System.currentTimeMillis()); + storageManager.saveFile(ocFile); filesUpdated++; } else { unchangedFiles++; } - storageManager.saveFile(ocFile); } // existing files to remove