Skip to content

Commit

Permalink
Merge pull request #35 from Karn/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Karn authored Apr 2, 2019
2 parents 861cb36 + 4383b88 commit da48adf
Show file tree
Hide file tree
Showing 42 changed files with 960 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Simplified notification construction for Android.
[![Codecov](https://img.shields.io/codecov/c/github/karn/notify.svg?style=flat-square)](https://codecov.io/gh/Karn/notify)
[![GitHub (pre-)release](https://img.shields.io/github/release/karn/notify/all.svg?style=flat-square)
](./../../releases)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FKarn%2Fnotify.svg?type=small)](https://app.fossa.io/projects/git%2Bgithub.com%2FKarn%2Fnotify?ref=badge_small)

Notify is a Fluent API for Android notifications which lets you build notifications without worrying how they'll look across devices or API versions. You can bring deterministic notifications to your Android projects with clarity & ease so you can finally stop fighting Developer documentation and get back to dev work that really matters.

Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
group = 'io.karn'
version = '1.2.0'

subprojects {
apply from: rootProject.file('gradle/configuration.gradle')
Expand Down
14 changes: 7 additions & 7 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Notify
.with(context)
.meta { // this: Payload.Meta
// Launch the MainActivity once the notification is clicked.
clickIntent = PendingIntent.getActivity(this@MainActivity,
clickIntent = PendingIntent.getActivity(context,
0,
Intent(this@MainActivity, MainActivity::class.java),
Intent(context, MainActivity::class.java),
0)
// Start a service which clears the badge count once the notification is dismissed.
clearIntent = PendingIntent.getService(this@MainActivity,
clearIntent = PendingIntent.getService(context,
0,
Intent(this@MainActivity, MyNotificationService::class.java)
Intent(context, MyNotificationService::class.java)
.putExtra("action", "clear_badges"),
0)
}
Expand Down Expand Up @@ -61,9 +61,9 @@ Notify
// The text corresponding to the action -- this is what shows .
"Clear",
// Swap this PendingIntent for whatever Intent is to be processed when the action is clicked.
PendingIntent.getService(this@MainActivity,
PendingIntent.getService(context,
0,
Intent(this@MainActivity, MyNotificationService::class.java)
Intent(context, MyNotificationService::class.java)
.putExtra("action", "clear_badges"),
0)
))
Expand All @@ -79,7 +79,7 @@ This is a particularly effective method of reducing the clutter of the notificat

```Kotlin
Notify
.with(this)
.with(context)
.content { // this: Payload.Content.Default
title = "New dessert menu"
text = "The Cheesecake Factory has a new dessert for you to try!"
Expand Down
4 changes: 4 additions & 0 deletions gradle/configuration.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@


def versions = [
libCode: 11,
libName: '1.2.1',

kotlin: '1.3.11',
core: '1.0.1',
appcompat: '1.0.2',
Expand Down Expand Up @@ -49,6 +52,7 @@ def testDependencies = [
]

ext.config = [
"versions": versions,
"deps" : dependencies,
"testDeps": testDependencies,
"build" : build
Expand Down
28 changes: 26 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2018 Karn Saheb
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
Expand All @@ -13,8 +37,8 @@ android {
targetSdkVersion config.build.targetSdk
minSdkVersion config.build.minSdk

versionCode 10
versionName "1.2.0"
versionCode config.versions.libCode
versionName config.versions.libName

testInstrumentationRunner config.testDeps.instrumentationRunner
}
Expand Down
24 changes: 24 additions & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ MIT License
~
~ Copyright (c) 2018 Karn Saheb
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->

<manifest package="io.karn.notify">

<application />
Expand Down
26 changes: 25 additions & 1 deletion library/src/main/java/io/karn/notify/Notify.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2018 Karn Saheb
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.karn.notify

import android.app.NotificationManager
Expand Down Expand Up @@ -76,7 +100,7 @@ class Notify internal constructor(internal var context: Context) {
* {@see Notify#defaultConfig((NotifyConfig) -> Unit)}.
*/
fun with(context: Context): NotifyCreator {
return NotifyCreator(Notify(context), defaultConfig)
return NotifyCreator(Notify(context))
}

/**
Expand Down
31 changes: 27 additions & 4 deletions library/src/main/java/io/karn/notify/NotifyCreator.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2018 Karn Saheb
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.karn.notify

import androidx.core.app.NotificationCompat
import io.karn.notify.entities.NotifyConfig
import io.karn.notify.entities.Payload
import io.karn.notify.internal.RawNotification
import io.karn.notify.internal.utils.Action
Expand All @@ -12,11 +35,11 @@ import io.karn.notify.internal.utils.NotifyScopeMarker
* Fluent API for creating a Notification object.
*/
@NotifyScopeMarker
class NotifyCreator internal constructor(private val notify: Notify, config: NotifyConfig = NotifyConfig()) {
class NotifyCreator internal constructor(private val notify: Notify) {

private var meta = Payload.Meta()
private var alerts = config.defaultAlerting
private var header = config.defaultHeader.copy()
private var alerts = Notify.defaultConfig.defaultAlerting
private var header = Notify.defaultConfig.defaultHeader.copy()
private var content: Payload.Content = Payload.Content.Default()
private var actions: ArrayList<Action>? = null
private var stackable: Payload.Stackable? = null
Expand Down
24 changes: 24 additions & 0 deletions library/src/main/java/io/karn/notify/entities/NotifyConfig.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2018 Karn Saheb
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.karn.notify.entities

import android.app.NotificationManager
Expand Down
30 changes: 28 additions & 2 deletions library/src/main/java/io/karn/notify/entities/Payload.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2018 Karn Saheb
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.karn.notify.entities

import android.app.PendingIntent
Expand Down Expand Up @@ -108,11 +132,13 @@ sealed class Payload {
*/
@ColorInt var lightColor: Int = Notify.NO_LIGHTS,
/**
* Vibration pattern for notification on this notifyChannel.
* Vibration pattern for notification on this notifyChannel. This is only set on
* notifications with importance that is at least [Notify.IMPORTANCE_NORMAL] or higher.
*/
var vibrationPattern: List<Long> = ArrayList(),
/**
* A custom notification sound if any.
* A custom notification sound if any. This is only set on notifications with importance
* that is at least [Notify.IMPORTANCE_NORMAL] or higher.
*/
var sound: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2018 Karn Saheb
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.karn.notify.internal

import android.annotation.SuppressLint
Expand Down Expand Up @@ -25,7 +49,7 @@ internal object NotificationChannelInterop {

// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
val channel = NotificationChannel(alerting.channelKey, alerting.channelName, alerting.channelImportance + 2).apply {
val channel = NotificationChannel(alerting.channelKey, alerting.channelName, alerting.channelImportance + 3).apply {
description = alerting.channelDescription

// Set the lockscreen visibility.
Expand Down
Loading

0 comments on commit da48adf

Please sign in to comment.