@@ -18,68 +18,70 @@ class Actions @PublishedApi internal constructor(private val builder: Notificati
1818 /* *
1919 * Add an action to this notification. Actions are typically displayed by
2020 * the system as a button adjacent to the notification content.
21+ *
22+ * On pre-Lollpop devices invisible actions will be ignored
2123 */
2224 fun action (
2325 title : CharSequence? ,
2426 intent : PendingIntent ? ,
2527 icon : IconCompat ? = null,
26- visible : Boolean = false
28+ visible : Boolean = true
2729 ) {
28- if (visible || isInvisibleActionsSupported()) {
29- val action = NotificationCompat .Action .Builder (icon, title, intent).build()
30- addAction(action, visible)
30+ addAction(visible) {
31+ NotificationCompat .Action .Builder (icon, title, intent)
3132 }
3233 }
3334
3435 /* *
3536 * Add an action to this notification. Actions are typically displayed by
3637 * the system as a button adjacent to the notification content.
38+ *
39+ * On pre-Lollpop devices invisible actions will be ignored
3740 */
3841 fun action (
3942 title : CharSequence? ,
4043 intent : PendingIntent ? ,
4144 @DrawableRes icon : Int ,
42- visible : Boolean = false
45+ visible : Boolean = true
4346 ) {
44- if (visible || isInvisibleActionsSupported()) {
45- val action = NotificationCompat .Action .Builder (icon, title, intent).build()
46- addAction(action, visible)
47+ addAction(visible) {
48+ NotificationCompat .Action .Builder (icon, title, intent)
4749 }
4850 }
4951
5052 /* *
5153 * Add an action to this notification. Actions are typically displayed by
5254 * the system as a button adjacent to the notification content.
55+ *
56+ * On pre-Lollpop devices invisible actions will be ignored
5357 */
5458 inline fun action (
5559 title : CharSequence? ,
5660 intent : PendingIntent ? ,
5761 icon : IconCompat ? = null,
58- visible : Boolean = false ,
59- body : @NotificationActionsMarker Action .() -> Unit
62+ visible : Boolean = true ,
63+ crossinline body : @NotificationActionsMarker Action .() -> Unit
6064 ) {
61- if (visible || isInvisibleActionsSupported()) {
62- val actionBuilder = NotificationCompat .Action .Builder (icon, title, intent)
63- Action (actionBuilder).body()
64- addAction(actionBuilder.build(), visible)
65+ addAction(visible) {
66+ NotificationCompat .Action .Builder (icon, title, intent).apply { Action (this ).body() }
6567 }
6668 }
6769
6870 /* *
6971 * Add an action to this notification. Actions are typically displayed by
7072 * the system as a button adjacent to the notification content.
73+ *
74+ * On pre-Lollpop devices invisible actions will be ignored
7175 */
7276 inline fun action (
7377 title : CharSequence? ,
7478 intent : PendingIntent ? ,
7579 @DrawableRes icon : Int ,
76- visible : Boolean = false ,
77- body : @NotificationActionsMarker Action .() -> Unit
80+ visible : Boolean = true ,
81+ crossinline body : @NotificationActionsMarker Action .() -> Unit
7882 ) {
79- if (visible || isInvisibleActionsSupported()) {
80- val actionBuilder = NotificationCompat .Action .Builder (icon, title, intent)
81- Action (actionBuilder).body()
82- addAction(actionBuilder.build(), visible)
83+ addAction(visible) {
84+ NotificationCompat .Action .Builder (icon, title, intent).apply { Action (this ).body() }
8385 }
8486 }
8587
@@ -89,14 +91,23 @@ class Actions @PublishedApi internal constructor(private val builder: Notificati
8991 *
9092 * On pre-Lollpop devices invisible actions will be ignored
9193 *
92- * @param visible is actions are never displayed by the system,
93- * but can be retrieved and used by other application listening to system notifications
94+ * @param visible is actions are never displayed by the system, but can be retrieved
95+ * and used by other application listening to system notifications
9496 */
95- fun addAction (action : NotificationCompat .Action , visible : Boolean = false ) {
97+ fun addAction (action : NotificationCompat .Action , visible : Boolean = true ) {
9698 if (visible) {
9799 builder.addAction(action)
98100 } else if (isInvisibleActionsSupported()) {
99101 builder.addInvisibleAction(action)
100102 }
101103 }
104+
105+ @PublishedApi
106+ internal fun addAction (visible : Boolean = true, action : () -> NotificationCompat .Action .Builder ) {
107+ if (visible) {
108+ builder.addAction(action().build())
109+ } else if (isInvisibleActionsSupported()) {
110+ builder.addInvisibleAction(action().build())
111+ }
112+ }
102113}
0 commit comments