diff --git a/screenshots/gplay/debug/com.owncloud.android.ui.activity.NotificationsActivityIT_showNotifications.png b/screenshots/gplay/debug/com.owncloud.android.ui.activity.NotificationsActivityIT_showNotifications.png index 6c4ccf0382..1c37094312 100644 Binary files a/screenshots/gplay/debug/com.owncloud.android.ui.activity.NotificationsActivityIT_showNotifications.png and b/screenshots/gplay/debug/com.owncloud.android.ui.activity.NotificationsActivityIT_showNotifications.png differ diff --git a/src/androidTest/java/com/owncloud/android/ui/activity/NotificationsActivityIT.kt b/src/androidTest/java/com/owncloud/android/ui/activity/NotificationsActivityIT.kt index a2b3c122fb..da2fda485d 100644 --- a/src/androidTest/java/com/owncloud/android/ui/activity/NotificationsActivityIT.kt +++ b/src/androidTest/java/com/owncloud/android/ui/activity/NotificationsActivityIT.kt @@ -87,9 +87,10 @@ class NotificationsActivityIT : AbstractIT() { ) ) - val actions = ArrayList() - actions.add(Action("Send usage", "link", "url", true)) - actions.add(Action("Not now", "link", "url", false)) + val actions = ArrayList().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().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(), + "Do you want to help us to improve Nextcloud by providing some anonymize data about your setup and " + + "usage?", + "MessageRich", + HashMap(), + "link", + "icon", + moreAction + ) + ) + sut.runOnUiThread { sut.populateList(notifications) } shortSleep() diff --git a/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java index 0f28ab6d0f..ddffe51e1e 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java @@ -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,46 +175,133 @@ public class NotificationListAdapter extends RecyclerView.Adapter overflowActions = new ArrayList<>(); + + if (notification.getActions().size() > 2) { + for (Action action: notification.getActions()) { + if (action.primary) { + button = new MaterialButton(notificationsActivity); + button.setAllCaps(false); - int primaryColor = ThemeColorUtils.primaryColor(notificationsActivity); + button.setText(action.label); + button.setCornerRadiusResource(R.dimen.button_corner_radius); - if (action.primary) { - ThemeButtonUtils.colorPrimaryButton(button, notificationsActivity); - } else { - button.setBackgroundColor(resources.getColor(R.color.grey_200)); - button.setTextColor(primaryColor); + 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(action.label); + 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 -> { - setButtonEnabled(holder, false); + PopupMenu popup = new PopupMenu(notificationsActivity, finalButton); - if (ACTION_TYPE_WEB.equals(action.type)) { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(action.link)); + for (Action action : overflowActions) { + popup.getMenu().add(action.label).setOnMenuItemClickListener(item -> { + setButtonEnabled(holder, false); - notificationsActivity.startActivity(intent); - } else { - new NotificationExecuteActionTask(client, - holder, - notification, - notificationsActivity) - .execute(action); + 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); + + if (action.primary) { + ThemeButtonUtils.colorPrimaryButton(button, notificationsActivity); + } else { + button.setBackgroundColor(resources.getColor(R.color.grey_200)); + button.setTextColor(primaryColor); + } + + 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); + } + }); + + holder.binding.buttons.addView(button); + } } } + + private void handleItemClick() { + + } + private SpannableStringBuilder makeSpecialPartsBold(Notification notification) { String text = notification.getSubjectRich(); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 81a63fb17b..dac528e99f 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -963,4 +963,5 @@ Please choose a template and enter a file name. Strict mode: no HTTP connection allowed! Fullscreen + more