Browse Source

Increase performance for addVideoOCFileOfLivePhoto

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 năm trước cách đây
mục cha
commit
fdd10c2555

+ 14 - 37
app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -414,53 +414,30 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
     }
 
     public void addVideoOCFileOfLivePhoto() {
-        for (int i = 0; i < mFiles.size(); i++) {
-            for (int j = i + 1; j < mFiles.size(); j++) {
-                OCFile file = mFiles.get(i);
-                OCFile nextFile = mFiles.get(j);
+        HashMap<String, OCFile> livePhotoMap = new HashMap<>();
 
-                String fileLivePhoto = file.getLivePhoto();
-                String nextFileLivePhoto = nextFile.getLivePhoto();
+        for (OCFile file : mFiles) {
+            String fileLivePhoto = file.getLivePhoto();
+
+            if (fileLivePhoto != null) {
+                String fileLivePhotoName = extractFileName(fileLivePhoto);
 
-                if (fileLivePhoto != null && nextFileLivePhoto != null) {
-                    String fileLivePhotoName = extractFileName(fileLivePhoto);
-                    String nextFileLivePhotoName = extractFileName(nextFileLivePhoto);
+                if (livePhotoMap.containsKey(fileLivePhotoName)) {
+                    OCFile existingFile = livePhotoMap.get(fileLivePhotoName);
 
-                    if (fileLivePhotoName.equals(nextFileLivePhotoName)) {
+                    if (existingFile != null) {
                         if (MimeTypeUtil.isVideo(file.getMimeType())) {
-                            nextFile.videoOfLivePhoto = file;
-                        } else if (MimeTypeUtil.isVideo(nextFile.getMimeType())) {
-                            file.videoOfLivePhoto = nextFile;
+                            existingFile.videoOfLivePhoto = file;
+                        } else if (MimeTypeUtil.isVideo(existingFile.getMimeType())) {
+                            file.videoOfLivePhoto = existingFile;
+                            livePhotoMap.put(fileLivePhotoName, file);
                         }
                     }
-                }
-            }
-        }
-
-        /*
-
-
-
-
-        Map<String, OCFile> livePhotoToVideoMap = new HashMap<>();
-
-        for (OCFile file : mFiles) {
-            if (MimeTypeUtil.isVideo(file.getMimeType())) {
-                String livePhotoKey = file.getLivePhoto();
-                if (livePhotoToVideoMap.containsKey(livePhotoKey)) {
-                    OCFile previousVideo = livePhotoToVideoMap.get(livePhotoKey);
-
-                    if (previousVideo != null) {
-                        previousVideo.videoOfLivePhoto = file;
-                        file.videoOfLivePhoto = previousVideo;
-                    }
                 } else {
-                    livePhotoToVideoMap.put(livePhotoKey, file);
+                    livePhotoMap.put(fileLivePhotoName, file);
                 }
             }
         }
-         */
-
     }
 
     private void bindListItemViewHolder(ListItemViewHolder holder, OCFile file) {