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

fix notification task, if it failed first

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 5 жил өмнө
parent
commit
44fefe9064

+ 4 - 2
src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.java

@@ -392,11 +392,13 @@ public class NotificationsActivity extends FileActivity implements Notifications
     }
 
     @Override
-    public void onActionCallback(boolean isSuccess, NotificationListAdapter.NotificationViewHolder holder) {
+    public void onActionCallback(boolean isSuccess,
+                                 Notification notification,
+                                 NotificationListAdapter.NotificationViewHolder holder) {
         if (isSuccess) {
             adapter.removeNotification(holder);
         } else {
-            adapter.setButtonEnabled(holder, true);
+            adapter.setButtons(holder, notification);
             DisplayUtils.showSnackMessage(this, getString(R.string.notification_action_failed));
         }
     }

+ 12 - 5
src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java

@@ -140,14 +140,24 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
             downloadIcon(notification.getIcon(), holder.icon);
         }
 
+        setButtons(holder, notification);
+
+        holder.dismiss.setOnClickListener(v -> new DeleteNotificationTask(client, notification, holder,
+                                                                          notificationsActivity).execute());
+    }
+
+    public void setButtons(NotificationViewHolder holder, Notification notification) {
         // add action buttons
         holder.buttons.removeAllViews();
         MaterialButton button;
 
         Resources resources = notificationsActivity.getResources();
-        NotificationExecuteActionTask task = new NotificationExecuteActionTask(client, holder, notificationsActivity);
+        NotificationExecuteActionTask task = new NotificationExecuteActionTask(client,
+                                                                               holder,
+                                                                               notification,
+                                                                               notificationsActivity);
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
-            ViewGroup.LayoutParams.WRAP_CONTENT);
+                                                                         ViewGroup.LayoutParams.WRAP_CONTENT);
         params.setMargins(20, 0, 20, 0);
 
         for (Action action : notification.getActions()) {
@@ -184,9 +194,6 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
 
             holder.buttons.addView(button);
         }
-
-        holder.dismiss.setOnClickListener(v -> new DeleteNotificationTask(client, notification, holder,
-                                                                          notificationsActivity).execute());
     }
 
     private SpannableStringBuilder makeSpecialPartsBold(Notification notification) {

+ 7 - 2
src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java

@@ -6,6 +6,7 @@ import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.resources.notifications.models.Action;
+import com.owncloud.android.lib.resources.notifications.models.Notification;
 import com.owncloud.android.ui.activity.NotificationsActivity;
 import com.owncloud.android.ui.adapter.NotificationListAdapter;
 
@@ -22,12 +23,16 @@ public class NotificationExecuteActionTask extends AsyncTask<Action, Void, Boole
 
     private NotificationListAdapter.NotificationViewHolder holder;
     private OwnCloudClient client;
+    private Notification notification;
     private NotificationsActivity notificationsActivity;
 
-    public NotificationExecuteActionTask(OwnCloudClient client, NotificationListAdapter.NotificationViewHolder holder,
+    public NotificationExecuteActionTask(OwnCloudClient client,
+                                         NotificationListAdapter.NotificationViewHolder holder,
+                                         Notification notification,
                                          NotificationsActivity notificationsActivity) {
         this.client = client;
         this.holder = holder;
+        this.notification = notification;
         this.notificationsActivity = notificationsActivity;
     }
 
@@ -73,6 +78,6 @@ public class NotificationExecuteActionTask extends AsyncTask<Action, Void, Boole
 
     @Override
     protected void onPostExecute(Boolean isSuccess) {
-        notificationsActivity.onActionCallback(isSuccess, holder);
+        notificationsActivity.onActionCallback(isSuccess, notification, holder);
     }
 }

+ 4 - 1
src/main/java/com/owncloud/android/ui/notifications/NotificationsContract.java

@@ -21,6 +21,7 @@
 
 package com.owncloud.android.ui.notifications;
 
+import com.owncloud.android.lib.resources.notifications.models.Notification;
 import com.owncloud.android.ui.adapter.NotificationListAdapter;
 
 public interface NotificationsContract {
@@ -32,6 +33,8 @@ public interface NotificationsContract {
 
         void onRemovedAllNotifications(boolean isSuccess);
 
-        void onActionCallback(boolean isSuccess, NotificationListAdapter.NotificationViewHolder holder);
+        void onActionCallback(boolean isSuccess,
+                              Notification notification,
+                              NotificationListAdapter.NotificationViewHolder holder);
     }
 }