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
modificationTimestamp = 746443755000
parentId = sut.storageManager.getFileByEncryptedRemotePath("/").fileId
livePhoto = "/video.mov"
linkedFileIdForLivePhoto = "/video.mov"
sut.storageManager.saveFile(this)
}

View file

@ -512,7 +512,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
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_LIVE_PHOTO, file.getLivePhoto());
cv.put(ProviderTableMeta.FILE_METADATA_LIVE_PHOTO, file.getLinkedFileIdForLivePhoto());
return cv;
}

View file

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

View file

@ -2100,7 +2100,7 @@ public class FileDisplayActivity extends FileActivity
public void startImagePreview(OCFile file, boolean showPreview) {
Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
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));
if (showPreview) {
startActivity(showDetailsIntent);

View file

@ -86,11 +86,8 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import androidx.annotation.NonNull;
@ -397,31 +394,34 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
}
private void mergeOCFilesForLivePhoto() {
Map<Long, OCFile> livePhotoMap = new HashMap<>();
List<OCFile> filesToRemove = new ArrayList<>();
for (Iterator<OCFile> iterator = mFiles.iterator(); iterator.hasNext();) {
OCFile file = iterator.next();
Long fileId = file.getFileId();
OCFile existingFile = livePhotoMap.get(fileId);
for (int i = 0; i < mFiles.size(); i++) {
OCFile file = mFiles.get(i);
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())) {
existingFile.videoOfLivePhoto = file;
iterator.remove();
} else if (MimeTypeUtil.isVideo(existingFile.getMimeType())) {
file.videoOfLivePhoto = existingFile;
iterator.remove();
nextFile.livePhotoVideo = file;
filesToRemove.add(file);
} else if (MimeTypeUtil.isVideo(nextFile.getMimeType())) {
file.livePhotoVideo = nextFile;
filesToRemove.add(nextFile);
}
}
} else {
livePhotoMap.put(fileId, file);
}
}
livePhotoMap.clear();
mFiles.removeAll(filesToRemove);
filesToRemove.clear();
}
private void updateLivePhotoIndicators(ListGridImageViewHolder holder, OCFile file) {
boolean isLivePhoto = file.getLivePhoto() != null;
boolean isLivePhoto = file.getLinkedFileIdForLivePhoto() != null;
if (holder instanceof OCFileListItemViewHolder) {
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.ThumbnailsCacheManager;
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.RemoveFilesDialogFragment;
import com.owncloud.android.ui.fragment.FileFragment;
@ -204,18 +203,16 @@ public class PreviewImageFragment extends FileFragment implements Injectable {
}
private void checkLivePhotoAvailability() {
String livePhoto = getFile().getLivePhoto();
OCFile livePhotoVideo = getFile().livePhotoVideo;
if (livePhoto != null) {
OCFile videoOfLivePhoto = getFile().videoOfLivePhoto;
if (livePhotoVideo == null) return;
binding.livePhotoIndicator.setVisibility(View.VISIBLE);
ExtensionsKt.clickWithDebounce(binding.livePhotoIndicator, 4000L, () -> {
playLivePhoto(videoOfLivePhoto);
playLivePhoto(livePhotoVideo);
return null;
});
}
}
private void hideActionBar() {
PreviewImageActivity activity = (PreviewImageActivity) requireActivity();

View file

@ -151,7 +151,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
}
private void addVideoOfLivePhoto(OCFile file) {
file.videoOfLivePhoto = selectedFile;
file.livePhotoVideo = selectedFile;
}
@NonNull
@ -173,7 +173,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
if (file.isEncrypted()) {
fragment = FileDownloadFragment.newInstance(file, user, mObsoletePositions.contains(i));
} 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 {
fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(i), true);
}