Skip to content

Commit

Permalink
README updates, breaking changes.
Browse files Browse the repository at this point in the history
The README has been updated with a new anatomy.svg asset which explicitly relies on outlines as opposed to fonts. Additionally, there are two breaking changes.
- `Creator#getBuilder()` is now `Creator#asBuilder()` which is inline with the function of the same name in `Notify`.
- `Creator#send()` and `Notify#send()` are now `Creator#show()` and `Notify#show()` respectively.
  • Loading branch information
Karn committed Apr 30, 2018
1 parent e9b7689 commit 421a2f8
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 126 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Notify

![Basic usecase](./docs/assets/default.svg)

If you run into a case in which the library does not provide the requisite builder functions you can get the `NotificationCompat.Builder` object and continue to use it as you would normally by calling `Creator#asBuilder()`.

###### NOTIFICATION ANATOMY

Expand All @@ -56,7 +57,7 @@ Notify
| ID | Name | Description |
| ---- | ------------ | ------------------------------------------------------------------------------------------------------- |
| 1 | Icon | Set using the `Header#icon` field. |
| 2 | App Name | Application Icon, immutable. |
| 2 | App Name | Application name, immutable. |
| 3 | Header Text | Optional description text. Set using the `Header#headerText` field. |
| 4 | Timestamp | Timestamp of the notification. |
| 5 | Expand Icon | Indicates that the notification is expandable. |
Expand Down
194 changes: 107 additions & 87 deletions docs/assets/anatomy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 21 additions & 21 deletions library/src/main/java/io/karn/notify/Creator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Creator internal constructor(private val notify: Notify, config: NotifyCon
* Scoped function for modifying the Metadata of a notification, such as click intents,
* notification category, and priority among other options.
*/
fun meta(meta: Payload.Meta.() -> Unit): Creator {
meta(this.meta)
fun meta(init: Payload.Meta.() -> Unit): Creator {
this.meta.init()

return this
}
Expand All @@ -32,82 +32,82 @@ class Creator internal constructor(private val notify: Notify, config: NotifyCon
* modification of the notificationIcon, color, the headerText (optional text next to the
* appName), and finally the channel of the notification if targeting Android O.
*/
fun header(header: Payload.Header.() -> Unit): Creator {
header(this.header)
fun header(init: Payload.Header.() -> Unit): Creator {
this.header.init()

return this
}

/**
* Scoped function for modifying the content of a 'Default' notification.
*/
fun content(block: Payload.Content.Default.() -> Unit): Creator {
fun content(init: Payload.Content.Default.() -> Unit): Creator {
this.content = Payload.Content.Default()
block(this.content as Payload.Content.Default)
(this.content as Payload.Content.Default).init()
return this
}

/**
* Scoped function for modifying the content of a 'TextList' notification.
*/
fun asTextList(block: Payload.Content.TextList.() -> Unit): Creator {
fun asTextList(init: Payload.Content.TextList.() -> Unit): Creator {
this.content = Payload.Content.TextList()
block(this.content as Payload.Content.TextList)
(this.content as Payload.Content.TextList).init()
return this
}

/**
* Scoped function for modifying the content of a 'BigText' notification.
*/
fun asBigText(block: Payload.Content.BigText.() -> Unit): Creator {
fun asBigText(init: Payload.Content.BigText.() -> Unit): Creator {
this.content = Payload.Content.BigText()
block(this.content as Payload.Content.BigText)
(this.content as Payload.Content.BigText).init()
return this
}

/**
* Scoped function for modifying the content of a 'BigPicture' notification.
*/
fun asBigPicture(block: Payload.Content.BigPicture.() -> Unit): Creator {
fun asBigPicture(init: Payload.Content.BigPicture.() -> Unit): Creator {
this.content = Payload.Content.BigPicture()
block(this.content as Payload.Content.BigPicture)
(this.content as Payload.Content.BigPicture).init()
return this
}

/**
* Scoped function for modifying the content of a 'Message' notification.
*/
fun asMessage(block: Payload.Content.Message.() -> Unit): Creator {
fun asMessage(init: Payload.Content.Message.() -> Unit): Creator {
this.content = Payload.Content.Message()
block(this.content as Payload.Content.Message)
(this.content as Payload.Content.Message).init()
return this
}

/**
* Scoped function for modifying the 'Actions' of a notification. The transformation
* relies on adding standard notification Action objects.
*/
fun actions(block: ArrayList<Action>.() -> Unit): Creator {
fun actions(init: ArrayList<Action>.() -> Unit): Creator {
this.actions = ArrayList()
block(this.actions as ArrayList<Action>)
(this.actions as ArrayList<Action>).init()
return this
}

/**
* Scoped function for modifying the behaviour of 'Stacked' notifications. The transformation
* relies on the 'summaryText' of a stackable notification.
*/
fun stackable(block: Payload.Stackable.() -> Unit): Creator {
fun stackable(init: Payload.Stackable.() -> Unit): Creator {
this.stackable = Payload.Stackable()
block(this.stackable as Payload.Stackable)
(this.stackable as Payload.Stackable).init()
return this
}

/**
* Return the standard {@see NotificationCompat.Builder} after applying fluent API
* transformations (if any) from the {@see Creator} builder object.
*/
fun getBuilder(): NotificationCompat.Builder {
fun asBuilder(): NotificationCompat.Builder {
return notify.asBuilder(RawNotification(meta, header, content, stackable, actions))
}

Expand All @@ -120,7 +120,7 @@ class Creator internal constructor(private val notify: Notify, config: NotifyCon
* @return An integer corresponding to the ID of the system notification. Any updates should use
* this returned integer to make updates or to cancel the notification.
*/
fun send(): Int {
return notify.send(getBuilder())
fun show(): Int {
return notify.show(asBuilder())
}
}
5 changes: 2 additions & 3 deletions library/src/main/java/io/karn/notify/Notify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class Notify internal constructor(internal var context: Context) {
/**
* Modify the default configuration.
*
* Takes a function that receives a lambda with the NotifyConfig immutable object which has
* mutable fields.
* Takes a receiver with the NotifyConfig immutable object which has mutable fields.
*/
fun defaultConfig(block: (NotifyConfig) -> Unit) {
block(defaultConfig)
Expand Down Expand Up @@ -78,7 +77,7 @@ class Notify internal constructor(internal var context: Context) {
* @return An integer corresponding to the ID of the system notification. Any updates should use
* this returned integer to make updates or to cancel the notification.
*/
internal fun send(builder: NotificationCompat.Builder): Int {
internal fun show(builder: NotificationCompat.Builder): Int {
return NotificationInterop.showNotification(context, builder)
}
}
4 changes: 2 additions & 2 deletions library/src/test/java/io/karn/notify/NotifyActionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NotifyActionsTest {
title = "New dessert menu"
text = "The Cheesecake Factory has a new dessert for you to try!"
}
.getBuilder()
.asBuilder()
.build()

Assert.assertNull(notification.actions)
Expand All @@ -39,7 +39,7 @@ class NotifyActionsTest {
null
))
}
.getBuilder()
.asBuilder()
.build()

Assert.assertNotNull(notification.actions)
Expand Down
10 changes: 5 additions & 5 deletions library/src/test/java/io/karn/notify/NotifyContentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NotifyContentTest {
title = testTitle
text = testText
}
.getBuilder()
.asBuilder()
.build()

Assert.assertNull(notification.extras.getCharSequence(NotificationCompat.EXTRA_TEMPLATE))
Expand All @@ -95,7 +95,7 @@ class NotifyContentTest {
title = testTitle
text = testText
}
.getBuilder()
.asBuilder()
.build()

Assert.assertEquals("android.app.Notification\$InboxStyle", notification.extras.getCharSequence(NotificationCompat.EXTRA_TEMPLATE).toString())
Expand All @@ -121,7 +121,7 @@ class NotifyContentTest {
collapsedText = testExpandedText
bigText = testBigText
}
.getBuilder()
.asBuilder()
.build()

Assert.assertEquals("android.app.Notification\$BigTextStyle", notification.extras.getCharSequence(NotificationCompat.EXTRA_TEMPLATE).toString())
Expand All @@ -144,7 +144,7 @@ class NotifyContentTest {
text = testText
image = testImage
}
.getBuilder()
.asBuilder()
.build()

Assert.assertEquals("android.app.Notification\$BigPictureStyle", notification.extras.getCharSequence(NotificationCompat.EXTRA_TEMPLATE).toString())
Expand Down Expand Up @@ -183,7 +183,7 @@ class NotifyContentTest {
conversationTitle = testConversationTitle
messages = testMessages
}
.getBuilder()
.asBuilder()
.build()

Assert.assertEquals("android.app.Notification\$MessagingStyle", notification.extras.getCharSequence(NotificationCompat.EXTRA_TEMPLATE).toString())
Expand Down
4 changes: 2 additions & 2 deletions library/src/test/java/io/karn/notify/NotifyHeaderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NotifyHeaderTest {
title = "New dessert menu"
text = "The Cheesecake Factory has a new dessert for you to try!"
}
.getBuilder()
.asBuilder()
.build()

Assert.assertEquals(Icon.createWithResource(this.context, R.drawable.ic_app_icon).describeContents(), notification.smallIcon.describeContents())
Expand All @@ -48,7 +48,7 @@ class NotifyHeaderTest {
title = "New dessert menu"
text = "The Cheesecake Factory has a new dessert for you to try!"
}
.getBuilder()
.asBuilder()
.build()

Assert.assertEquals(Icon.createWithResource(this.context, testIcon).describeContents(), notification.smallIcon.describeContents())
Expand Down
10 changes: 5 additions & 5 deletions sample/src/main/java/presentation/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MainActivity : AppCompatActivity() {
null
))
}
.send()
.show()
}

fun notifyTextList(view: View) {
Expand All @@ -54,7 +54,7 @@ class MainActivity : AppCompatActivity() {
title = "New menu items!"
text = lines.size.toString() + " new dessert menu items found."
}
.send()
.show()

}

Expand All @@ -69,7 +69,7 @@ class MainActivity : AppCompatActivity() {
"\n" +
"Come try this delicious new dessert and get two for the price of one!"
}
.send()
.show()
}

fun notifyBigPicture(view: View) {
Expand All @@ -80,7 +80,7 @@ class MainActivity : AppCompatActivity() {
text = "Get a look at this amazing dessert!"
image = BitmapFactory.decodeResource(this@MainActivity.resources, R.drawable.chocolate_brownie_sundae)
}
.send()
.show()
}

fun notifyMessage(view: View) {
Expand All @@ -101,6 +101,6 @@ class MainActivity : AppCompatActivity() {
"Moez")
)
}
.send()
.show()
}
}

0 comments on commit 421a2f8

Please sign in to comment.