Эх сурвалжийг харах

Add auto play functionality

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 жил өмнө
parent
commit
ef60fcee22

+ 9 - 0
app/src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -357,6 +357,15 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
         return false;
     }
 
+    public String getFileNameWithoutExtension(String fileName) {
+        int dotIndex = fileName.lastIndexOf(".");
+        if (dotIndex > 0) {
+            return fileName.substring(0, dotIndex);
+        } else {
+            return fileName;
+        }
+    }
+
     public String getFileNameWithExtension(int fileNameLength) {
         String fileName = getFileName();
         String shortFileName = fileName.substring(0, Math.min(fileName.length(), fileNameLength));

+ 7 - 8
app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -401,26 +401,25 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         // 594c962d71b
         // Not needed for Grid mode unfortunately ListGridImageViewHolder interface used for List and Grid mode
         holder.getLivePhotoIndicatorSeparator().setVisibility(isLivePhoto ? (View.VISIBLE) : (View.GONE));
+
+        hideVideoFileOfLivePhoto(holder, file);
         addVideoOCFileOfLivePhoto();
     }
 
-    public static String extractFileName(String fileName) {
-        int dotIndex = fileName.lastIndexOf(".");
-        if (dotIndex > 0) {
-            return fileName.substring(0, dotIndex);
-        } else {
-            return fileName;
+    private void hideVideoFileOfLivePhoto(ListGridImageViewHolder holder, OCFile file) {
+        if (MimeTypeUtil.isVideo(file) && file.getLivePhoto() != null) {
+            holder.getItemLayout().setVisibility(View.GONE);
         }
     }
 
-    public void addVideoOCFileOfLivePhoto() {
+    private void addVideoOCFileOfLivePhoto() {
         HashMap<String, OCFile> livePhotoMap = new HashMap<>();
 
         for (OCFile file : mFiles) {
             String fileLivePhoto = file.getLivePhoto();
 
             if (fileLivePhoto != null) {
-                String fileLivePhotoName = extractFileName(fileLivePhoto);
+                String fileLivePhotoName = file.getFileNameWithoutExtension(fileLivePhoto);
 
                 if (livePhotoMap.containsKey(fileLivePhotoName)) {
                     OCFile existingFile = livePhotoMap.get(fileLivePhotoName);

+ 11 - 4
app/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -209,17 +209,24 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
         if (livePhoto != null) {
             binding.livePhotoIndicator.setVisibility(View.VISIBLE);
 
+            OCFile videoOfLivePhoto = getFile().videoOfLivePhoto;
+
+            // Automatically play live photo
+            playLivePhoto(videoOfLivePhoto);
+
+            // For replay functionality setOnLongClickListener
             binding.image.setOnLongClickListener(v -> {
-                OCFile videoOfLivePhoto = getFile().videoOfLivePhoto;
-                if (videoOfLivePhoto != null) {
-                    playLivePhoto(videoOfLivePhoto);
-                }
+                playLivePhoto(videoOfLivePhoto);
                 return true;
             });
         }
     }
 
     private void playLivePhoto(OCFile file) {
+        if (file == null) {
+            return;
+        }
+
         Fragment mediaFragment = PreviewMediaFragment.newInstance(file, accountManager.getUser(), 0, true);
         FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
         FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();