Skip to content

Commit 69471a5

Browse files
committed
Merge branch 'release/1.4.14'
2 parents e14fe85 + 76ca662 commit 69471a5

File tree

1 file changed

+99
-0
lines changed
  • pam-android-kotlin/src/main/java/ai/pams/android/kotlin/utils

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package ai.pams.android.kotlin.utils
2+
3+
import ai.pams.android.kotlin.models.notification.NotificationItem
4+
import android.app.Activity
5+
import android.content.Context
6+
import android.content.Intent
7+
import com.google.firebase.messaging.RemoteMessage
8+
import org.json.JSONObject
9+
import org.threeten.bp.LocalDateTime
10+
11+
class PAMUtils {
12+
companion object{
13+
fun isPamNotification(message: RemoteMessage): Boolean{
14+
return message.data.containsKey("pam")
15+
}
16+
17+
fun convertRemoteMessageToPam(remoteMessage: RemoteMessage, context: Context): NotificationItem?{
18+
//remoteMessage.notification
19+
return when(remoteMessage.data.containsKey("pam")){
20+
true-> {
21+
val pam = remoteMessage.data["pam"] ?: "{}"
22+
val pamObj = JSONObject(pam)
23+
24+
val payload = mutableMapOf<String, Any>()
25+
pamObj.keys().forEach { key->
26+
if(key != "popupType" && key != "flex" && key != "pixel" && key != "url" && key != "created_date") {
27+
payload[key] = pamObj.get(key)
28+
}
29+
}
30+
31+
val createdDate = when(pamObj.getString("created_date")){
32+
null-> LocalDateTime.now()
33+
else-> DateUtils.localDateTimeFromString(pamObj.getString("created_date"))
34+
}
35+
36+
NotificationItem(
37+
createdDate,
38+
null,
39+
remoteMessage.notification?.body,
40+
pamObj.getString("flex"),
41+
false,
42+
payload,
43+
pamObj.getString("pixel"),
44+
null,
45+
remoteMessage.notification?.title,
46+
pamObj.getString("url"),
47+
pamObj.optString("popupType"),
48+
).also {
49+
it.parseFlex(context)
50+
}
51+
}
52+
else-> null
53+
}
54+
}
55+
56+
fun readPamNotificationFromIntent(intent: Intent, context: Context): NotificationItem? {
57+
58+
return when(intent.extras?.containsKey("pam")){
59+
true-> {
60+
val title = intent.extras?.getString("title")
61+
val message = intent.extras?.getString("message")
62+
63+
val pam = intent.extras?.getString("pam")
64+
val pamObj = JSONObject(pam)
65+
66+
val payload = mutableMapOf<String, Any>()
67+
pamObj.keys().forEach { key->
68+
if(key != "popupType" && key != "flex" && key != "pixel" && key != "url" && key != "created_date") {
69+
payload[key] = pamObj.get(key)
70+
}
71+
}
72+
73+
val createdDate = when(pamObj.getString("created_date")){
74+
null-> LocalDateTime.now()
75+
else-> DateUtils.localDateTimeFromString(pamObj.getString("created_date"))
76+
}
77+
78+
NotificationItem(
79+
createdDate,
80+
null,
81+
message,
82+
pamObj.getString("flex"),
83+
false,
84+
payload,
85+
pamObj.getString("pixel"),
86+
null,
87+
title,
88+
pamObj.getString("url"),
89+
pamObj.getString("popupType"),
90+
).also {
91+
it.parseFlex(context)
92+
}
93+
94+
}
95+
else-> null
96+
}
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)