Эх сурвалжийг харах

Use M3 for RemoveFilesDialog

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 жил өмнө
parent
commit
df4f93af02

+ 35 - 14
app/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.java

@@ -23,6 +23,7 @@ import android.app.Dialog;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.view.ActionMode;
 import android.view.ActionMode;
 
 
+import com.google.android.material.button.MaterialButton;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.di.Injectable;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.OCFile;
@@ -96,15 +97,20 @@ public class RemoveFilesDialogFragment extends ConfirmationDialogFragment implem
                 R.string.confirmation_remove_files_alert;
                 R.string.confirmation_remove_files_alert;
         }
         }
 
 
-        int localRemoveButton = (containsFolder || containsDown) ? R.string.confirmation_remove_local : -1;
-
         args.putInt(ARG_MESSAGE_RESOURCE_ID, messageStringId);
         args.putInt(ARG_MESSAGE_RESOURCE_ID, messageStringId);
         if (files.size() == SINGLE_SELECTION) {
         if (files.size() == SINGLE_SELECTION) {
-            args.putStringArray(ARG_MESSAGE_ARGUMENTS, new String[]{files.get(0).getFileName()});
+            args.putStringArray(ARG_MESSAGE_ARGUMENTS, new String[] { files.get(0).getFileName() } );
         }
         }
+
         args.putInt(ARG_POSITIVE_BTN_RES, R.string.file_delete);
         args.putInt(ARG_POSITIVE_BTN_RES, R.string.file_delete);
-        args.putInt(ARG_NEUTRAL_BTN_RES, R.string.file_keep);
-        args.putInt(ARG_NEGATIVE_BTN_RES, localRemoveButton);
+
+        if (containsFolder || containsDown) {
+            args.putInt(ARG_NEGATIVE_BTN_RES, R.string.confirmation_remove_local);
+            args.putInt(ARG_NEUTRAL_BTN_RES, R.string.file_keep);
+        } else {
+            args.putInt(ARG_NEGATIVE_BTN_RES, R.string.file_keep);
+        }
+
         args.putParcelableArrayList(ARG_TARGET_FILES, files);
         args.putParcelableArrayList(ARG_TARGET_FILES, files);
         frag.setArguments(args);
         frag.setArguments(args);
 
 
@@ -131,9 +137,16 @@ public class RemoveFilesDialogFragment extends ConfirmationDialogFragment implem
         AlertDialog alertDialog = (AlertDialog) getDialog();
         AlertDialog alertDialog = (AlertDialog) getDialog();
 
 
         if (alertDialog != null) {
         if (alertDialog != null) {
-            viewThemeUtils.platform.colorTextButtons(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE),
-                                                     alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE),
-                                                     alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
+            MaterialButton positiveButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+            viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton);
+
+            MaterialButton negativeButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
+            viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton);
+
+            MaterialButton neutralButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
+            if (neutralButton != null) {
+                viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(neutralButton);
+            }
         }
         }
     }
     }
 
 
@@ -141,10 +154,14 @@ public class RemoveFilesDialogFragment extends ConfirmationDialogFragment implem
     @Override
     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
     public Dialog onCreateDialog(Bundle savedInstanceState) {
         Dialog dialog = super.onCreateDialog(savedInstanceState);
         Dialog dialog = super.onCreateDialog(savedInstanceState);
-        mTargetFiles = getArguments().getParcelableArrayList(ARG_TARGET_FILES);
+        Bundle arguments = getArguments();
 
 
-        setOnConfirmationListener(this);
+        if (arguments == null) {
+            return dialog;
+        }
 
 
+        mTargetFiles = arguments.getParcelableArrayList(ARG_TARGET_FILES);
+        setOnConfirmationListener(this);
         return dialog;
         return dialog;
     }
     }
 
 
@@ -154,9 +171,7 @@ public class RemoveFilesDialogFragment extends ConfirmationDialogFragment implem
      */
      */
     @Override
     @Override
     public void onConfirmation(String callerTag) {
     public void onConfirmation(String callerTag) {
-        ComponentsGetter cg = (ComponentsGetter) getActivity();
-        cg.getFileOperationsHelper().removeFiles(mTargetFiles, false, false);
-        finishActionMode();
+        removeFiles(false);
     }
     }
 
 
     /**
     /**
@@ -164,8 +179,14 @@ public class RemoveFilesDialogFragment extends ConfirmationDialogFragment implem
      */
      */
     @Override
     @Override
     public void onCancel(String callerTag) {
     public void onCancel(String callerTag) {
+        removeFiles(true);
+    }
+
+    private void removeFiles(boolean onlyLocalCopy) {
         ComponentsGetter cg = (ComponentsGetter) getActivity();
         ComponentsGetter cg = (ComponentsGetter) getActivity();
-        cg.getFileOperationsHelper().removeFiles(mTargetFiles, true, false);
+        if (cg != null) {
+            cg.getFileOperationsHelper().removeFiles(mTargetFiles, onlyLocalCopy, false);
+        }
         finishActionMode();
         finishActionMode();
     }
     }