Skip to content

Commit f5e7aef

Browse files
committed
Change Date to Java Date
1 parent ae861a4 commit f5e7aef

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

pam-android-kotlin/src/main/java/ai/pams/android/kotlin/models/notification/NotificationIist.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ai.pams.android.kotlin.models.notification
22

33
import ai.pams.android.kotlin.utils.DateUtils
4+
import ai.pams.android.kotlin.utils.PAMUtils
45
import android.content.Context
56
import org.json.JSONException
67
import org.json.JSONObject
@@ -47,8 +48,10 @@ class NotificationList(
4748
}
4849
}
4950

51+
val date = PAMUtils.convertToJavaDate(DateUtils.localDateTimeFromString(createdDate))
52+
5053
val item = NotificationItem(
51-
date = DateUtils.localDateTimeFromString(createdDate),
54+
date = date,
5255
deliverId = jsonItem.optString("deliver_id"),
5356
description = jsonItem.optString("description"),
5457
flex = jsonItem.optString("flex"),

pam-android-kotlin/src/main/java/ai/pams/android/kotlin/models/notification/NotificationItem.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import android.content.Context
99
import android.os.Parcel
1010
import android.os.Parcelable
1111
import org.json.JSONObject
12-
import org.threeten.bp.LocalDateTime
13-
12+
import java.text.SimpleDateFormat
13+
import java.util.*
1414

1515

1616
data class NotificationItem(
17-
var date: LocalDateTime? = null,
17+
var date: Date? = null,
1818
val deliverId: String? = null,
1919
val description: String? = null,
2020
val flex: String? = null,
@@ -29,7 +29,7 @@ data class NotificationItem(
2929
var bannerUrl: String? = null
3030

3131
@Deprecated("createdDate is deprecated use date instead.", ReplaceWith("date"))
32-
val createdDate: LocalDateTime?
32+
val createdDate: Date?
3333
get() = date
3434

3535
fun parseFlex(context: Context) {
@@ -87,7 +87,8 @@ data class NotificationItem(
8787
if( date != null ){
8888
var dateStr = ""
8989
date?.let{
90-
dateStr = DateUtils.localDateToServerFormat(it)
90+
val dateFormat = SimpleDateFormat("yyyy-mm-dd hh:mm:ss")
91+
dateStr = dateFormat.format(it)
9192
}
9293
parcel.writeString(dateStr)
9394
}else{
@@ -141,9 +142,9 @@ data class NotificationItem(
141142
}
142143
return m.toMap()
143144
}
144-
fun convertStringToDate(str: String?): LocalDateTime?{
145-
str?.let{
146-
return@convertStringToDate DateUtils.localDateTimeFromString(str)
145+
fun convertStringToDate(str: String?): Date?{
146+
str?.let {
147+
return@convertStringToDate SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(it)
147148
}
148149
return null
149150
}

pam-android-kotlin/src/main/java/ai/pams/android/kotlin/utils/PAMUtils.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
package ai.pams.android.kotlin.utils
22

33
import ai.pams.android.kotlin.models.notification.NotificationItem
4-
import android.app.Activity
54
import android.content.Context
65
import android.content.Intent
76
import com.google.firebase.messaging.RemoteMessage
87
import org.json.JSONObject
98
import org.threeten.bp.LocalDateTime
9+
import java.util.*
1010

1111
class PAMUtils {
1212
companion object{
1313
fun isPamNotification(message: RemoteMessage): Boolean{
1414
return message.data.containsKey("pam")
1515
}
1616

17+
fun convertToJavaDate(ld: LocalDateTime): Date {
18+
val cal: Calendar = Calendar.getInstance()
19+
cal.set(Calendar.YEAR, ld.year)
20+
cal.set(Calendar.MONTH,ld.month.value-1)
21+
cal.set(Calendar.DAY_OF_MONTH, ld.dayOfMonth)
22+
return cal.time
23+
}
24+
1725
fun convertRemoteMessageToPam(remoteMessage: RemoteMessage, context: Context): NotificationItem?{
1826
//remoteMessage.notification
1927
return when(remoteMessage.data.containsKey("pam")){
@@ -33,8 +41,10 @@ class PAMUtils {
3341
else-> DateUtils.localDateTimeFromString(pamObj.getString("created_date"))
3442
}
3543

44+
val date = convertToJavaDate(createdDate)
45+
3646
NotificationItem(
37-
createdDate,
47+
date,
3848
null,
3949
remoteMessage.notification?.body,
4050
pamObj.getString("flex"),
@@ -60,7 +70,7 @@ class PAMUtils {
6070
val title = intent.extras?.getString("title")
6171
val message = intent.extras?.getString("message")
6272

63-
val pam = intent.extras?.getString("pam")
73+
val pam = intent.extras?.getString("pam") ?: "{}"
6474
val pamObj = JSONObject(pam)
6575

6676
val payload = mutableMapOf<String, Any>()
@@ -76,7 +86,7 @@ class PAMUtils {
7686
}
7787

7888
NotificationItem(
79-
createdDate,
89+
convertToJavaDate(createdDate),
8090
null,
8191
message,
8292
pamObj.getString("flex"),

0 commit comments

Comments
 (0)