Skip to content

Commit 2a3f555

Browse files
committed
- Fixes of Redmine-14014 (Issue, Letter)
- Fixed "func update()" on Order SSEC
1 parent 9dfb587 commit 2a3f555

File tree

6 files changed

+45
-31
lines changed

6 files changed

+45
-31
lines changed

app/src/main/java/com/sendsay/example/view/fragments/TrackFragment.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ class TrackFragment : BaseFragment(), AdapterView.OnItemClickListener {
166166

167167
private fun trackClearBasket() {
168168
// Получение текущего времени с использованием SimpleDateFormat
169-
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US)
170-
val currentDateTime = dateFormat.format(Date())
169+
// val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US)
170+
// val currentDateTime = dateFormat.format(Date())
171171

172172
val data = TrackSSEC
173173
.basketClear()
174-
.dateTime(dt = currentDateTime)
174+
// .dateTime(dt = currentDateTime)
175175
.items(listOf(OrderItem(id = "-1")))
176176
.buildData()
177177

app/src/main/res/layout/dialog_track_custom_event.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
android:layout_height="wrap_content"
1414
android:layout_marginStart="16dp"
1515
android:layout_marginTop="16dp"
16-
android:text="Track Custom Event"
16+
android:text="Track Custom Event (CCE)"
1717
android:textSize="20sp"
1818
android:textStyle="bold"
1919
app:layout_constraintStart_toStartOf="parent"

app/src/main/res/layout/fragment_track.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
android:layout_height="wrap_content"
219219
android:layout_marginEnd="16dp"
220220
android:layout_marginStart="8dp"
221-
android:text="Custom Event"
221+
android:text="Custom Event (cce)"
222222
android:theme="@style/AppButton"
223223
app:layout_constraintBottom_toBottomOf="@+id/buttonUpdateProperties"
224224
app:layout_constraintEnd_toEndOf="parent"

sdk/src/main/java/com/sendsay/sdk/models/NotificationPayload.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class NotificationPayload(val rawData: HashMap<String, String>) {
1717
val buttons: ArrayList<ActionPayload>? = parseActions(rawData["actions"])
1818
val notificationAction: ActionPayload = parseMainAction(rawData["action"], rawData["url"])
1919
val notificationData: NotificationData = parseNotificationData(rawData)
20-
val attributes: Map<String, Any>? = parseAttributes(rawData["attributes"])
20+
val attributes: Map<String, Any>? = parseAttributes(rawData["data"] ?: rawData["attributes"])
2121
var deliveredTimestamp: Double? = notificationData.sentTimestamp
2222

2323
data class ActionPayload(

sdk/src/main/java/com/sendsay/sdk/models/TrackSSECBuilders.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.sendsay.sdk.models
22

33
import com.sendsay.sdk.preferences.SendsayPreferencesImpl
4+
import com.sendsay.sdk.repository.PushNotificationRepositoryImpl
45
import com.sendsay.sdk.repository.PushNotificationRepositoryImpl.Companion.KEY_ISSUE
6+
import com.sendsay.sdk.repository.PushNotificationRepositoryImpl.Companion.KEY_ISSUE_LETTER_DATETIME_DATA_UTC
7+
import com.sendsay.sdk.repository.PushNotificationRepositoryImpl.Companion.KEY_LETTER
58
import com.sendsay.sdk.services.SendsayContextProvider
69

710
// Типо-безопасные билдеры-обёртки вокруг существующего TrackSSECDataCore
@@ -43,8 +46,8 @@ class ViewProductBuilder internal constructor(
4346
}
4447

4548
// fun email(value: String) = apply { core.setEmail(value) }
46-
fun update(isUpdate: Boolean? = null, isUpdatePerItem: Boolean? = null) = apply {
47-
core.setUpdate(isUpdate, isUpdatePerItem)
49+
fun update(isUpdate: Boolean? = null,) = apply {
50+
core.setUpdate(isUpdate)
4851
}
4952

5053
// override fun cp(map: Map<String, Any>) = apply { core.setCp(map) }
@@ -69,8 +72,8 @@ class OrderBuilder internal constructor(
6972
core.setTransaction(id = id, dt = dt, sum = sum, discount = discount, status = status)
7073
}
7174

72-
fun update(isUpdate: Boolean? = null, isUpdatePerItem: Boolean? = null) = apply {
73-
core.setUpdate(isUpdate, isUpdatePerItem)
75+
fun update(isUpdate: Boolean? = null) = apply {
76+
core.setUpdate(isUpdate)
7477
}
7578

7679
fun delivery(dt: String, price: Double? = null) = apply { core.setDelivery(dt, price) }
@@ -88,7 +91,11 @@ class OrderBuilder internal constructor(
8891
core.setProduct(id = id, name = name, price = price)
8992
}
9093

91-
// override fun cp(map: Map<String, Any>) = apply { core.setCp(map) }
94+
fun update(isUpdate: Boolean? = null, isUpdatePerItem: Boolean? = null) = apply {
95+
core.setUpdate(isUpdate, isUpdatePerItem)
96+
}
97+
98+
// override fun cp(map: Map<String, Any>) = apply { core.setCp(map) }
9299
override fun buildData(): TrackSSECData = core.build()
93100
override fun buildProperties(): HashMap<String, Any> =
94101
core.build().toProperties(TrackingSSECType.ORDER)
@@ -435,11 +442,12 @@ internal class TrackSSECDataCore(private val type: TrackingSSECType) {
435442
val formattedPaymentDt = paymentDt
436443

437444
// Передача данных о выпуске CDP Sendsay (Redmine 14014)
438-
val prefs = SendsayPreferencesImpl(SendsayContextProvider.applicationContext!!)
445+
val prefs =
446+
PushNotificationRepositoryImpl(SendsayPreferencesImpl(SendsayContextProvider.applicationContext!!)).getExtraData() as HashMap<String, Any>
439447
setIssueLetter(
440-
issue = prefs.getLong(key = KEY_ISSUE, default = 0L).toInt(),
441-
letter = prefs.getLong(key = KEY_ISSUE, default = 0L).toInt(),
442-
issueDt = prefs.getString(key = KEY_ISSUE, default = "")
448+
issue = (prefs.entries.find { it.key == KEY_ISSUE }?.value as String).toIntOrNull() ?: -1,
449+
letter = (prefs.entries.find { it.key == KEY_LETTER }?.value as String).toIntOrNull() ?: -1,
450+
// issueDt = prefs.entries.find { it.key == KEY_ISSUE_LETTER_DATETIME_DATA_UTC }?.value as String
443451
)
444452

445453
return TrackSSECData(

sdk/src/main/java/com/sendsay/sdk/repository/PushNotificationRepositoryImpl.kt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import com.sendsay.sdk.models.PushOpenedData
66
import com.sendsay.sdk.preferences.SendsayPreferences
77
import com.sendsay.sdk.util.Logger
88
import com.sendsay.sdk.util.fromJson
9-
import kotlin.time.Duration.Companion.minutes
9+
import kotlin.time.Clock
10+
import kotlin.time.Duration.Companion.hours
1011
import kotlin.time.DurationUnit
12+
import kotlin.time.ExperimentalTime
1113

1214
internal class PushNotificationRepositoryImpl(
1315
private val preferences: SendsayPreferences
1416
) : PushNotificationRepository {
1517
companion object {
16-
// private val ISSUE_LETTER_EXPIRE_DURATION: Long = 48.hours.toLong(DurationUnit.MILLISECONDS)
17-
val ISSUE_LETTER_EXPIRE_DURATION: Long = 15.minutes.toLong(DurationUnit.MILLISECONDS)
18+
private val ISSUE_LETTER_EXPIRE_DURATION: Long = 48.hours.toLong(DurationUnit.MILLISECONDS)
19+
// val ISSUE_LETTER_EXPIRE_DURATION: Long = 15.minutes.toLong(DurationUnit.MILLISECONDS)
1820

19-
val KEY_ISSUE_LETTER_DATETIME_DATA = "SendsayIssueLetterDateTimeData"
21+
val KEY_ISSUE_LETTER_DATETIME_DATA_UTC = "sendsay_issue_letter_datetime"
2022
val KEY_ISSUE = "sendsay_issue_id"
2123
val KEY_LETTER = "sendsay_letter_id"
2224
}
@@ -30,38 +32,42 @@ internal class PushNotificationRepositoryImpl(
3032
if (dataString.isEmpty()) {
3133
return null
3234
}
33-
val mapData = Gson().fromJson<HashMap<String, Any>>(dataString)
34-
checkIssueAndLetterOnExpire(mapData)
35+
var mapData = Gson().fromJson<HashMap<String, Any>>(dataString)
36+
mapData = checkIssueAndLetterOnExpire(mapData)
3537
return mapData
3638
}
3739

38-
private fun checkIssueAndLetterOnExpire(data: Map<String, Any>) {
39-
val now = Calendar.getInstance().timeInMillis
40+
@OptIn(ExperimentalTime::class)
41+
private fun checkIssueAndLetterOnExpire(data: HashMap<String, Any>) : HashMap<String, Any> {
42+
val now = Clock.System.now().toEpochMilliseconds()
4043
val lastIssueLetterDateTime: Long =
41-
(data.entries.firstOrNull { it.key == KEY_ISSUE_LETTER_DATETIME_DATA }
42-
?.value as? Long ?: now)
44+
((data.entries.firstOrNull { it.key == KEY_ISSUE_LETTER_DATETIME_DATA_UTC }
45+
?.value as? String)?.toLong() ?: now)
4346
if ((now - lastIssueLetterDateTime)
4447
>= ISSUE_LETTER_EXPIRE_DURATION
4548
) {
4649
val mutableMap = data.toMutableMap()
47-
mutableMap.remove(KEY_ISSUE_LETTER_DATETIME_DATA)
50+
mutableMap.remove(KEY_ISSUE_LETTER_DATETIME_DATA_UTC)
4851
mutableMap.remove(KEY_ISSUE)
4952
mutableMap.remove(KEY_LETTER)
5053
setExtraData(mutableMap)
54+
return mutableMap as HashMap
5155
}
56+
return data
5257
}
5358

5459
override fun setExtraData(data: Map<String, Any>) {
55-
setLastDateTimeOnIssueAndLetter(data)
56-
val dataString = Gson().toJson(data)
60+
val newData = setLastDateTimeOnIssueAndLetter(data)
61+
val dataString = Gson().toJson(newData)
5762
preferences.setString(KEY_EXTRA_DATA, dataString)
5863
}
5964

60-
private fun setLastDateTimeOnIssueAndLetter(data: Map<String, Any>) {
65+
private fun setLastDateTimeOnIssueAndLetter(data: Map<String, Any>): Map<String, Any> {
6166
if (data.entries.any { it.key == KEY_ISSUE || it.key == KEY_LETTER }) {
62-
val currentDateTime = Calendar.getInstance().timeInMillis
63-
data.entries.plus(KEY_ISSUE_LETTER_DATETIME_DATA to currentDateTime)
67+
val currentDateTime = Calendar.getInstance().timeInMillis.toString()
68+
return data.plus(KEY_ISSUE_LETTER_DATETIME_DATA_UTC to currentDateTime)
6469
}
70+
return data
6571
}
6672

6773
override fun appendDeliveredNotification(data: Map<String, String>) {

0 commit comments

Comments
 (0)