Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification button handling #3114

Merged
merged 1 commit into from
Oct 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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