Parcourir la source

Revert "Merge pull request #12228 from nextcloud/feature/better-feedback-for-failed-uploads"

This reverts commit f71d5a4aee0f5ed6d6bda4b08e7ebe0d07f021e3, reversing
changes made to d3906c0f457cf9a45f796c4704df2103e08d9f17.
Andy Scherzinger il y a 1 an
Parent
commit
ad820fcc08

+ 24 - 54
app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt

@@ -23,7 +23,6 @@
 package com.nextcloud.client.jobs
 
 import android.accounts.Account
-import android.annotation.SuppressLint
 import android.app.NotificationManager
 import android.app.PendingIntent
 import android.content.Context
@@ -254,54 +253,9 @@ class FilesUploadWorker(
         // TODO generalize for automated uploads
     }
 
-    private fun createConflictResolveAction(context: Context, uploadFileOperation: UploadFileOperation): PendingIntent {
-        val intent = ConflictsResolveActivity.createIntent(
-            uploadFileOperation.file,
-            uploadFileOperation.user,
-            uploadFileOperation.ocUploadId,
-            Intent.FLAG_ACTIVITY_CLEAR_TOP,
-            context
-        )
-
-        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
-            PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_MUTABLE)
-        } else {
-            PendingIntent.getActivity(
-                context,
-                0,
-                intent,
-                PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
-            )
-        }
-    }
-
-    private fun addConflictResolveActionToNotification(uploadFileOperation: UploadFileOperation) {
-        val intent: PendingIntent = createConflictResolveAction(context, uploadFileOperation)
-
-        notificationBuilder.addAction(
-            R.drawable.ic_cloud_upload,
-            context.getString(R.string.upload_list_resolve_conflict),
-            intent
-        )
-    }
-
-    private fun addUploadListContentIntent(uploadFileOperation: UploadFileOperation) {
-        val uploadListIntent = createUploadListIntent(uploadFileOperation)
-
-        notificationBuilder.setContentIntent(
-            PendingIntent.getActivity(
-                context,
-                System.currentTimeMillis().toInt(),
-                uploadListIntent,
-                PendingIntent.FLAG_IMMUTABLE
-            )
-        )
-    }
-
     /**
      * adapted from [com.owncloud.android.files.services.FileUploader.notifyUploadResult]
      */
-    @SuppressLint("RestrictedApi")
     private fun notifyUploadResult(
         uploadFileOperation: UploadFileOperation,
         uploadResult: RemoteOperationResult<Any?>
@@ -330,7 +284,6 @@ class FilesUploadWorker(
                 // check file conflict
                 tickerId = R.string.uploader_upload_failed_sync_conflict_error
             }
-
             notificationBuilder
                 .setTicker(context.getString(tickerId))
                 .setContentTitle(context.getString(tickerId))
@@ -341,16 +294,23 @@ class FilesUploadWorker(
 
             val content = ErrorMessageAdapter.getErrorCauseMessage(uploadResult, uploadFileOperation, context.resources)
 
-            addUploadListContentIntent(uploadFileOperation)
-
-            if (uploadResult.code == ResultCode.SYNC_CONFLICT) {
-                addConflictResolveActionToNotification(uploadFileOperation)
-            }
-
             if (needsToUpdateCredentials) {
                 createUpdateCredentialsNotification(uploadFileOperation.user.toPlatformAccount())
+            } else {
+                val intent = if (uploadResult.code == ResultCode.SYNC_CONFLICT) {
+                    createResolveConflictIntent(uploadFileOperation)
+                } else {
+                    createUploadListIntent(uploadFileOperation)
+                }
+                notificationBuilder.setContentIntent(
+                    PendingIntent.getActivity(
+                        context,
+                        System.currentTimeMillis().toInt(),
+                        intent,
+                        PendingIntent.FLAG_IMMUTABLE
+                    )
+                )
             }
-
             notificationBuilder.setContentText(content)
             if (!uploadResult.isSuccess) {
                 notificationManager.notify(SecureRandom().nextInt(), notificationBuilder.build())
@@ -367,6 +327,16 @@ class FilesUploadWorker(
         )
     }
 
+    private fun createResolveConflictIntent(uploadFileOperation: UploadFileOperation): Intent {
+        return ConflictsResolveActivity.createIntent(
+            uploadFileOperation.file,
+            uploadFileOperation.user,
+            uploadFileOperation.ocUploadId,
+            Intent.FLAG_ACTIVITY_CLEAR_TOP,
+            context
+        )
+    }
+
     private fun createUpdateCredentialsNotification(account: Account) {
         // let the user update credentials with one click
         val updateAccountCredentials = Intent(context, AuthenticatorActivity::class.java)

+ 1 - 0
app/src/main/java/com/owncloud/android/MainApp.java

@@ -129,6 +129,7 @@ import static com.owncloud.android.ui.activity.ContactsPreferenceActivity.PREFER
  * Contains methods to build the "static" strings. These strings were before constants in different classes
  */
 public class MainApp extends MultiDexApplication implements HasAndroidInjector {
+
     public static final OwnCloudVersion OUTDATED_SERVER_VERSION = NextcloudVersion.nextcloud_23;
     public static final OwnCloudVersion MINIMUM_SUPPORTED_SERVER_VERSION = OwnCloudVersion.nextcloud_16;
 

+ 0 - 1
app/src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -1052,7 +1052,6 @@ public class FileUploader extends Service
         i.putExtra(FileUploader.KEY_ACCOUNT, user.toPlatformAccount());
         i.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload);
 
-        // FIXME Conflict files not uploading successfully
         if (useFilesUploadWorker(context)) {
             new FilesUploadHelper().retryUpload(upload, user);
         } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

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

@@ -89,7 +89,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 +235,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 +286,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 +383,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 +405,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 +423,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 +436,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 +457,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 +484,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,14 +503,21 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                                                          OCUpload item,
                                                          String status) {
         String remotePath = item.getRemotePath();
-        OCFile ocFile = storageManager.getFileByEncryptedRemotePath(remotePath);
+        OCFile ocFile = storageManager.getFileByPath(remotePath);
 
         if (ocFile == null) {
             // Remote file doesn't exist, try to refresh folder
-            OCFile folder = storageManager.getFileByEncryptedRemotePath(new File(remotePath).getParent() + "/");
-
+            OCFile folder = storageManager.getFileByPath(new File(remotePath).getParent() + "/");
             if (folder != null && folder.isFolder()) {
-                refreshFolderAndUpdateUI(itemViewHolder, user, folder, remotePath, item, status);
+                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);
+                        }
+                    }
+                });
                 return true;
             }
 
@@ -526,29 +533,6 @@ 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);
-        DisplayUtils.showSnackMessage(itemView, message);
-    }
-
     private void showItemConflictPopup(User user,
                                        ItemViewHolder itemViewHolder,
                                        OCUpload item,
@@ -576,13 +560,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,
@@ -614,7 +598,8 @@ 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.
@@ -695,8 +680,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);
@@ -706,7 +691,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);
@@ -778,17 +763,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());

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

@@ -912,7 +912,6 @@
     <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>