Parcourir la source

Upload list conflicts: replace trash icon with menu and add resolve action

Signed-off-by: Alice Gaudon <alice@gaudon.pro>
Alice Gaudon il y a 5 ans
Parent
commit
6540e3ef71

+ 75 - 40
src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java

@@ -38,6 +38,7 @@ import android.view.ViewGroup;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
+import android.widget.PopupMenu;
 import android.widget.ProgressBar;
 import android.widget.TextView;
 
@@ -335,14 +336,22 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
             });
 
         } else if (item.getUploadStatus() == UploadStatus.UPLOAD_FAILED) {
-            // Delete
-            itemViewHolder.button.setImageResource(R.drawable.ic_action_delete_grey);
+            if (item.getLastResult() == UploadResult.SYNC_CONFLICT) {
+                itemViewHolder.button.setImageResource(R.drawable.ic_dots_vertical);
+                itemViewHolder.button.setOnClickListener(view -> {
+                    if (optionalUser.isPresent()) {
+                        Account account = optionalUser.get().toPlatformAccount();
+                        showItemConflictPopup(
+                            itemViewHolder, item, account, status, view
+                        );
+                    }
+                });
+            } else {
+                // Delete
+                itemViewHolder.button.setImageResource(R.drawable.ic_action_delete_grey);
+                itemViewHolder.button.setOnClickListener(v -> removeUpload(item));
+            }
             itemViewHolder.button.setVisibility(View.VISIBLE);
-            itemViewHolder.button.setOnClickListener(v -> {
-                uploadsStorageManager.removeUpload(item);
-                loadUploadItemsFromDb();
-            });
-
         } else {    // UploadStatus.UPLOAD_SUCCESS
             itemViewHolder.button.setVisibility(View.INVISIBLE);
         }
@@ -354,40 +363,13 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
             final UploadResult uploadResult = item.getLastResult();
             itemViewHolder.itemLayout.setOnClickListener(v -> {
                 if (uploadResult == UploadResult.CREDENTIAL_ERROR) {
-                    parentActivity.getFileOperationsHelper().checkCurrentCredentials(
-                        item.getAccount(accountManager));
+                    parentActivity.getFileOperationsHelper().checkCurrentCredentials(item.getAccount(accountManager));
                     return;
-                } else if (uploadResult == UploadResult.SYNC_CONFLICT) {
-                    String remotePath = item.getRemotePath();
-                    OCFile ocFile = storageManager.getFileByPath(remotePath);
-
-                    if (ocFile == null) { // Remote file doesn't exist, try to refresh folder
-                        OCFile folder = storageManager.getFileByPath(new File(remotePath).getParent() + "/");
-                        if (folder != null && folder.isFolder()) {
-                            if (optionalUser.isPresent()) {
-                                Account userAccount = optionalUser.get().toPlatformAccount();
-                                this.refreshFolder(itemViewHolder, userAccount, folder, (caller, result) -> {
-                                    itemViewHolder.status.setText(status);
-                                    if (result.isSuccess()) {
-                                        OCFile file = storageManager.getFileByPath(remotePath);
-                                        if (file != null) {
-                                            this.openConflictActivity(file, item);
-                                        }
-                                    }
-                                });
-                            }
-                            return;
-                        }
-
-                        // Destination folder doesn't exist anymore
-                    }
-
-                    if (ocFile != null) {
-                        this.openConflictActivity(ocFile, item);
+                } else if (uploadResult == UploadResult.SYNC_CONFLICT && optionalUser.isPresent()) {
+                    Account account = optionalUser.get().toPlatformAccount();
+                    if (checkAndOpenConflictResolutionDialog(itemViewHolder, item, account, status)) {
                         return;
                     }
-
-                    // Remote file doesn't exist anymore = there is no more conflict
                 }
 
                 // not a credentials error
@@ -403,8 +385,7 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
                 }
             });
         } else {
-            itemViewHolder.itemLayout.setOnClickListener(v ->
-                    onUploadItemClick(item));
+            itemViewHolder.itemLayout.setOnClickListener(v -> onUploadItemClick(item));
         }
 
         // Set icon or thumbnail
@@ -509,6 +490,60 @@ public class UploadListAdapter extends SectionedRecyclerViewAdapter<SectionedVie
         }
     }
 
+    private boolean checkAndOpenConflictResolutionDialog(ItemViewHolder itemViewHolder, OCUpload item, Account account, String status) {
+        String remotePath = item.getRemotePath();
+        OCFile ocFile = storageManager.getFileByPath(remotePath);
+
+        if (ocFile == null) { // Remote file doesn't exist, try to refresh folder
+            OCFile folder = storageManager.getFileByPath(new File(remotePath).getParent() + "/");
+            if (folder != null && folder.isFolder()) {
+                this.refreshFolder(itemViewHolder, account, folder, (caller, result) -> {
+                    itemViewHolder.status.setText(status);
+                    if (result.isSuccess()) {
+                        OCFile file = storageManager.getFileByPath(remotePath);
+                        if (file != null) {
+                            this.openConflictActivity(file, item);
+                        }
+                    }
+                });
+                return true;
+            }
+
+            // Destination folder doesn't exist anymore
+        }
+
+        if (ocFile != null) {
+            this.openConflictActivity(ocFile, item);
+            return true;
+        }
+
+        // Remote file doesn't exist anymore = there is no more conflict
+        return false;
+    }
+
+    private void showItemConflictPopup(ItemViewHolder itemViewHolder, OCUpload item, Account account, String status, View view) {
+        PopupMenu popup = new PopupMenu(MainApp.getAppContext(), view);
+        popup.inflate(R.menu.upload_list_item_file_conflict);
+        popup.setOnMenuItemClickListener(i -> {
+            switch (i.getItemId()) {
+                case R.id.action_upload_list_resolve_conflict:
+                    checkAndOpenConflictResolutionDialog(itemViewHolder, item, account, status);
+                    break;
+                case R.id.action_upload_list_delete:
+                default:
+                    removeUpload(item);
+                    break;
+            }
+            return true;
+        });
+        popup.show();
+    }
+
+    private void removeUpload(OCUpload item) {
+        uploadsStorageManager.removeUpload(item);
+        loadUploadItemsFromDb();
+    }
+
     private void refreshFolder(ItemViewHolder view, Account account, OCFile folder, OnRemoteOperationListener listener) {
         view.itemLayout.setClickable(false);
         view.status.setText(R.string.uploads_view_upload_status_fetching_server_version);

+ 30 - 0
src/main/res/menu/upload_list_item_file_conflict.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Nextcloud Android client application
+
+  Copyright (C) 2019 Nextcloud GmbH.
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU 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 General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program. If not, see <https://www.gnu.org/licenses/>.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:id="@+id/action_upload_list_resolve_conflict"
+        android:icon="@drawable/ic_history"
+        android:title="@string/upload_list_resolve_conflict" />
+
+    <item
+        android:id="@+id/action_upload_list_delete"
+        android:title="@string/upload_list_delete"
+        android:icon="@drawable/nav_trashbin" />
+</menu>

+ 2 - 0
src/main/res/values/strings.xml

@@ -916,6 +916,8 @@
     <string name="edit_rich_workspace">edit folder info</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>
+    <string name="upload_list_delete">Delete</string>
     <string name="create_new">Create new</string>
     <string name="editor_placeholder" translatable="false">%1$s %2$s</string>