Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android deeplink support (send notifications with URI on Android devices) #60

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 19 additions & 60 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
distribution: 'temurin'

- name: Setup gradle
uses: gradle/gradle-build-action@v2.4.2
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1

- name: Check api
run: ./gradlew apiCheck
Expand All @@ -59,7 +59,7 @@ jobs:
distribution: 'temurin'

- name: Setup gradle
uses: gradle/gradle-build-action@v2.4.2
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1

- name: Test ${{ matrix.config.target }} targets
continue-on-error: ${{ matrix.config.continueOnError }}
Expand All @@ -84,7 +84,7 @@ jobs:
distribution: 'temurin'

- name: Setup gradle
uses: gradle/gradle-build-action@v2.4.2
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1

- name: Setup Pages
uses: actions/configure-pages@v3
Expand All @@ -101,73 +101,32 @@ jobs:
id: deployment
uses: actions/deploy-pages@v1

- name: Create new release from tag
env:
github_token: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
token: ${{ env.github_token }}


create-staging-repository:
runs-on: ubuntu-latest
name: Create staging repository
needs: release
outputs:
repository_id: ${{ steps.create.outputs.repository_id }}
steps:
- id: create
uses: nexus-actions/[email protected]
with:
username: ${{ secrets.SONATYPE_USERNAME }}
password: ${{ secrets.SONATYPE_PASSWORD }}
staging_profile_id: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
description: Created by GitHub Actions
base_url: https://s01.oss.sonatype.org/service/local/

publish:
name: Publish to Maven
runs-on: macos-latest
needs: create-staging-repository
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Setup gradle
uses: gradle/[email protected]

- name: Write secrets to local.properties
run: |
echo sonatypeUsername="${SONATYPE_USERNAME}" >> "local.properties"
echo sonatypePassword="${SONATYPE_PASSWORD}" >> "local.properties"
echo gpgKeyPassword="${GPG_KEY_PASSWORD}" >> "local.properties"
echo gpgKeySecret="${GPG_KEY_SECRET}" >> "local.properties"
env:
SONATYPE_REPOSITORY_ID: ${{ needs.create-staging-repository.outputs.repository_id }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_USERNAME: mirzemehdi
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GPG_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }}
GPG_KEY_SECRET: ${{ secrets.GPG_KEY_SECRET }}

- name: Release to sonatype
run: ./gradlew publishAllPublicationsToMavenRepository

close-staging-repository:
name: Close staging repository
runs-on: ubuntu-latest
needs: [ create-staging-repository, publish ]
if: ${{ always() && needs.create-staging-repository.result == 'success' }}
steps:
- name: Close staging repository
uses: nexus-actions/release-nexus-staging-repo@6632a81bfab63557b2717e8423b0a620ae5aa414
- name: Publish to sonatype
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1
with:
username: ${{ secrets.SONATYPE_USERNAME }}
password: ${{ secrets.SONATYPE_PASSWORD }}
staging_repository_id: ${{ needs.create-staging-repository.outputs.repository_id }}
base_url: https://s01.oss.sonatype.org/service/local/
arguments: |
publishToSonatype
closeAndReleaseSonatypeStagingRepository

- name: Create new release from tag
env:
github_token: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
token: ${{ env.github_token }}


37 changes: 15 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
alias(libs.plugins.kotlinNativeCocoaPods) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.kotlinx.binary.validator)

alias(libs.plugins.nexusPublish)
id("com.google.gms.google-services") version "4.4.0" apply false
}

Expand All @@ -21,9 +21,8 @@ plugins {

allprojects {
group = "io.github.mirzemehdi"
version = "1.2.0-alpha02"
val sonatypeUsername = gradleLocalProperties(rootDir).getProperty("sonatypeUsername")
val sonatypePassword = gradleLocalProperties(rootDir).getProperty("sonatypePassword")
version = project.properties["kmpNotifierVersion"] as String

val gpgKeySecret = gradleLocalProperties(rootDir).getProperty("gpgKeySecret")
val gpgKeyPassword = gradleLocalProperties(rootDir).getProperty("gpgKeyPassword")

Expand All @@ -36,24 +35,6 @@ allprojects {


extensions.configure<PublishingExtension> {
repositories {
maven {
val isSnapshot = version.toString().endsWith("SNAPSHOT")
val repositoryId = System.getenv("SONATYPE_REPOSITORY_ID") ?: ""
url = uri(
when{
isSnapshot.not() && repositoryId.isNotEmpty() -> "https://s01.oss.sonatype.org/service/local/staging/deployByRepositoryId/${repositoryId}/"
isSnapshot.not() -> "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2"
else -> "https://s01.oss.sonatype.org/content/repositories/snapshots"
}
)
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}

val javadocJar = tasks.register<Jar>("javadocJar") {
dependsOn(tasks.getByName<DokkaTask>("dokkaHtml"))
archiveClassifier.set("javadoc")
Expand Down Expand Up @@ -104,5 +85,17 @@ allprojects {
dependsOn(project.tasks.withType(Sign::class.java))
}
}
nexusPublishing {
repositories {
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
val sonatypeUsername = gradleLocalProperties(rootDir).getProperty("sonatypeUsername")
val sonatypePassword = gradleLocalProperties(rootDir).getProperty("sonatypePassword")
username = sonatypeUsername
password = sonatypePassword
}
}
}


4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.mpp.enableCInteropCommonization=true

#Development
development=true
development=true

kmpNotifierVersion=1.2.0-alpha02
19 changes: 11 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
[versions]
compose = "1.6.7"
compose-plugin = "1.6.10"
agp = "8.2.0"
compose = "1.6.8"
compose-plugin = "1.6.11"
agp = "8.2.2"
android-minSdk = "21"
android-compileSdk = "34"
android-targetSdk = "34"
androidx-activityCompose = "1.9.0"
androidx-activityCompose = "1.9.1"
androidx-core-ktx = "1.13.1"
androidx-appcompat = "1.7.0"
androidx-material = "1.12.0"
androidx-constraintlayout = "2.1.4"
androidx-test-junit = "1.1.5"
androidx-espresso-core = "3.5.1"
androidx-test-junit = "1.2.1"
androidx-espresso-core = "3.6.1"
androidx-startup-runtime = "1.1.1"
kotlin = "2.0.0"
junit = "4.13.2"
koin = "3.6.0-Beta5"
koin = "4.0.0-RC1"
kotlinx-binary-validator = "0.13.2"
dokka = "1.9.10"
firebase-messaging = "24.0.0"
kotlinx-coroutine = "1.9.0-RC"
nexusPublish = "2.0.0"



[libraries]
Expand Down Expand Up @@ -55,4 +57,5 @@ androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinNativeCocoaPods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
kotlinx-binary-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "kotlinx-binary-validator" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublish" }
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ internal class AndroidNotifier(
}

private fun getPendingIntent(payloadData: Map<String, String>): PendingIntent? {


val intent = getLauncherActivityIntent()?.apply {
putExtra(ACTION_NOTIFICATION_CLICK, ACTION_NOTIFICATION_CLICK)
payloadData.forEach { putExtra(it.key, it.value) }
val urlData = payloadData.getOrDefault(Notifier.KEY_URL, null)
urlData?.let { setData(Uri.parse(urlData)) }
}
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

Expand All @@ -84,5 +88,4 @@ internal class AndroidNotifier(
return packageManager.getLaunchIntentForPackage(context.applicationContext.packageName)
}


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.mmk.kmpnotifier.notification

import org.koin.core.scope.Scope

/**
* Class that represent local notification
*/
public interface Notifier {

public companion object {
public const val KEY_URL: String = "URL"
}

/**
* Sends local notification to device
* @param title Title part
Expand Down
10 changes: 9 additions & 1 deletion sample/src/commonMain/kotlin/com/mmk/kmpnotifier/sample/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.mmk.kmpnotifier.notification.Notifier
import com.mmk.kmpnotifier.notification.NotifierManager

@Composable
Expand Down Expand Up @@ -45,7 +46,14 @@ fun App() {
val permissionUtil = remember { NotifierManager.getPermissionUtil() }
var notificationId by remember { mutableStateOf(0) }
Button(onClick = {
notificationId = notifier.notify("Title", "bodyMessage")
notificationId = notifier.notify(
title = "Title",
body = "bodyMessage",
payloadData = mapOf(
Notifier.KEY_URL to "https://github.com/mirzemehdi/KMPNotifier/",
"extraKey" to "randomValue"
)
)
}) {
Text("Send Local Notification")
}
Expand Down