Use file id for merging live photos

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-12-08 12:35:51 +01:00
parent b48c027fca
commit 7719b2eb76
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
7 changed files with 33 additions and 36 deletions

View file

@ -72,7 +72,7 @@ class OCFileListFragmentStaticServerIT : AbstractIT() {
fileLength = 3072000 fileLength = 3072000
modificationTimestamp = 746443755000 modificationTimestamp = 746443755000
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
livePhoto = "/video.mov" linkedFileIdForLivePhoto = "/video.mov"
sut.storageManager.saveFile(this) sut.storageManager.saveFile(this)
} }

View file

@ -512,7 +512,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp()); cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
cv.put(ProviderTableMeta.FILE_METADATA_SIZE, gson.toJson(file.getImageDimension())); cv.put(ProviderTableMeta.FILE_METADATA_SIZE, gson.toJson(file.getImageDimension()));
cv.put(ProviderTableMeta.FILE_METADATA_GPS, gson.toJson(file.getGeoLocation())); cv.put(ProviderTableMeta.FILE_METADATA_GPS, gson.toJson(file.getGeoLocation()));
cv.put(ProviderTableMeta.FILE_METADATA_LIVE_PHOTO, file.getLivePhoto()); cv.put(ProviderTableMeta.FILE_METADATA_LIVE_PHOTO, file.getLinkedFileIdForLivePhoto());
return cv; return cv;
} }

View file

@ -85,7 +85,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
private long lastSyncDateForData; private long lastSyncDateForData;
private boolean previewAvailable; private boolean previewAvailable;
private String livePhoto; private String livePhoto;
public OCFile videoOfLivePhoto; public OCFile livePhotoVideo;
private String etag; private String etag;
private String etagOnServer; private String etagOnServer;
private boolean sharedViaLink; private boolean sharedViaLink;
@ -249,7 +249,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
dest.writeString(livePhoto); dest.writeString(livePhoto);
} }
public String getLivePhoto() { public String getLinkedFileIdForLivePhoto() {
return livePhoto; return livePhoto;
} }

View file

@ -2100,7 +2100,7 @@ public class FileDisplayActivity extends FileActivity
public void startImagePreview(OCFile file, boolean showPreview) { public void startImagePreview(OCFile file, boolean showPreview) {
Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class); Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
showDetailsIntent.putExtra(EXTRA_FILE, file); showDetailsIntent.putExtra(EXTRA_FILE, file);
showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE, file.videoOfLivePhoto); showDetailsIntent.putExtra(EXTRA_LIVE_PHOTO_FILE, file.livePhotoVideo);
showDetailsIntent.putExtra(EXTRA_USER, getUser().orElseThrow(RuntimeException::new)); showDetailsIntent.putExtra(EXTRA_USER, getUser().orElseThrow(RuntimeException::new));
if (showPreview) { if (showPreview) {
startActivity(showDetailsIntent); startActivity(showDetailsIntent);

View file

@ -86,11 +86,8 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Set; import java.util.Set;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -397,31 +394,34 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
} }
private void mergeOCFilesForLivePhoto() { private void mergeOCFilesForLivePhoto() {
Map<Long, OCFile> livePhotoMap = new HashMap<>(); List<OCFile> filesToRemove = new ArrayList<>();
for (Iterator<OCFile> iterator = mFiles.iterator(); iterator.hasNext();) { for (int i = 0; i < mFiles.size(); i++) {
OCFile file = iterator.next(); OCFile file = mFiles.get(i);
Long fileId = file.getFileId();
OCFile existingFile = livePhotoMap.get(fileId);
if (existingFile != null) { for (int j = i + 1; j < mFiles.size(); j++) {
OCFile nextFile = mFiles.get(j);
String fileLocalId = String.valueOf(file.getLocalId());
String nextFileLinkedLocalId = nextFile.getLinkedFileIdForLivePhoto();
if (fileLocalId.equals(nextFileLinkedLocalId)) {
if (MimeTypeUtil.isVideo(file.getMimeType())) { if (MimeTypeUtil.isVideo(file.getMimeType())) {
existingFile.videoOfLivePhoto = file; nextFile.livePhotoVideo = file;
iterator.remove(); filesToRemove.add(file);
} else if (MimeTypeUtil.isVideo(existingFile.getMimeType())) { } else if (MimeTypeUtil.isVideo(nextFile.getMimeType())) {
file.videoOfLivePhoto = existingFile; file.livePhotoVideo = nextFile;
iterator.remove(); filesToRemove.add(nextFile);
}
} }
} else {
livePhotoMap.put(fileId, file);
} }
} }
livePhotoMap.clear(); mFiles.removeAll(filesToRemove);
filesToRemove.clear();
} }
private void updateLivePhotoIndicators(ListGridImageViewHolder holder, OCFile file) { private void updateLivePhotoIndicators(ListGridImageViewHolder holder, OCFile file) {
boolean isLivePhoto = file.getLivePhoto() != null; boolean isLivePhoto = file.getLinkedFileIdForLivePhoto() != null;
if (holder instanceof OCFileListItemViewHolder) { if (holder instanceof OCFileListItemViewHolder) {
holder.getLivePhotoIndicator().setVisibility(isLivePhoto ? (View.VISIBLE) : (View.GONE)); holder.getLivePhotoIndicator().setVisibility(isLivePhoto ? (View.VISIBLE) : (View.GONE));

View file

@ -61,7 +61,6 @@ import com.owncloud.android.databinding.PreviewImageFragmentBinding;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment; import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.FileFragment;
@ -204,18 +203,16 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
} }
private void checkLivePhotoAvailability() { private void checkLivePhotoAvailability() {
String livePhoto = getFile().getLivePhoto(); OCFile livePhotoVideo = getFile().livePhotoVideo;
if (livePhoto != null) { if (livePhotoVideo == null) return;
OCFile videoOfLivePhoto = getFile().videoOfLivePhoto;
binding.livePhotoIndicator.setVisibility(View.VISIBLE); binding.livePhotoIndicator.setVisibility(View.VISIBLE);
ExtensionsKt.clickWithDebounce(binding.livePhotoIndicator, 4000L, () -> { ExtensionsKt.clickWithDebounce(binding.livePhotoIndicator, 4000L, () -> {
playLivePhoto(videoOfLivePhoto); playLivePhoto(livePhotoVideo);
return null; return null;
}); });
} }
}
private void hideActionBar() { private void hideActionBar() {
PreviewImageActivity activity = (PreviewImageActivity) requireActivity(); PreviewImageActivity activity = (PreviewImageActivity) requireActivity();

View file

@ -151,7 +151,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
} }
private void addVideoOfLivePhoto(OCFile file) { private void addVideoOfLivePhoto(OCFile file) {
file.videoOfLivePhoto = selectedFile; file.livePhotoVideo = selectedFile;
} }
@NonNull @NonNull
@ -173,7 +173,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
if (file.isEncrypted()) { if (file.isEncrypted()) {
fragment = FileDownloadFragment.newInstance(file, user, mObsoletePositions.contains(i)); fragment = FileDownloadFragment.newInstance(file, user, mObsoletePositions.contains(i));
} else if (PreviewMediaFragment.canBePreviewed(file)) { } else if (PreviewMediaFragment.canBePreviewed(file)) {
fragment = PreviewMediaFragment.newInstance(file, user, 0, false, file.videoOfLivePhoto != null); fragment = PreviewMediaFragment.newInstance(file, user, 0, false, file.livePhotoVideo != null);
} else { } else {
fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(i), true); fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(i), true);
} }