Skip to content

Commit

Permalink
Merge pull request #44 from Karn/develop
Browse files Browse the repository at this point in the history
Version bump: 1.3.0
  • Loading branch information
Karn authored Jul 31, 2019
2 parents da48adf + 498c780 commit 59f4df1
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 71 deletions.
25 changes: 17 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
language: android
dist: trusty
android:
components:
- tools
- platform-tools
- android-28
licenses:
- '.+'

before_script:
- echo yes | /usr/local/android-sdk/tools/bin/sdkmanager --update

script:
- ./gradlew build jacocoTestReport
- ./gradlew connectedCheck
after_success:
- bash <(curl -s https://codecov.io/bash)
- ./gradlew build jacocoTestReport
- ./gradlew connectedCheck

before_install:
- yes | sdkmanager "platforms;android-27"
after_success:
- bash <(curl -s https://codecov.io/bash)

branches:
only:
- master
- develop
- master
- develop
37 changes: 17 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
group = 'io.karn'

subprojects {
buildscript {
apply from: rootProject.file('gradle/configuration.gradle')

buildscript {

repositories {
google()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
repositories {
google()
jcenter()
}

dependencies {
classpath config.build.gradle.androidPlugin
classpath config.build.gradle.kotlin
dependencies {
classpath config.build.gradle.androidPlugin
classpath config.build.gradle.kotlin

// NOTE: Do not place your application configuration here; they belong
// in the individual module build.gradle files
classpath config.build.gradle.androidMaven
// Code coverage
classpath config.build.gradle.jacoco
// Library documentation
classpath config.build.gradle.dokka
}
// NOTE: Do not place your application configuration here; they belong
// in the individual module build.gradle files
classpath config.build.gradle.androidMaven
// Code coverage
classpath config.build.gradle.jacoco
// Library documentation
classpath config.build.gradle.dokka
}
}

subprojects {
repositories {
google()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/configuration.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


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

kotlin: '1.3.11',
core: '1.0.1',
Expand Down
25 changes: 12 additions & 13 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
abortOnError false
}
lintOptions.abortOnError false

testOptions {
unitTests {
Expand All @@ -69,13 +67,6 @@ android {
}
}

allprojects {
repositories {
google()
jcenter()
}
}

dependencies {
implementation config.deps.kotlin.stdlib

Expand All @@ -85,9 +76,7 @@ dependencies {
testImplementation config.testDeps.robolectric
}

jacoco {
toolVersion = config.build.jacocoAgentVersion
}
jacoco.toolVersion = config.build.jacocoAgentVersion

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
Expand All @@ -96,6 +85,16 @@ tasks.withType(Test) {
jvmArgs "-Xmx1024m"
}

/**
* Generate sources. Adapted from https://stackoverflow.com/a/28969412/5037824
*/
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}

artifacts.archives sourcesJar

/**
* Adapted from https://medium.com/@rafael_toledo/unified-code-coverage-for-android-revisited-44789c9b722f
*/
Expand Down
45 changes: 25 additions & 20 deletions library/src/main/java/io/karn/notify/Notify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,30 @@ class Notify internal constructor(internal var context: Context) {
*/
const val CHANNEL_DEFAULT_DESCRIPTION = "General application notifications."
/**
* Lowest priority for a notification. These notifications might not be shown to the user except under special
* circumstances, such as detailed notification logs.
* Lowest priority for a notification. These notifications might not be shown to the user
* except under special circumstances, such as detailed notification logs.
*/
const val IMPORTANCE_MIN = NotificationCompat.PRIORITY_MIN
/**
* Lower priority for notifications that are deemed less important. The UI may choose to show these items
* smaller, or at a different position in the list, compared to notifications with normal importance.
* Lower priority for notifications that are deemed less important. The UI may choose to
* show these items smaller, or at a different position in the list, compared to
* notifications with normal importance.
*/
const val IMPORTANCE_LOW = NotificationCompat.PRIORITY_LOW
/**
* Default priority for notifications. If your application does not prioritize its own notifications, use this
* value for all notifications.
* Default priority for notifications. If your application does not prioritize its own
* notifications, use this value for all notifications.
*/
const val IMPORTANCE_NORMAL = NotificationCompat.PRIORITY_DEFAULT
/**
* Higher priority for notifications, for more important notifications or alerts. The UI may choose to show
* these items larger, or at a different position in notification lists, compared with your app's notifications
* of normal importance.
* Higher priority for notifications, for more important notifications or alerts. The UI may
* choose to show these items larger, or at a different position in notification lists,
* compared with your app's notifications of normal importance.
*/
const val IMPORTANCE_HIGH = NotificationCompat.PRIORITY_HIGH
/**
* Highest priority for notifications, use for notifications that require the user's prompt attention or input.
* Highest priority for notifications, use for notifications that require the user's prompt
* attention or input.
*/
const val IMPORTANCE_MAX = NotificationCompat.PRIORITY_MAX

Expand All @@ -96,8 +98,8 @@ class Notify internal constructor(internal var context: Context) {
/**
* A new {@see Notify} and {@see NotifyCreator} instance.
*
* This object is automatically initialized with the singleton default configuration which can be modified using
* {@see Notify#defaultConfig((NotifyConfig) -> Unit)}.
* This object is automatically initialized with the singleton default configuration which
* can be modified using {@see Notify#defaultConfig((NotifyConfig) -> Unit)}.
*/
fun with(context: Context): NotifyCreator {
return NotifyCreator(Notify(context))
Expand All @@ -123,23 +125,26 @@ class Notify internal constructor(internal var context: Context) {
}

/**
* Return the standard {@see NotificationCompat.Builder} after applying fluent API transformations (if any) from the
* {@see NotifyCreator} builder object.
* Return the standard {@see NotificationCompat.Builder} after applying fluent API
* transformations (if any) from the {@see NotifyCreator} builder object.
*/
internal fun asBuilder(payload: RawNotification): NotificationCompat.Builder {
return NotificationInterop.buildNotification(this, payload)
}

/**
* Delegate a {@see Notification.Builder} object to the Notify NotificationInterop class which builds and displays
* the notification.
* Delegate a {@see Notification.Builder} object to the Notify NotificationInterop class which
* builds and displays the notification.
*
* This is a terminal operation.
*
* @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.
* @param id An optional integer which will be used as the ID for the notification that is
* shown. This argument is ignored if the notification is a NotifyCreator#stackable
* receiver is set.
* @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 show(builder: NotificationCompat.Builder): Int {
return NotificationInterop.showNotification(Notify.defaultConfig.notificationManager!!, builder)
internal fun show(id: Int?, builder: NotificationCompat.Builder): Int {
return NotificationInterop.showNotification(Notify.defaultConfig.notificationManager!!, id, builder)
}
}
11 changes: 7 additions & 4 deletions library/src/main/java/io/karn/notify/NotifyCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,21 @@ class NotifyCreator internal constructor(private val notify: Notify) {
*
* This is a terminal operation.
*
* @param id An optional integer which will be used as the ID for the notification that is
* shown. This argument is ignored if the notification is a NotifyCreator#stackable
* receiver is set.
* @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 show(): Int {
return notify.show(asBuilder())
fun show(id: Int? = null): Int {
return notify.show(id, asBuilder())
}

/**
* Cancel an existing notification given an ID.
*
* @deprecated Choose to instead use the static function {@see Notify#cancelNotification()} which provides the correct
* encapsulation of the this `cancel` function.
* @deprecated Choose to instead use the static function {@see Notify#cancelNotification()}
* which provides the correct encapsulation of the this `cancel` function.
*/
@Deprecated(message = "Exposes function under the incorrect API -- NotifyCreator is reserved strictly for notification construction.",
replaceWith = ReplaceWith("Notify.cancelNotification(id)", "io.karn.notify.Notify"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import io.karn.notify.internal.utils.Utils

internal object NotificationInterop {

fun showNotification(notificationManager: NotificationManager, notification: NotificationCompat.Builder): Int {
fun showNotification(notificationManager: NotificationManager, id: Int?, notification: NotificationCompat.Builder): Int {
val key = NotifyExtender.getKey(notification.extras)
var id = Utils.getRandomInt()
var id = id ?: Utils.getRandomInt()

if (key != null) {
id = key.hashCode()
Expand Down
14 changes: 14 additions & 0 deletions library/src/test/java/io/karn/notify/NotifyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ class NotifyTest : NotifyTestBase() {
Assert.assertEquals(1, NotificationInterop.getActiveNotifications(shadowNotificationManager).size)
}

@Test
fun showNotificationWithId() {
val expectedId = 10
val actualId = Notify.with(this.context)
.content {
title = "New dessert menu"
text = "The Cheesecake Factory has a new dessert for you to try!"
}
.show(expectedId)

Assert.assertEquals(expectedId, actualId)
Assert.assertEquals(1, NotificationInterop.getActiveNotifications(shadowNotificationManager).size)
}

@Test
fun cancelNotification() {
val notificationId = Notify.with(this.context)
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ dependencies {
implementation project(path: ':library')
}

// Skip teting and linting.
// Skip testing and linting.
tasks.whenTaskAdded { task ->
if (task.name.equals("lint") || task.name.contains("Test")) {
if (task.name == "lint" || task.name.contains("Test")) {
task.enabled = false
}
}

0 comments on commit 59f4df1

Please sign in to comment.