Skip to content

Commit

Permalink
Merge pull request #99 from GlobalMessageServices/develop
Browse files Browse the repository at this point in the history
Bump target SDK API to 34
Bump Kotlin version to 1.9.22
Bump Gradle version to 8.4.0
Bump Dokka version to 1.9.10
Bump version of com.google.gms:google-services to 4.4.2
Bump version of androidx.core:core-ktx to 1.13.1
Bump version of androidx.lifecycle:lifecycle-process to 2.8.3
Bump version of com.google.firebase:firebase-messaging to 24.0.0
Bump version of androidx.work:work-runtime-ktx to 2.9.0
  • Loading branch information
o-korniienko committed Jul 25, 2024
2 parents afce517 + 21f5948 commit 9b6cafb
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 118 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ on:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
runs-on: macos-latest
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11
java-version: 17
- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
Expand All @@ -38,5 +39,8 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
api-level: 29
arch: x86_64
profile: Nexus 6
force-avd-creation: false
script: ./gradlew connectedCheck && ./gradlew build sonar --info

58 changes: 46 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ allprojects {
}
}
```
Add SDK dependency to your module (app-level) build.gradle. The latest version 1.1.9
Add SDK dependency to your module (app-level) build.gradle. The latest version 1.1.10
```Gradle
dependencies {
...
//or use a newer version if available
'com.github.GlobalMessageServices:Hyber-GMS-SDK-Android:1.1.9'
'com.github.GlobalMessageServices:Hyber-GMS-SDK-Android:1.1.10'
}
```
To use http protocol instead of https, add android:usesCleartextTraffic="true" to your application tag inside android manifest
Expand Down Expand Up @@ -566,15 +566,14 @@ override fun prepareNotification(data: Map<String, String>, notificationId: Int)

### Using reply button in notification
The reply button empowers end users to make a response to the push message directly from notification. <br>
It only appears if push message is 2way. <br>
You can catch user's response and process it by using the followed code in BroadcastReceiver:
To display reply button in notification and process the user's response you should create class that extends BroadcastReceiver and override function `onReceive(context: Context?, intent: Intent?)`: <br>
```Kotlin
private val mPlugInReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
class MyBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val remoteInput = RemoteInput.getResultsFromIntent(intent)
when (intent.action) {
PushSDK.NOTIFICATION_REPLY_INTENT_ACTION -> {
intent.extras?.let {
//get extra data
Expand All @@ -585,11 +584,11 @@ private val mPlugInReceiver = object : BroadcastReceiver() {
if (remoteInput != null) {
//get reply text
val reply = remoteInput.getCharSequence(
"pushsdk.remote_input_key"
PushSdkNotificationManager.REMOTE_INPUT_KEY
).toString()
println("reply is: $reply")
// cancel notification to update reply UI
// cancel notification to update notification UI
NotificationManagerCompat.from(context).cancel(tag,id)
}
}
Expand All @@ -599,6 +598,39 @@ private val mPlugInReceiver = object : BroadcastReceiver() {
}
}
```
Register MyBroadcastReceiver in AndroidManifest.xml: <br>
```Gradle
<application
...>
...
<receiver
android:name=".handler.MyBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="pushsdk.notification.reply.intent" />
</intent-filter>
</receiver>
</application>
```
Create Intent with MyBroadcastReceiver and manually change function `prepareNotification(data: Map<String, String>, notificationId: Int): NotificationCompat.Builder?` in `MyPushKFirebaseService`: <br>
```Kotlin
override fun prepareNotification(
data: Map<String, String>,
notificationId: Int
): NotificationCompat.Builder? {
val replyIntent = Intent(this, MyBroadcastReceiver::class.java)
return pushSdkNotificationManager.constructNotification(
data,
notificationId,
PushSdkNotificationManager.NotificationStyle.BIG_TEXT,
replyIntent
)
}
```
`Reply button only appears in notifications if push message is 2way and you pass replyIntent into `constructNotification()` function.` <br>
***
# Bubbles
Expand All @@ -622,12 +654,13 @@ private val mPlugInReceiver = object : BroadcastReceiver() {
* Manually chang the `NotificationCompat.Builder` object style to NotificationStyle.BUBBLES and pass Intent object with BubbleActivity to the called function constructNotification <br>
It can be achieved by overriding the `prepareNotification()` method
```Kotlin
override fun prepareNotification(data: Map<String, String>): NotificationCompat.Builder? {
override fun prepareNotification(data: Map<String, String>, notificationId: Int): NotificationCompat.Builder? {
return pushSdkNotificationManager.constructNotification(
data,
notificationId,
PushSdkNotificationManager.NotificationStyle.BUBBLES,
bubbleIntent = Intent(this, BubbleActivity::class.java)
)
}
```
Expand Down Expand Up @@ -816,9 +849,10 @@ class MessageAdapter(private val messages: MutableList<ChatMessage>) :
### You can change Bubble settings by passing the `BubbleSettings` object to the called function constructNotification
```Kotlin
override fun prepareNotification(data: Map<String, String>): NotificationCompat.Builder? {
override fun prepareNotification(data: Map<String, String>, notificationId: Int): NotificationCompat.Builder? {
return pushSdkNotificationManager.constructNotification(
data,
notificationId,
PushSdkNotificationManager.NotificationStyle.BUBBLES,
bubbleIntent = Intent(this, BubbleActivity::class.java),
bubbleSettings = BubbleSettings(shortLabel = "My custom label")
Expand Down
18 changes: 10 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@


buildscript {
ext.kotlin_version = '1.9.10'
ext.gradleVersion = '7.4.2'
ext.dokka_version = "1.8.20"
ext.jacocoVersion = '0.8.10'
ext.kotlin_version = '1.9.22'
ext.gradleVersion = '8.4.0'
ext.dokka_version = "1.9.10"
ext.jacocoVersion = '0.8.12'
repositories {
google()
jcenter()
//jcenter()
mavenCentral()
maven {
url 'https://jitpack.io'
}
Expand All @@ -22,7 +23,7 @@ buildscript {
classpath("org.jetbrains.dokka:dokka-gradle-plugin:${dokka_version}")

//noinspection GradleDependency
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.google.gms:google-services:4.4.2'
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"

//test coverage
Expand All @@ -34,7 +35,7 @@ buildscript {
}

plugins{
id "org.sonarqube" version "4.3.1.3277"
id "org.sonarqube" version "5.1.0.4882"
}

sonarqube {
Expand All @@ -49,7 +50,8 @@ sonarqube {
allprojects {
repositories {
google()
jcenter()
//jcenter()
mavenCentral()
maven {
url 'https://jitpack.io'
}
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 14 09:23:53 CET 2023
#Tue May 07 14:00:08 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
38 changes: 19 additions & 19 deletions pushsdkandroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ apply plugin: 'jacoco'
ext.build_version_name = '1.1.9'

android {
compileSdkVersion 33
buildToolsVersion "30.0.3"
namespace = "com.push.android.pushsdkandroid"

buildFeatures {
buildConfig = true
}

defaultConfig {
//applicationId "com.push.android.pushsdkandroid"
minSdkVersion 21
targetSdkVersion 33
compileSdk 34
targetSdkVersion 34
versionCode 1

versionName "${build_version_name}"
Expand Down Expand Up @@ -53,15 +57,15 @@ android {
}

kotlinOptions {
jvmTarget=11
jvmTarget = 11
}
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

reports {
xml.enabled = true
html.enabled = true
xml { enabled true }
html { enabled true }
}

def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
Expand All @@ -78,29 +82,25 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'crea
}






dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.lifecycle:lifecycle-process:2.6.1'
implementation 'androidx.test:monitor:1.6.1'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.lifecycle:lifecycle-process:2.8.3'
implementation 'androidx.test:monitor:1.7.1'
implementation 'androidx.security:security-crypto:1.1.0-alpha06'


testImplementation 'junit:junit:4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testImplementation project(path: ':pushsdkandroid')
testImplementation 'org.robolectric:robolectric:4.10.3'


androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'

implementation 'android.arch.work:work-runtime:1.0.1'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0"
Expand All @@ -110,17 +110,17 @@ dependencies {
//noinspection GradleDependency
//implementation 'com.google.firebase:firebase-iid:20.2.4'
//noinspection GradleDependency
implementation 'com.google.firebase:firebase-messaging:23.2.1'
implementation 'com.google.firebase:firebase-messaging:24.0.0'

implementation 'io.github.microutils:kotlin-logging:3.0.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'

implementation "org.jacoco:org.jacoco.agent:0.8.8:runtime"
implementation "org.jacoco:org.jacoco.agent:0.8.11:runtime"

implementation 'com.google.code.gson:gson:2.10.1'

//WorkManager Version 2.7.0 is required for apps targeting Android 12 (S) or higher
implementation 'androidx.work:work-runtime-ktx:2.8.1'
implementation 'androidx.work:work-runtime-ktx:2.9.0'
}

//get HEAD commit hash
Expand Down
18 changes: 16 additions & 2 deletions pushsdkandroid/src/androidTest/java/PushSDKAndroidTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.push.android.pushsdkandroid.managers.PushSdkNotificationManager
import com.push.android.pushsdkandroid.settings.BubbleSettings
import com.push.android.pushsdkandroid.utils.Info
import junit.framework.TestCase
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -118,14 +119,16 @@ class PushSDKAndroidTest {
remoteMessage2.data,
notificationIdBubbles,
PushSdkNotificationManager.NotificationStyle.BUBBLES,
null,
bubbleIntent = Intent(),
bubbleSettings = BubbleSettings()
)

val construct2Way = notificationManager.constructNotification(
remoteMessage3.data,
notificationManager.getNotificationId(),
PushSdkNotificationManager.NotificationStyle.BIG_TEXT
PushSdkNotificationManager.NotificationStyle.BIG_TEXT,
Intent(appContext, PushSDKAndroidTest::class.java)
)

println(construct1)
Expand All @@ -136,11 +139,22 @@ class PushSDKAndroidTest {
println(construct2Way)

val isSent = construct2?.let { notificationManager.sendNotification(it, notificationId) }
val isSent2wWay =
construct2Way?.let { notificationManager.sendNotification(it, notificationId) }

val isSentBubble =
constructBubble?.let { notificationManager.sendNotification(it, notificationIdBubbles) }



val isSentBubble = constructBubble?.let { notificationManager.sendNotification(it, notificationIdBubbles) }

println(isSent)
println(isSent2wWay)
println(isSentBubble)

assertEquals(true, isSent)
assertEquals(true, isSent2wWay)

}

@Test
Expand Down
2 changes: 1 addition & 1 deletion pushsdkandroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.push.android.pushsdkandroid">
<manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ open class PushKFirebaseService(
val notificationConstruct = prepareNotification(remoteMessage.data, notificationId)
if (notificationConstruct != null) {
var isNotificationSent =
pushSdkNotificationManager.sendNotification(notificationConstruct, notificationId)
pushSdkNotificationManager.sendNotification(
notificationConstruct,
notificationId
)
if (isNotificationSent) {
onNotificationSent(
appIsInForeground,
Expand Down Expand Up @@ -271,7 +274,10 @@ open class PushKFirebaseService(
* @return NotificationCompat.Builder?
* @see PushSdkNotificationManager.NotificationStyle, (https://developer.android.com/training/notify-user/group), (https://stackoverflow.com/a/41114135)
*/
open fun prepareNotification(data: Map<String, String>, notificationId: Int): NotificationCompat.Builder? {
open fun prepareNotification(
data: Map<String, String>,
notificationId: Int
): NotificationCompat.Builder? {
PushSDKLogger.debug(applicationContext, "calling prepareNotification()")
return pushSdkNotificationManager.constructNotification(
data,
Expand Down
Loading

0 comments on commit 9b6cafb

Please sign in to comment.