Bläddra i källkod

Add feedback for missing files

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 år sedan
förälder
incheckning
ca9c3f9ff5

+ 34 - 0
app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt

@@ -0,0 +1,34 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Alper Ozturk
+ * Copyright (C) 2023 Alper Ozturk
+ * Copyright (C) 2023 Nextcloud GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.utils.extensions
+
+import android.view.View
+import com.google.android.material.snackbar.Snackbar
+
+/**
+ * Shows a Snackbar message.
+ * @param view The view to attached.
+ * @param message The message to show.
+ */
+fun showSnackbar(view: View, message: String) {
+    Snackbar.make(view, message, Snackbar.LENGTH_LONG).show()
+}

+ 63 - 47
app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java

@@ -44,6 +44,7 @@ import com.nextcloud.client.core.Clock;
 import com.nextcloud.client.device.PowerManagementService;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.java.util.Optional;
+import com.nextcloud.utils.extensions.ViewExtensionsKt;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.databinding.UploadListHeaderBinding;
@@ -89,7 +90,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
     private Clock clock;
     private UploadGroup[] uploadGroups;
     private boolean showUser;
-    private final  ViewThemeUtils viewThemeUtils;
+    private final ViewThemeUtils viewThemeUtils;
 
     @Override
     public int getSectionCount() {
@@ -235,7 +236,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
         // file size
         if (item.getFileSize() != 0) {
             itemViewHolder.binding.uploadFileSize.setText(String.format("%s, ",
-                    DisplayUtils.bytesToHumanReadable(item.getFileSize())));
+                                                                        DisplayUtils.bytesToHumanReadable(item.getFileSize())));
         } else {
             itemViewHolder.binding.uploadFileSize.setText("");
         }
@@ -286,7 +287,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                             binder.removeDatatransferProgressListener(
                                 progressListener,
                                 progressListener.getUpload()   // the one that was added
-                            );
+                                                                     );
                         }
                         // ... then, bind the current progress bar to listen for updates
                         progressListener = new ProgressListener(item, itemViewHolder.binding.uploadProgressBar);
@@ -383,16 +384,16 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                     DisplayUtils.showSnackMessage(
                         v.getRootView().findViewById(android.R.id.content),
                         R.string.local_file_not_found_message
-                    );
+                                                 );
                 }
             });
-        } else if (item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED){
+        } else if (item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED) {
             itemViewHolder.binding.uploadListItemLayout.setOnClickListener(v -> onUploadedItemClick(item));
         }
 
 
         // click on thumbnail to open locally
-        if (item.getUploadStatus() != UploadStatus.UPLOAD_SUCCEEDED){
+        if (item.getUploadStatus() != UploadStatus.UPLOAD_SUCCEEDED) {
             itemViewHolder.binding.thumbnail.setOnClickListener(v -> onUploadingItemClick(item));
         }
 
@@ -405,17 +406,17 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
         fakeFileToCheatThumbnailsCacheManagerInterface.setMimeType(item.getMimeType());
 
         boolean allowedToCreateNewThumbnail = ThumbnailsCacheManager.cancelPotentialThumbnailWork(
-                fakeFileToCheatThumbnailsCacheManagerInterface, itemViewHolder.binding.thumbnail
-        );
+            fakeFileToCheatThumbnailsCacheManagerInterface, itemViewHolder.binding.thumbnail
+                                                                                                 );
 
         // TODO this code is duplicated; refactor to a common place
         if (MimeTypeUtil.isImage(fakeFileToCheatThumbnailsCacheManagerInterface)
-                && fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null &&
-                item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED) {
+            && fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId() != null &&
+            item.getUploadStatus() == UploadStatus.UPLOAD_SUCCEEDED) {
             // Thumbnail in Cache?
             Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
-                    String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId())
-            );
+                String.valueOf(fakeFileToCheatThumbnailsCacheManagerInterface.getRemoteId())
+                                                                            );
             if (thumbnail != null && !fakeFileToCheatThumbnailsCacheManagerInterface.isUpdateThumbnailNeeded()) {
                 itemViewHolder.binding.thumbnail.setImageBitmap(thumbnail);
             } else {
@@ -423,11 +424,11 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                 Optional<User> user = parentActivity.getUser();
                 if (allowedToCreateNewThumbnail && user.isPresent()) {
                     final ThumbnailsCacheManager.ThumbnailGenerationTask task =
-                            new ThumbnailsCacheManager.ThumbnailGenerationTask(
-                                itemViewHolder.binding.thumbnail,
-                                parentActivity.getStorageManager(),
-                                user.get()
-                            );
+                        new ThumbnailsCacheManager.ThumbnailGenerationTask(
+                            itemViewHolder.binding.thumbnail,
+                            parentActivity.getStorageManager(),
+                            user.get()
+                        );
                     if (thumbnail == null) {
                         if (MimeTypeUtil.isVideo(fakeFileToCheatThumbnailsCacheManagerInterface)) {
                             thumbnail = ThumbnailsCacheManager.mDefaultVideo;
@@ -436,20 +437,20 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                         }
                     }
                     final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
-                            new ThumbnailsCacheManager.AsyncThumbnailDrawable(
-                                parentActivity.getResources(),
-                                thumbnail,
-                                task
-                            );
+                        new ThumbnailsCacheManager.AsyncThumbnailDrawable(
+                            parentActivity.getResources(),
+                            thumbnail,
+                            task
+                        );
                     itemViewHolder.binding.thumbnail.setImageDrawable(asyncDrawable);
                     task.execute(new ThumbnailsCacheManager.ThumbnailGenerationTaskObject(
-                            fakeFileToCheatThumbnailsCacheManagerInterface, null));
+                        fakeFileToCheatThumbnailsCacheManagerInterface, null));
                 }
             }
 
             if ("image/png".equals(item.getMimeType())) {
                 itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources()
-                        .getColor(R.color.bg_default));
+                                                                        .getColor(R.color.bg_default));
             }
 
 
@@ -457,14 +458,14 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
             File file = new File(item.getLocalPath());
             // Thumbnail in Cache?
             Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
-                    String.valueOf(file.hashCode()));
+                String.valueOf(file.hashCode()));
             if (thumbnail != null) {
                 itemViewHolder.binding.thumbnail.setImageBitmap(thumbnail);
             } else {
                 // generate new Thumbnail
                 if (allowedToCreateNewThumbnail) {
                     final ThumbnailsCacheManager.ThumbnailGenerationTask task =
-                            new ThumbnailsCacheManager.ThumbnailGenerationTask(itemViewHolder.binding.thumbnail);
+                        new ThumbnailsCacheManager.ThumbnailGenerationTask(itemViewHolder.binding.thumbnail);
 
                     if (MimeTypeUtil.isVideo(file)) {
                         thumbnail = ThumbnailsCacheManager.mDefaultVideo;
@@ -484,7 +485,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
 
             if ("image/png".equalsIgnoreCase(item.getMimeType())) {
                 itemViewHolder.binding.thumbnail.setBackgroundColor(parentActivity.getResources()
-                        .getColor(R.color.bg_default));
+                                                                        .getColor(R.color.bg_default));
             }
         } else {
             if (optionalUser.isPresent()) {
@@ -503,21 +504,14 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                                                          OCUpload item,
                                                          String status) {
         String remotePath = item.getRemotePath();
-        OCFile ocFile = storageManager.getFileByPath(remotePath);
+        OCFile ocFile = storageManager.getFileByEncryptedRemotePath(remotePath);
 
         if (ocFile == null) {
             // Remote file doesn't exist, try to refresh folder
-            OCFile folder = storageManager.getFileByPath(new File(remotePath).getParent() + "/");
+            OCFile folder = storageManager.getFileByEncryptedRemotePath(new File(remotePath).getParent() + "/");
+
             if (folder != null && folder.isFolder()) {
-                this.refreshFolder(itemViewHolder, user, folder, (caller, result) -> {
-                    itemViewHolder.binding.uploadStatus.setText(status);
-                    if (result.isSuccess()) {
-                        OCFile file = storageManager.getFileByPath(remotePath);
-                        if (file != null) {
-                            this.openConflictActivity(file, item);
-                        }
-                    }
-                });
+                refreshFolderAndUpdateUI(itemViewHolder, user, folder, remotePath, item, status);
                 return true;
             }
 
@@ -533,6 +527,29 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
         return false;
     }
 
+    private void refreshFolderAndUpdateUI(ItemViewHolder holder, User user, OCFile folder, String remotePath, OCUpload item, String status) {
+        Context context = MainApp.getAppContext();
+
+        this.refreshFolder(context, holder, user, folder, (caller, result) -> {
+            holder.binding.uploadStatus.setText(status);
+
+            if (result.isSuccess()) {
+                OCFile file = storageManager.getFileByEncryptedRemotePath(remotePath);
+
+                if (file != null) {
+                    openConflictActivity(file, item);
+                } else {
+                    displayFileNotFoundError(holder.itemView, context);
+                }
+            }
+        });
+    }
+
+    private void displayFileNotFoundError(View itemView, Context context) {
+        String message = context.getString(R.string.uploader_file_not_found_message);
+        ViewExtensionsKt.showSnackbar(itemView, message);
+    }
+
     private void showItemConflictPopup(User user,
                                        ItemViewHolder itemViewHolder,
                                        OCUpload item,
@@ -560,13 +577,13 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
     }
 
     private void refreshFolder(
+        Context context,
         ItemViewHolder view,
         User user,
         OCFile folder,
         OnRemoteOperationListener listener) {
         view.binding.uploadListItemLayout.setClickable(false);
         view.binding.uploadStatus.setText(R.string.uploads_view_upload_status_fetching_server_version);
-        Context context = MainApp.getAppContext();
         new RefreshFolderOperation(folder,
                                    clock.getCurrentTime(),
                                    false,
@@ -598,8 +615,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
     }
 
     /**
-     * Gets the status text to show to the user according to the status and last result of the
-     * the given upload.
+     * Gets the status text to show to the user according to the status and last result of the the given upload.
      *
      * @param upload Upload to describe.
      * @return Text describing the status of the given upload.
@@ -680,8 +696,8 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
             case SSL_RECOVERABLE_PEER_UNVERIFIED:
                 status =
                     parentActivity.getString(
-                                R.string.uploads_view_upload_status_failed_ssl_certificate_not_trusted
-                        );
+                        R.string.uploads_view_upload_status_failed_ssl_certificate_not_trusted
+                                            );
                 break;
             case UNKNOWN:
                 status = parentActivity.getString(R.string.uploads_view_upload_status_unknown_fail);
@@ -691,7 +707,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                 break;
             case DELAYED_IN_POWER_SAVE_MODE:
                 status = parentActivity.getString(
-                        R.string.uploads_view_upload_status_waiting_exit_power_save_mode);
+                    R.string.uploads_view_upload_status_waiting_exit_power_save_mode);
                 break;
             case VIRUS_DETECTED:
                 status = parentActivity.getString(R.string.uploads_view_upload_status_virus_detected);
@@ -763,17 +779,17 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
      */
     private void onUploadedItemClick(OCUpload upload) {
         final OCFile file = parentActivity.getStorageManager().getFileByEncryptedRemotePath(upload.getRemotePath());
-        if (file == null){
+        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)){
+        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{
+        } else {
             Intent intent = new Intent(parentActivity, FileDisplayActivity.class);
             intent.setAction(Intent.ACTION_VIEW);
             intent.putExtra(FileDisplayActivity.KEY_FILE_PATH, upload.getRemotePath());

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -912,6 +912,7 @@
     <string name="failed_to_start_editor">Failed to start editor</string>
     <string name="create_rich_workspace">Add folder info</string>
     <string name="creates_rich_workspace">creates folder info</string>
+    <string name="uploader_file_not_found_message">File not found. Are you sure this file exist or conflict not solved before?</string>
     <string name="uploader_upload_failed_sync_conflict_error">File upload conflict</string>
     <string name="uploader_upload_failed_sync_conflict_error_content">Pick which version to keep of %1$s</string>
     <string name="upload_list_resolve_conflict">Resolve conflict</string>