Skip to content

Commit d34e1bd

Browse files
committed
Merge branch 'release/1.4.11'
2 parents e1bd7b5 + 7a7ced5 commit d34e1bd

File tree

5 files changed

+95
-27
lines changed

5 files changed

+95
-27
lines changed

pam-android-kotlin/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ android {
3535
}
3636

3737
dependencies {
38-
implementation 'androidx.core:core-ktx:1.7.0'
39-
implementation 'androidx.appcompat:appcompat:1.4.1'
40-
implementation 'com.google.android.material:material:1.5.0'
38+
implementation 'androidx.core:core-ktx:1.8.0'
39+
implementation 'androidx.appcompat:appcompat:1.4.2'
40+
implementation 'com.google.android.material:material:1.6.1'
4141
testImplementation 'junit:junit:4.13.2'
4242
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
4343
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
44-
implementation "org.jetbrains.kotlin:kotlin-reflect:1.6.10"
45-
implementation 'com.google.firebase:firebase-messaging-ktx:23.0.2'
44+
implementation "org.jetbrains.kotlin:kotlin-reflect:1.7.0"
45+
implementation 'com.google.firebase:firebase-messaging-ktx:23.0.6'
4646
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-native-mt'
4747
implementation 'com.google.code.gson:gson:2.9.0'
4848
implementation ('com.github.mrmike:ok2curl:0.7.0'){
@@ -52,4 +52,5 @@ dependencies {
5252
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.5'
5353
implementation 'com.github.bumptech.glide:glide:4.13.0'
5454
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
55+
implementation 'com.jakewharton.threetenabp:threetenabp:1.2.3'
5556
}

pam-android-kotlin/src/main/java/ai/pams/android/kotlin/flex/parser/PContainer.kt

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

33
import android.view.View
4-
import android.widget.LinearLayout
54

65
class PContainer: PView() {
76

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
package ai.pams.android.kotlin.models.notification
22

3+
import ai.pams.android.kotlin.utils.DateUtils
34
import android.content.Context
4-
import android.os.Build
5-
import androidx.annotation.RequiresApi
65
import org.json.JSONObject
7-
import java.text.ParseException
8-
import java.text.SimpleDateFormat
9-
import java.time.LocalDateTime
10-
import java.util.*
116

127
class NotificationList(
138
var items: List<NotificationItem>? = null
149
){
1510
companion object{
1611

17-
private fun stringToDate(dateString: String): Date? {
18-
val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
19-
try {
20-
return format.parse(dateString)
21-
} catch (e: ParseException) {
22-
e.printStackTrace()
23-
}
24-
return null
25-
}
26-
2712
fun parse(jsonString: String?, context: Context): NotificationList{
2813
if(jsonString == null){
2914
val noti = NotificationList()
@@ -55,7 +40,7 @@ class NotificationList(
5540
}
5641

5742
val item = NotificationItem(
58-
date = stringToDate(createdDate),
43+
date = DateUtils.localDateTimeFromString(createdDate),
5944
deliverId = jsonItem.optString("deliver_id"),
6045
description = jsonItem.optString("description"),
6146
flex = jsonItem.optString("flex"),

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import ai.pams.android.kotlin.flex.parser.FlexParser
55
import ai.pams.android.kotlin.flex.parser.PImage
66
import ai.pams.android.kotlin.http.Http
77
import android.content.Context
8-
import com.google.gson.annotations.SerializedName
9-
import java.util.*
8+
import org.threeten.bp.LocalDateTime
109

1110
data class NotificationItem(
12-
var date: Date? = null,
11+
var date: LocalDateTime? = null,
1312
val deliverId: String? = null,
1413
val description: String? = null,
1514
val flex: String? = null,
@@ -24,7 +23,7 @@ data class NotificationItem(
2423
var bannerUrl: String? = null
2524

2625
@Deprecated("createdDate is deprecated use date instead.", ReplaceWith("date"))
27-
val createdDate: Date?
26+
val createdDate: LocalDateTime?
2827
get() = date
2928

3029
fun parseFlex(context: Context) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package ai.pams.android.kotlin.utils
2+
3+
import android.annotation.SuppressLint
4+
import org.threeten.bp.*
5+
import org.threeten.bp.format.DateTimeFormatter
6+
7+
class DateUtils {
8+
companion object {
9+
10+
fun getDateFormat() = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
11+
12+
fun hourFromGMT(): Int {
13+
val now = LocalDateTime.now()
14+
val zone = ZoneId.of("GMT0")
15+
val zoneOffSet = zone.rules.getOffset(now)
16+
return zoneOffSet.totalSeconds / 3600
17+
}
18+
19+
fun now(): LocalDateTime {
20+
return LocalDateTime.now()
21+
}
22+
23+
fun localDateTimeFromString(dateString: String): LocalDateTime {
24+
val zdt = ZonedDateTime.parse(dateString, getDateFormat())
25+
val localZdt = zdt.withZoneSameInstant(ZoneId.systemDefault())
26+
return localZdt.toLocalDateTime()
27+
}
28+
29+
fun toDateStringForUI(date: LocalDate): String {
30+
val formatter = DateTimeFormatter.ofPattern("d MMM yyyy")
31+
return formatter.format(date)
32+
}
33+
34+
fun toDateStringForUI(dateTime: LocalDateTime): String {
35+
val formatter = DateTimeFormatter.ofPattern("d MMM yyyy HH:mm")
36+
return formatter.format(dateTime)
37+
}
38+
39+
fun toOnlyTimeStringForUI(date: LocalDateTime): String {
40+
val formatter = DateTimeFormatter.ofPattern("HH:mm")
41+
return formatter.format(date)
42+
}
43+
44+
@SuppressLint("SimpleDateFormat")
45+
fun timeStampToTimeString(timeStamp: Long, pattern: String): String {
46+
val sdf = java.text.SimpleDateFormat(pattern)
47+
val date = java.util.Date(timeStamp)
48+
49+
return sdf.format(date)
50+
}
51+
52+
fun localDateToServerFormat(date: LocalDate): String {
53+
val zdt = ZonedDateTime.of(date, LocalTime.MIDNIGHT, ZoneId.of("GMT0"))
54+
val formatter = getDateFormat()
55+
return formatter.format(zdt)
56+
}
57+
58+
fun convertGMT0StringToLocalDateTime(dateTimeString: String?): LocalDateTime? {
59+
if (dateTimeString == null || dateTimeString == "") {
60+
return null
61+
}
62+
63+
val format = getDateFormat()
64+
val dt = LocalDateTime.parse(dateTimeString, format)
65+
val zdt = ZonedDateTime.of(dt, ZoneId.of("GMT0"))
66+
67+
val systemZoneDateTime = zdt.withZoneSameInstant(ZoneId.systemDefault())
68+
69+
return systemZoneDateTime.toLocalDateTime()
70+
}
71+
72+
fun getGMT0TimeStamp(): String {
73+
val zdt = ZonedDateTime.now(ZoneId.systemDefault())
74+
val formatter = getDateFormat()
75+
return formatter.format(zdt)
76+
}
77+
78+
private fun set2Digit(m: Int) = if (m <= 9) {
79+
"0$m"
80+
} else {
81+
"$m"
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)