Skip to content

Commit 9fc9a24

Browse files
committed
UPS: fix crashes when ETA is null
1 parent a557ab7 commit 9fc9a24

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

app/src/main/java/dev/itsvic/parceltracker/api/UPSDeliveryService.kt

+30-26
Original file line numberDiff line numberDiff line change
@@ -87,37 +87,41 @@ object UPSDeliveryService : DeliveryService {
8787
else -> logUnknownStatus("UPS", details.progressBarType)
8888
}
8989

90+
val metadata = mutableMapOf(
91+
R.string.property_weight to "${details.additionalInformation.weight} ${details.additionalInformation.weightUnit}",
92+
)
93+
9094
// ETA
91-
val month = when (details.scheduledDeliveryDateDetail.monthCMSKey) {
92-
"cms.stapp.jan" -> 1
93-
"cms.stapp.feb" -> 2
94-
"cms.stapp.mar" -> 3
95-
"cms.stapp.apr" -> 4
96-
"cms.stapp.may" -> 5
97-
"cms.stapp.jun" -> 6
98-
"cms.stapp.jul" -> 7
99-
"cms.stapp.aug" -> 8
100-
"cms.stapp.sep" -> 9
101-
"cms.stapp.oct" -> 10
102-
"cms.stapp.nov" -> 11
103-
"cms.stapp.dec" -> 12
104-
else -> 0
95+
if (details.scheduledDeliveryDateDetail != null && details.packageStatusTime != null) {
96+
val month = when (details.scheduledDeliveryDateDetail.monthCMSKey) {
97+
"cms.stapp.jan" -> 1
98+
"cms.stapp.feb" -> 2
99+
"cms.stapp.mar" -> 3
100+
"cms.stapp.apr" -> 4
101+
"cms.stapp.may" -> 5
102+
"cms.stapp.jun" -> 6
103+
"cms.stapp.jul" -> 7
104+
"cms.stapp.aug" -> 8
105+
"cms.stapp.sep" -> 9
106+
"cms.stapp.oct" -> 10
107+
"cms.stapp.nov" -> 11
108+
"cms.stapp.dec" -> 12
109+
else -> 0
110+
}
111+
val day = details.scheduledDeliveryDateDetail.dayNum.toInt()
112+
val date = LocalDate.now().withMonth(month).withDayOfMonth(day)
113+
val eta = (date?.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL))
114+
+ "\n"
115+
// cleanup A.M., P.M. -> AM, PM
116+
+ details.packageStatusTime.replace(".M.", "M"))
117+
metadata[R.string.property_eta] = eta
105118
}
106-
val day = details.scheduledDeliveryDateDetail.dayNum.toInt()
107-
val date = LocalDate.now().withMonth(month).withDayOfMonth(day)
108-
val eta = (date.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL))
109-
+ "\n"
110-
// cleanup A.M., P.M. -> AM, PM
111-
+ details.packageStatusTime.replace(".M.", "M"))
112119

113120
return Parcel(
114121
trackingId,
115122
history,
116123
status,
117-
mapOf(
118-
R.string.property_weight to "${details.additionalInformation.weight} ${details.additionalInformation.weightUnit}",
119-
R.string.property_eta to eta,
120-
)
124+
metadata
121125
)
122126
}
123127

@@ -168,8 +172,8 @@ object UPSDeliveryService : DeliveryService {
168172
val progressBarType: String,
169173
val additionalInformation: PkgMoreInfo,
170174
val shipmentProgressActivities: List<ActivityEntry>,
171-
val scheduledDeliveryDateDetail: DeliveryDateDetail,
172-
val packageStatusTime: String,
175+
val scheduledDeliveryDateDetail: DeliveryDateDetail?,
176+
val packageStatusTime: String?,
173177
)
174178

175179
@JsonClass(generateAdapter = true)

0 commit comments

Comments
 (0)