Skip to content

Commit

Permalink
feat(PPG - Flags): add ovveride for flags in handleBackgroundNotifica…
Browse files Browse the repository at this point in the history
…tionClick
  • Loading branch information
amarose committed Aug 19, 2024
1 parent 67ad878 commit 3600ca1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ dependencyResolutionManagement {

// /libs.versions.toml
[versions]
ppgSdk = "2.1.0"
ppgSdk = "2.2.0"

[libraries]
ppg-sdk = { module = "com.github.ppgco.android-sdk:sdk", version.ref = "ppgSdk" }
Expand Down
10 changes: 5 additions & 5 deletions library/src/main/java/com/pushpushgo/sdk/PushPushGo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PushPushGo private constructor(
) {

companion object {
const val VERSION = "2.1.0-20240509~1"
const val VERSION = "2.2.0-20240819~1"

internal const val TAG = "PPGo"

Expand Down Expand Up @@ -169,7 +169,7 @@ class PushPushGo private constructor(
*/
var defaultIsSubscribed: Boolean = false

var notificationHandler: NotificationHandler = { context, url -> handleNotificationLinkClick(context, url) }
var notificationHandler: NotificationHandler = { context, url, overrideFlags -> handleNotificationLinkClick(context, url, overrideFlags) }

/**
* function to check whether the given notification data belongs to the PPGo sender
Expand Down Expand Up @@ -212,7 +212,7 @@ class PushPushGo private constructor(
/**
* helper function to handle click on notification from background
*/
fun handleBackgroundNotificationClick(intent: Intent?) {
fun handleBackgroundNotificationClick(intent: Intent?, overrideFlags: Int = Intent.FLAG_ACTIVITY_NEW_TASK) {
if (intent?.hasExtra(PushNotificationDelegate.PROJECT_ID_EXTRA) != true) return

val intentProjectId = intent.getStringExtra(PushNotificationDelegate.PROJECT_ID_EXTRA)
Expand All @@ -230,7 +230,7 @@ class PushPushGo private constructor(

//TODO Remove duplicated code
val notify = deserializeNotificationData(intent.extras)
notificationHandler(application, notify?.redirectLink ?: intentLink)
notificationHandler(application, notify?.redirectLink ?: intentLink, overrideFlags)
intent.removeExtra(PushNotificationDelegate.PROJECT_ID_EXTRA)

uploadDelegate.sendEvent(
Expand Down Expand Up @@ -363,6 +363,6 @@ class PushPushGo private constructor(
fun createBeacon(): BeaconBuilder = BeaconBuilder(uploadDelegate)
}

typealias NotificationHandler = (context: Context, url: String) -> Unit
typealias NotificationHandler = (context: Context, url: String, overrideFlags: Int) -> Unit

typealias InvalidProjectIdHandler = (pushProjectId: String, pushSubscriberId: String, currentProjectId: String) -> Unit
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ internal fun deserializeNotificationData(data: Bundle?): PushPushNotification? {
)
}

internal fun handleNotificationLinkClick(context: Context, uri: String) {
internal fun handleNotificationLinkClick(context: Context, uri: String, overrideFlags: Int) {
Intent.parseUri(uri, 0).let {
it.addFlags(FLAG_ACTIVITY_NEW_TASK)
it.addFlags(overrideFlags)
try {
context.startActivity(it)
} catch (e: ActivityNotFoundException) {
Expand Down

0 comments on commit 3600ca1

Please sign in to comment.