Skip to content

Commit

Permalink
Merge pull request #3172 from nextcloud/backport-3114
Browse files Browse the repository at this point in the history
Backport #3114: create a task for each button
  • Loading branch information
AndyScherzinger authored Oct 24, 2018
2 parents bd5942a + 8b172b8 commit c7e072c
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,23 @@ public void onBindViewHolder(@NonNull NotificationViewHolder holder, int positio
// add action buttons
holder.buttons.removeAllViews();
Button button;
ExecuteActionTask executeActionTask = new ExecuteActionTask(holder);


for (Action action : notification.getActions()) {
button = new Button(notificationsActivity);
button.setText(action.label);

if (action.primary) {
button.getBackground().setColorFilter(ThemeUtils.primaryColor(notificationsActivity, true),
PorterDuff.Mode.SRC_ATOP);
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);
}
Expand Down Expand Up @@ -222,7 +227,7 @@ protected Boolean doInBackground(Action... actions) {
return false;
}

return status == HttpStatus.SC_OK;
return status == HttpStatus.SC_OK || status == HttpStatus.SC_ACCEPTED;
}

@Override
Expand All @@ -232,11 +237,18 @@ protected void onPostExecute(Boolean success) {
notificationsList.remove(position);
notifyItemRemoved(position);
} else {
setButtonEnabled(holder, true);
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) {
GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(notificationsActivity)
.using(Glide.buildStreamModelLoader(Uri.class, notificationsActivity), InputStream.class)
Expand Down

0 comments on commit c7e072c

Please sign in to comment.