From 65f11e5d8c02b50f3bd1b4b1c2349732cdf5c88f Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Tue, 7 Nov 2023 18:31:39 +0100 Subject: [PATCH 1/4] open app internal preview on uploaded item click Signed-off-by: Jonas Mayer --- .../ui/activity/UploadListActivity.java | 11 +++++++ .../android/ui/adapter/UploadListAdapter.java | 31 +++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java index 7ebc62326ae5..2ad81abafd3d 100755 --- a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java @@ -347,6 +347,17 @@ public void onServiceDisconnected(ComponentName component) { } } + /** + * Switches to FileDisplayActivity and shows file (eg. image preview). + */ + public void openFile(String remotePath) { + Intent intent = new Intent(this, FileDisplayActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.putExtra(FileDisplayActivity.KEY_FILE_PATH, remotePath); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + } + /** * Once the file upload has changed its status -> update uploads list view */ diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java index 0298ef49bc0e..4ebc8c2ccb5a 100755 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java @@ -62,6 +62,7 @@ import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.ui.activity.ConflictsResolveActivity; import com.owncloud.android.ui.activity.FileActivity; +import com.owncloud.android.ui.activity.UploadListActivity; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.MimeTypeUtil; import com.owncloud.android.utils.theme.ViewThemeUtils; @@ -346,12 +347,15 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati itemViewHolder.binding.uploadRightButton.setOnClickListener(v -> removeUpload(item)); } itemViewHolder.binding.uploadRightButton.setVisibility(View.VISIBLE); - } else { // UploadStatus.UPLOAD_SUCCESS + } else { // UploadStatus.UPLOAD_SUCCEEDED itemViewHolder.binding.uploadRightButton.setVisibility(View.INVISIBLE); } itemViewHolder.binding.uploadListItemLayout.setOnClickListener(null); + // Set icon or thumbnail + itemViewHolder.binding.thumbnail.setImageResource(R.drawable.file); + // click on item if (item.getUploadStatus() == UploadStatus.UPLOAD_FAILED) { final UploadResult uploadResult = item.getLastResult(); @@ -381,12 +385,15 @@ public void onBindViewHolder(SectionedViewHolder holder, int section, int relati ); } }); - } else { - itemViewHolder.binding.uploadListItemLayout.setOnClickListener(v -> onUploadItemClick(item)); + } else if (item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED){ + itemViewHolder.binding.uploadListItemLayout.setOnClickListener(v -> onUploadedItemClick(item)); } - // Set icon or thumbnail - itemViewHolder.binding.thumbnail.setImageResource(R.drawable.file); + + // click on thumbnail to open locally + if (item.getUploadStatus() != UploadStatus.UPLOAD_SUCCEEDED){ + itemViewHolder.binding.thumbnail.setOnClickListener(v -> onUploadingItemClick(item)); + } /* * Cancellation needs do be checked and done before changing the drawable in fileIcon, or @@ -738,7 +745,10 @@ public final void loadUploadItemsFromDb() { notifyDataSetChanged(); } - private void onUploadItemClick(OCUpload file) { + /** + * Open local file. + */ + private void onUploadingItemClick(OCUpload file) { File f = new File(file.getLocalPath()); if (!f.exists()) { DisplayUtils.showSnackMessage(parentActivity, R.string.local_file_not_found_message); @@ -747,6 +757,15 @@ private void onUploadItemClick(OCUpload file) { } } + /** + * Open remote file. + */ + private void onUploadedItemClick(OCUpload file) { + if (parentActivity instanceof UploadListActivity uploadListActivity) { + uploadListActivity.openFile(file.getRemotePath()); + } + } + /** * Open file with app associates with its MIME type. If MIME type unknown, show list with all apps. From c79205a465b7d82dd0c04091818cd1f3bdc491df Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Mon, 13 Nov 2023 11:27:56 +0100 Subject: [PATCH 2/4] handle FileDisplayActivity openFileByPath request failed (e.g. file deleted) Signed-off-by: Jonas Mayer --- .../ui/activity/FileDisplayActivity.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index cb7013cd1ce2..cac42bf18894 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -2507,8 +2507,7 @@ private void openFile(User user, String fileId) { setUser(user); if (fileId == null) { - dismissLoadingDialog(); - DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file)); + onFileRequestError(null); return; } @@ -2529,8 +2528,7 @@ private void openFileByPath(User user, String filepath) { setUser(user); if (filepath == null) { - dismissLoadingDialog(); - DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file)); + onFileRequestError(null); return; } @@ -2544,8 +2542,7 @@ private void openFileByPath(User user, String filepath) { try { client = clientFactory.create(user); } catch (ClientFactory.CreationException e) { - dismissLoadingDialog(); - DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file)); + onFileRequestError(null); return; } @@ -2554,9 +2551,16 @@ private void openFileByPath(User user, String filepath) { client, storageManager, user); - asyncRunner.postQuickTask(getRemoteFileTask, this::onFileRequestResult, null); + asyncRunner.postQuickTask(getRemoteFileTask, this::onFileRequestResult, this::onFileRequestError); + } + + private Unit onFileRequestError(Throwable throwable) { + dismissLoadingDialog(); + DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file)); + return null; } + private Unit onFileRequestResult(GetRemoteFileTask.Result result) { dismissLoadingDialog(); From ceeba2660858370df2d0585d19e41bc83ffafcf3 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Tue, 14 Nov 2023 12:40:52 +0100 Subject: [PATCH 3/4] view images in uploads tab and do everything in UploadListActivity Signed-off-by: Jonas Mayer --- .../ui/activity/UploadListActivity.java | 11 --------- .../android/ui/adapter/UploadListAdapter.java | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java index 2ad81abafd3d..7ebc62326ae5 100755 --- a/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java @@ -347,17 +347,6 @@ public void onServiceDisconnected(ComponentName component) { } } - /** - * Switches to FileDisplayActivity and shows file (eg. image preview). - */ - public void openFile(String remotePath) { - Intent intent = new Intent(this, FileDisplayActivity.class); - intent.setAction(Intent.ACTION_VIEW); - intent.putExtra(FileDisplayActivity.KEY_FILE_PATH, remotePath); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); - } - /** * Once the file upload has changed its status -> update uploads list view */ diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java index 4ebc8c2ccb5a..821d44ac3c7a 100755 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java @@ -62,7 +62,8 @@ import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.ui.activity.ConflictsResolveActivity; import com.owncloud.android.ui.activity.FileActivity; -import com.owncloud.android.ui.activity.UploadListActivity; +import com.owncloud.android.ui.activity.FileDisplayActivity; +import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.MimeTypeUtil; import com.owncloud.android.utils.theme.ViewThemeUtils; @@ -760,9 +761,24 @@ private void onUploadingItemClick(OCUpload file) { /** * Open remote file. */ - private void onUploadedItemClick(OCUpload file) { - if (parentActivity instanceof UploadListActivity uploadListActivity) { - uploadListActivity.openFile(file.getRemotePath()); + private void onUploadedItemClick(OCUpload upload) { + final OCFile file = parentActivity.getStorageManager().getFileByEncryptedRemotePath(upload.getRemotePath()); + if (file == null){ + DisplayUtils.showSnackMessage(parentActivity, R.string.error_retrieving_file); + Log_OC.i(TAG, "Could not find uploaded file on remote."); + return; + } + + if (PreviewImageFragment.canBePreviewed(file)){ + //show image preview and stay in uploads tab + Intent intent = FileDisplayActivity.openFileIntent(parentActivity, parentActivity.getUser().get(), file); + parentActivity.startActivity(intent); + }else{ + Intent intent = new Intent(parentActivity, FileDisplayActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.putExtra(FileDisplayActivity.KEY_FILE_PATH, upload.getRemotePath()); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + parentActivity.startActivity(intent); } } From 05c269c31b83f036a638f2371a23b5547313fe53 Mon Sep 17 00:00:00 2001 From: Jonas Mayer Date: Tue, 14 Nov 2023 17:54:24 +0100 Subject: [PATCH 4/4] add log message for onError of file request in FileDisplayActivity Signed-off-by: Jonas Mayer --- .../com/owncloud/android/ui/activity/FileDisplayActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index cac42bf18894..16478cd5b628 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -2557,6 +2557,7 @@ private void openFileByPath(User user, String filepath) { private Unit onFileRequestError(Throwable throwable) { dismissLoadingDialog(); DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file)); + Log_OC.e(TAG, "Requesting file from remote failed!", throwable); return null; }