Skip to content

Commit

Permalink
Release 1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
cristidregan committed Jun 10, 2022
1 parent c52e263 commit bf042cc
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion OmetriaSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.2.2"
versionName "1.2.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down
13 changes: 8 additions & 5 deletions OmetriaSDK/src/main/java/com/android/ometriasdk/core/Ometria.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import android.app.Notification.COLOR_DEFAULT
import android.content.Intent
import android.net.Uri
import android.webkit.URLUtil
import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.ProcessLifecycleOwner
import com.android.ometriasdk.core.Constants.Params.BASKET
Expand Down Expand Up @@ -412,11 +413,13 @@ class Ometria private constructor() : OmetriaNotificationInteractionHandler {
remoteMessage.toOmetriaNotification()

override fun onNotificationInteraction(ometriaNotification: OmetriaNotification) {
ometriaNotification.deepLinkActionUrl.let { safeDeeplinkActionUrl ->
Logger.d(
Constants.Logger.PUSH_NOTIFICATIONS,
"Open URL: $safeDeeplinkActionUrl"
)
ometriaNotification.deepLinkActionUrl?.let { safeDeeplinkActionUrl ->
if (URLUtil.isValidUrl(safeDeeplinkActionUrl).not()) {
Logger.e(Constants.Logger.PUSH_NOTIFICATIONS, "Can not open $safeDeeplinkActionUrl")
return
}

Logger.d(Constants.Logger.PUSH_NOTIFICATIONS, "Open URL: $safeDeeplinkActionUrl")
val intent = Intent(Intent.ACTION_VIEW)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.data = Uri.parse(safeDeeplinkActionUrl)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.ometriasdk.notification

import android.annotation.SuppressLint
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
Expand Down Expand Up @@ -27,6 +28,7 @@ internal class OmetriaPushNotification(
private val notificationColor: Int?
) {

@SuppressLint("LaunchActivityFromNotification")
fun createPushNotification(
title: String?,
body: String?,
Expand All @@ -38,7 +40,7 @@ internal class OmetriaPushNotification(
context,
System.currentTimeMillis().toInt(),
getRoutingIntent(ometriaNotificationBody),
PendingIntent.FLAG_UPDATE_CURRENT
getFlags()
)

val notificationBuilder = NotificationCompat.Builder(context, OMETRIA_CHANNEL_ID)
Expand Down Expand Up @@ -76,4 +78,10 @@ internal class OmetriaPushNotification(
.setClass(context, PushClickBroadcastReceiver::class.java)
.putExtras(options)
}

private fun getFlags(): Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.android.ometriasdk.notification
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.webkit.URLUtil
import com.android.ometriasdk.core.Ometria
import com.android.ometriasdk.core.event.OmetriaEventType
import com.android.ometriasdk.core.network.toOmetriaNotification
Expand All @@ -28,15 +27,11 @@ internal class PushClickBroadcastReceiver : BroadcastReceiver() {
val ometriaNotificationBody =
intent.getStringExtra(OMETRIA_NOTIFICATION_BODY_KEY)?.toOmetriaNotificationBody()


ometriaNotificationBody?.let { safeOmetriaNotificationBody ->
if (safeOmetriaNotificationBody.deepLinkActionUrl != null
&& URLUtil.isValidUrl(safeOmetriaNotificationBody.deepLinkActionUrl)
) {
if (safeOmetriaNotificationBody.deepLinkActionUrl != null) {
Ometria.instance().notificationInteractionHandler.onDeepLinkInteraction(
safeOmetriaNotificationBody.deepLinkActionUrl
)

}
Ometria.instance().notificationInteractionHandler.onNotificationInteraction(
safeOmetriaNotificationBody.toOmetriaNotification()
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
defaultConfig {
applicationId "com.android.sample"
minSdkVersion 21
targetSdkVersion 29
targetSdkVersion 31
versionCode 1
versionName "1.0.0"

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:theme="@style/AppTheme">
<activity
android:name=".presentation.MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustNothing">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/android/sample/SampleApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import android.content.Intent
import android.net.Uri
import android.util.Log
import android.webkit.URLUtil
import androidx.core.content.ContextCompat
import com.android.ometriasdk.core.Ometria
import com.android.ometriasdk.notification.OmetriaNotification
Expand Down Expand Up @@ -55,6 +56,8 @@ class SampleApp : Application(), OmetriaNotificationInteractionHandler {

private fun openBrowser(deepLink: String?) {
deepLink?.let { safeDeepLink ->
if (URLUtil.isValidUrl(safeDeepLink).not()) return

Ometria.instance()
.trackDeepLinkOpenedEvent(safeDeepLink, "Browser")
Log.d(SampleApp::class.java.simpleName, "Open URL: $safeDeepLink")
Expand Down

0 comments on commit bf042cc

Please sign in to comment.