@@ -8,18 +8,21 @@ import ai.pams.android.kotlin.utils.DateUtils
8
8
import android.content.Context
9
9
import android.os.Parcel
10
10
import android.os.Parcelable
11
+ import kotlinx.parcelize.IgnoredOnParcel
11
12
import org.json.JSONObject
12
13
import java.text.SimpleDateFormat
13
14
import java.util.*
15
+ import kotlinx.parcelize.Parcelize
16
+ import kotlinx.parcelize.RawValue
14
17
15
-
18
+ @Parcelize
16
19
data class NotificationItem (
17
20
var date : Date ? = null ,
18
21
val deliverId : String? = null ,
19
22
val description : String? = null ,
20
23
val flex : String? = null ,
21
24
val isOpen : Boolean? = null ,
22
- val payload : Map <String , Any >? = null ,
25
+ val payload : @RawValue Map <String , Any >? = null ,
23
26
val pixel : String? = null ,
24
27
val thumbnailUrl : String? = null ,
25
28
val title : String? = null ,
@@ -53,100 +56,4 @@ data class NotificationItem(
53
56
}
54
57
}
55
58
56
-
57
- // PARCEL IMPLEMENTATION
58
- constructor (parcel: Parcel ) : this (
59
- // date
60
- convertStringToDate(parcel.readString() ),
61
- // deliverId
62
- parcel.readString(),
63
- // description
64
- parcel.readString(),
65
- // flex
66
- parcel.readString(),
67
- // isOpen
68
- parcel.readValue(Boolean ::class .java.classLoader) as ? Boolean ,
69
- // payload
70
- jsonToMap( parcel.readString()),
71
- // pixel
72
- parcel.readString(),
73
- // thumbnailUrl
74
- parcel.readString(),
75
- // title
76
- parcel.readString(),
77
- // url
78
- parcel.readString(),
79
- // popupType
80
- parcel.readString()
81
- ) {
82
- bannerUrl = parcel.readString()
83
- }
84
-
85
- override fun writeToParcel (parcel : Parcel , flags : Int ) {
86
- // date
87
- if ( date != null ){
88
- var dateStr = " "
89
- date?.let {
90
- val dateFormat = SimpleDateFormat (" yyyy-mm-dd hh:mm:ss" )
91
- dateStr = dateFormat.format(it)
92
- }
93
- parcel.writeString(dateStr)
94
- }else {
95
- parcel.writeString(" -" )
96
- }
97
-
98
- parcel.writeString(deliverId)
99
- parcel.writeString(description)
100
- parcel.writeString(flex)
101
- parcel.writeValue(isOpen)
102
- parcel.writeValue(payload)
103
- parcel.writeString(pixel)
104
- parcel.writeString(thumbnailUrl)
105
- parcel.writeString(title)
106
- parcel.writeString(url)
107
- parcel.writeString(popupType)
108
- parcel.writeString(bannerUrl)
109
- }
110
-
111
- override fun describeContents (): Int {
112
- return 0
113
- }
114
-
115
- companion object CREATOR : Parcelable.Creator<NotificationItem> {
116
- override fun createFromParcel (parcel : Parcel ): NotificationItem {
117
- return NotificationItem (parcel)
118
- }
119
-
120
- override fun newArray (size : Int ): Array <NotificationItem ?> {
121
- return arrayOfNulls(size)
122
- }
123
-
124
- fun jsonToMap (jsonStr : String? ): Map <String , Any >? {
125
- if (jsonStr == null ){
126
- return null
127
- }
128
- val json = JSONObject (jsonStr)
129
- val m = mutableMapOf<String , Any >()
130
- json.keys().forEach {
131
- if (json.get(it) is Int ){
132
- m[it] = json.optInt(it)
133
- }else if (json.get(it) is String ){
134
- m[it] = json.optString(it)
135
- }else if (json.get(it) is Boolean ){
136
- m[it] = json.optBoolean(it)
137
- }else if (json.get(it) is Double ){
138
- m[it] = json.optDouble(it)
139
- }else {
140
- m[it] = json.get(it)
141
- }
142
- }
143
- return m.toMap()
144
- }
145
- fun convertStringToDate (str : String? ): Date ? {
146
- str?.let {
147
- return @convertStringToDate SimpleDateFormat (" yyyy-MM-dd hh:mm:ss" ).parse(it)
148
- }
149
- return null
150
- }
151
- }
152
59
}
0 commit comments