mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 05:35:39 +03:00
Merge pull request #4730 from nextcloud/taskTwice
fix notification task, if it failed first
This commit is contained in:
commit
4f8fc49d15
4 changed files with 27 additions and 10 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue