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

Merge pull request #3114 from nextcloud/notificationButtonHandling

Notification button handling
Andy Scherzinger 6 жил өмнө
parent
commit
0c525db644

+ 15 - 3
src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java

@@ -136,18 +136,23 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
         // add action buttons
         // add action buttons
         holder.buttons.removeAllViews();
         holder.buttons.removeAllViews();
         Button button;
         Button button;
-        ExecuteActionTask executeActionTask = new ExecuteActionTask(holder);
+
 
 
         for (Action action : notification.getActions()) {
         for (Action action : notification.getActions()) {
             button = new Button(notificationsActivity);
             button = new Button(notificationsActivity);
             button.setText(action.label);
             button.setText(action.label);
+
             if (action.primary) {
             if (action.primary) {
                 button.getBackground().setColorFilter(ThemeUtils.primaryColor(notificationsActivity, true),
                 button.getBackground().setColorFilter(ThemeUtils.primaryColor(notificationsActivity, true),
                         PorterDuff.Mode.SRC_ATOP);
                         PorterDuff.Mode.SRC_ATOP);
                 button.setTextColor(ThemeUtils.fontColor(notificationsActivity));
                 button.setTextColor(ThemeUtils.fontColor(notificationsActivity));
             }
             }
 
 
-            button.setOnClickListener(v -> executeActionTask.execute(action));
+            button.setOnClickListener(v -> {
+                setButtonEnabled(holder, false);
+
+                new ExecuteActionTask(holder).execute(action);
+            });
 
 
             holder.buttons.addView(button);
             holder.buttons.addView(button);
         }
         }
@@ -222,7 +227,7 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
                 return false;
                 return false;
             }
             }
 
 
-            return status == HttpStatus.SC_OK;
+            return status == HttpStatus.SC_OK || status == HttpStatus.SC_ACCEPTED;
         }
         }
 
 
         @Override
         @Override
@@ -232,11 +237,18 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
                 notificationsList.remove(position);
                 notificationsList.remove(position);
                 notifyItemRemoved(position);
                 notifyItemRemoved(position);
             } else {
             } else {
+                setButtonEnabled(holder, true);
                 DisplayUtils.showSnackMessage(notificationsActivity, "Failed to execute action!");
                 DisplayUtils.showSnackMessage(notificationsActivity, "Failed to execute action!");
             }
             }
         }
         }
     }
     }
 
 
+    private void setButtonEnabled(NotificationViewHolder holder, boolean enabled) {
+        for (int i = 0; i < holder.buttons.getChildCount(); i++) {
+            holder.buttons.getChildAt(i).setEnabled(enabled);
+        }
+    }
+
     private void downloadIcon(String icon, ImageView itemViewType) {
     private void downloadIcon(String icon, ImageView itemViewType) {
         GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(notificationsActivity)
         GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(notificationsActivity)
                 .using(Glide.buildStreamModelLoader(Uri.class, notificationsActivity), InputStream.class)
                 .using(Glide.buildStreamModelLoader(Uri.class, notificationsActivity), InputStream.class)