Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Karn committed Feb 14, 2021
2 parents 59f4df1 + f7ec69e commit ab8bede
Show file tree
Hide file tree
Showing 27 changed files with 632 additions and 79 deletions.
76 changes: 63 additions & 13 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ Notify
add(Action(
// The icon corresponding to the action.
R.drawable.ic_app_icon,
// The text corresponding to the action -- this is what shows .
// The text corresponding to the action -- this is what shows below the
// notification.
"Clear",
// Swap this PendingIntent for whatever Intent is to be processed when the action is clicked.
// Swap this PendingIntent for whatever Intent is to be processed when the action
// is clicked.
PendingIntent.getService(context,
0,
Intent(context, MyNotificationService::class.java)
Expand All @@ -84,21 +86,69 @@ Notify
title = "New dessert menu"
text = "The Cheesecake Factory has a new dessert for you to try!"
}
// Define the notification as being stackable. This block should be the same for all notifications which
// are to be grouped together.
// Define the notification as being stackable. This block should be the same for all
// notifications which are to be grouped together.
.stackable { // this: Payload.Stackable
// In particular, this key should be the same. The properties of this stackable notification as
// taken from the latest stackable notification's stackable block.
// In particular, this key should be the same. The properties of this stackable
// notification as taken from the latest stackable notification's stackable block.
key = "test_key"
// This is the summary of this notification as it appears when it is as part of a stacked notification. This
// String value is what is shown as a single line in the stacked notification.
// This is the summary of this notification as it appears when it is as part of a
// stacked notification. This String value is what is shown as a single line in the
// stacked notification.
summaryContent = "test summary content"
// The number of notifications with the same key is passed as the 'count' argument. We happen not to
// use it, but it is there if needed.
// The number of notifications with the same key is passed as the 'count' argument. We
// happen not to use it, but it is there if needed.
summaryTitle = { count -> "Summary title" }
// ... here as well, but we instead choose to use to to update the summary for when the notification
// is collapsed.
// ... here as well, but we instead choose to use to to update the summary for when the
// notification is collapsed.
summaryDescription = { count -> count.toString() + " new notifications." }
}
.show()
```
```


#### BUBBLE NOTIFICATIONS

With the release of Android 10, Notify now also supports [Notification Bubbles](https://developer.android.com/guide/topics/ui/bubbles) on devices with the `Notification Bubbles` enabled through the Developer Settings. This new form of notification allows an application to display rich content from an activity at a glance to a user.

Begin by first creating an activity and adding the following permissions to that activity within your `AndroidManifest.xml`:

```xml
<application
...>

<!-- Find the Activity being used for the Bubble Notification -->
<activity
...
<!-- Add the three lines below to the activity being used -->
android:allowEmbedded="true"
android:documentLaunchMode="always"
android:resizeableActivity="true" />
</application>
```

Then you can target that activity from the notification.

```kotlin
Notify.with(context)
.content { // this: Payload.Content.Default
title = "New dessert menu"
text = "The Cheesecake Factory has a new dessert for you to try!"
}
// Define the Notification as supporting a Bubble format. This style can be applied to any
// notification.
.bubblize { // this: Payload.Bubble
// Configure the target Intent for the Notification to launch when it is expanded.
val target = Intent(context, BubbleActivity::class.java)
// Provide a PendingIntent to launch the above target once the Bubble is expanded.
val bubbleIntent = PendingIntent.getActivity(context, 0, target, 0)

// Set the image for the Bubble, this uses the IconCompat class to build the icon being
// shown within the bubble.
bubbleIcon = IconCompat.createWithResource(context, R.drawable.ic_app_icon)
// Set the activity that is being shown when the Bubble is expanded to the PendingIntent
// created above.
targetActivity = bubbleIntent
}
.show()
```
Binary file added docs/assets/types/progress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 25 additions & 1 deletion docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,28 @@ Notify
)
}
.show()
```
```

#### PROGRESS NOTIFICATION

![Progress notification](./assets/types/progress.png)

Progress notification is useful when you need to display information about the detail of a process such as uploading a file to a server, or some calculation that takes time and you want to keep the user informed. You can ser `showProgress` true to display it, and if you need determinate progress you can set `enablePercentage` true and specify `progressPercent` to your current value

```Kotlin
Notify
.with(context)
.asBigText {
title = "Uploading files"
expandedText = "The files are being uploaded!"
bigText = "Daft Punk - Get Lucky.flac is uploading to server /music/favorites"
}
.progress {
showProgress = true

//For determinate progress
//enablePercentage = true
//progressPercent = 27
}
.show()
```
14 changes: 7 additions & 7 deletions gradle/configuration.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@


def versions = [
libCode: 12,
libName: '1.3.0',
libCode: 13,
libName: '1.4.0',

kotlin: '1.3.11',
core: '1.0.1',
core: '1.2.0-alpha04',
appcompat: '1.0.2',

jacoco: '0.8.2',
dokka: '0.9.17'
]

def build = [
compileSdk: 28,
targetSdk: 28,
compileSdk: 29,
targetSdk: 29,
minSdk: 19,

jacocoAgentVersion: versions.jacoco,
Expand All @@ -40,15 +40,15 @@ def dependencies = [
reflect: "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
],
androidx: [
core: "androidx.core:core:${versions.core}",
core: "androidx.core:core-ktx:${versions.core}",
appcompat: "androidx.appcompat:appcompat:${versions.appcompat}"
]
]

def testDependencies = [
instrumentationRunner: 'androidx.test.runner.AndroidJUnitRunner',
junit: 'junit:junit:4.12',
robolectric: 'org.robolectric:robolectric:4.0'
robolectric: 'org.robolectric:robolectric:4.3'
]

ext.config = [
Expand Down
5 changes: 5 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// For Kotlin projects
kotlinOptions {
freeCompilerArgs += ['-module-name', "io.karn.notify"]
jvmTarget = "1.8"
}

lintOptions.abortOnError false

Expand Down
18 changes: 16 additions & 2 deletions library/src/main/java/io/karn/notify/Notify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,22 @@ class Notify internal constructor(internal var context: Context) {
/**
* Cancel an existing notification with a particular id.
*/
@Deprecated(message = "NotificationManager might not have been initialized and can throw a NullPointerException -- provide a context.",
replaceWith = ReplaceWith("Notify.cancelNotification(context, id)"))
@Throws(NullPointerException::class)
fun cancelNotification(id: Int) {
return NotificationInterop.cancelNotification(Notify.defaultConfig.notificationManager!!, id)
return NotificationInterop.cancelNotification(defaultConfig.notificationManager!!, id)
}

/**
* Cancel an existing notification with a particular id.
*/
fun cancelNotification(context: Context, id: Int) {
if (defaultConfig.notificationManager == null) {
defaultConfig.notificationManager = context.applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
}

return NotificationInterop.cancelNotification(defaultConfig.notificationManager!!, id)
}
}

Expand Down Expand Up @@ -145,6 +159,6 @@ class Notify internal constructor(internal var context: Context) {
* this returned integer to make updates or to cancel the notification.
*/
internal fun show(id: Int?, builder: NotificationCompat.Builder): Int {
return NotificationInterop.showNotification(Notify.defaultConfig.notificationManager!!, id, builder)
return NotificationInterop.showNotification(defaultConfig.notificationManager!!, id, builder)
}
}
Loading

0 comments on commit ab8bede

Please sign in to comment.