mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 14:45:47 +03:00
Notification buttons enhancement (#8932)
* Show buttons: two or primary and more option menu Signed-off-by: tobiasKaminsky <tobias@kaminsky.me> * NotificationsActivityIT: fix linting issues Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com> * Fix kotlin syntax Signed-off-by: tobiasKaminsky <tobias@kaminsky.me> Co-authored-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
fa30776100
commit
f6fbfbd4c5
4 changed files with 141 additions and 23 deletions
Binary file not shown.
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 43 KiB |
|
@ -87,9 +87,10 @@ class NotificationsActivityIT : AbstractIT() {
|
|||
)
|
||||
)
|
||||
|
||||
val actions = ArrayList<Action>()
|
||||
actions.add(Action("Send usage", "link", "url", true))
|
||||
actions.add(Action("Not now", "link", "url", false))
|
||||
val actions = ArrayList<Action>().apply {
|
||||
add(Action("Send usage", "link", "url", true))
|
||||
add(Action("Not now", "link", "url", false))
|
||||
}
|
||||
|
||||
notifications.add(
|
||||
Notification(
|
||||
|
@ -112,6 +113,34 @@ class NotificationsActivityIT : AbstractIT() {
|
|||
)
|
||||
)
|
||||
|
||||
val moreAction = ArrayList<Action>().apply {
|
||||
add(Action("Send usage", "link", "url", true))
|
||||
add(Action("Not now", "link", "url", false))
|
||||
add(Action("third action", "link", "url", false))
|
||||
add(Action("Delay", "link", "url", false))
|
||||
}
|
||||
|
||||
notifications.add(
|
||||
Notification(
|
||||
2,
|
||||
"files",
|
||||
"user",
|
||||
date.time,
|
||||
"objectType",
|
||||
"objectId",
|
||||
"Help improve Nextcloud",
|
||||
"SubjectRich",
|
||||
HashMap<String, RichObject>(),
|
||||
"Do you want to help us to improve Nextcloud by providing some anonymize data about your setup and " +
|
||||
"usage?",
|
||||
"MessageRich",
|
||||
HashMap<String, RichObject>(),
|
||||
"link",
|
||||
"icon",
|
||||
moreAction
|
||||
)
|
||||
)
|
||||
|
||||
sut.runOnUiThread { sut.populateList(notifications) }
|
||||
|
||||
shortSleep()
|
||||
|
|
|
@ -67,6 +67,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
|
@ -174,11 +175,92 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
0
|
||||
);
|
||||
|
||||
int primaryColor = ThemeColorUtils.primaryColor(notificationsActivity);
|
||||
|
||||
List<Action> overflowActions = new ArrayList<>();
|
||||
|
||||
if (notification.getActions().size() > 2) {
|
||||
for (Action action: notification.getActions()) {
|
||||
if (action.primary) {
|
||||
button = new MaterialButton(notificationsActivity);
|
||||
button.setAllCaps(false);
|
||||
|
||||
button.setText(action.label);
|
||||
button.setCornerRadiusResource(R.dimen.button_corner_radius);
|
||||
|
||||
button.setLayoutParams(params);
|
||||
button.setGravity(Gravity.CENTER);
|
||||
|
||||
button.setOnClickListener(v -> {
|
||||
setButtonEnabled(holder, false);
|
||||
|
||||
if (ACTION_TYPE_WEB.equals(action.type)) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(action.link));
|
||||
|
||||
notificationsActivity.startActivity(intent);
|
||||
} else {
|
||||
new NotificationExecuteActionTask(client,
|
||||
holder,
|
||||
notification,
|
||||
notificationsActivity)
|
||||
.execute(action);
|
||||
}
|
||||
});
|
||||
|
||||
ThemeButtonUtils.colorPrimaryButton(button, notificationsActivity);
|
||||
holder.binding.buttons.addView(button);
|
||||
} else {
|
||||
overflowActions.add(action);
|
||||
}
|
||||
}
|
||||
|
||||
// further actions
|
||||
button = new MaterialButton(notificationsActivity);
|
||||
button.setBackgroundColor(resources.getColor(R.color.grey_200));
|
||||
button.setTextColor(primaryColor);
|
||||
|
||||
button.setAllCaps(false);
|
||||
|
||||
button.setText(R.string.more);
|
||||
button.setCornerRadiusResource(R.dimen.button_corner_radius);
|
||||
|
||||
button.setLayoutParams(params);
|
||||
button.setGravity(Gravity.CENTER);
|
||||
|
||||
MaterialButton finalButton = button;
|
||||
button.setOnClickListener(v -> {
|
||||
PopupMenu popup = new PopupMenu(notificationsActivity, finalButton);
|
||||
|
||||
for (Action action : overflowActions) {
|
||||
popup.getMenu().add(action.label).setOnMenuItemClickListener(item -> {
|
||||
setButtonEnabled(holder, false);
|
||||
|
||||
if (ACTION_TYPE_WEB.equals(action.type)) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(action.link));
|
||||
|
||||
notificationsActivity.startActivity(intent);
|
||||
} else {
|
||||
new NotificationExecuteActionTask(client,
|
||||
holder,
|
||||
notification,
|
||||
notificationsActivity)
|
||||
.execute(action);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
popup.show();
|
||||
});
|
||||
|
||||
holder.binding.buttons.addView(button);
|
||||
} else {
|
||||
for (Action action : notification.getActions()) {
|
||||
button = new MaterialButton(notificationsActivity);
|
||||
|
||||
int primaryColor = ThemeColorUtils.primaryColor(notificationsActivity);
|
||||
|
||||
if (action.primary) {
|
||||
ThemeButtonUtils.colorPrimaryButton(button, notificationsActivity);
|
||||
} else {
|
||||
|
@ -214,6 +296,12 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
holder.binding.buttons.addView(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleItemClick() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private SpannableStringBuilder makeSpecialPartsBold(Notification notification) {
|
||||
String text = notification.getSubjectRich();
|
||||
|
|
|
@ -963,4 +963,5 @@
|
|||
<string name="choose_template_helper_text">Please choose a template and enter a file name.</string>
|
||||
<string name="strict_mode">Strict mode: no HTTP connection allowed!</string>
|
||||
<string name="fullscreen">Fullscreen</string>
|
||||
<string name="more">more</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue