Skip to content

Commit a12893d

Browse files
committed
Add simpler verification
1 parent 4883fd4 commit a12893d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

core/src/main/java/io/snabble/sdk/Coupons.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ data class Coupon (
2727
val image: CouponImage?,
2828
val disclaimer: String?,
2929
val colors: Map<String, String>?,
30-
) : Parcelable
30+
) : Parcelable {
31+
val isValid: Boolean
32+
get() = when(type) {
33+
CouponType.DIGITAL -> image != null && validFrom != null && validUntil != null
34+
CouponType.MANUAL -> name != null
35+
CouponType.PRINTED -> true
36+
}
37+
}
3138

3239
@Parcelize
3340
data class CouponCode (
@@ -118,9 +125,8 @@ class Coupons (
118125
if (response.isSuccessful) {
119126
val localizedResponse = GsonBuilder().create()
120127
.fromJson(response.body?.string(), CouponResponse::class.java)
121-
postValue(localizedResponse.coupons.filterNot {
122-
// filter invalid
123-
it.type == CouponType.DIGITAL && (it.image == null || it.validFrom == null || it.validUntil == null)
128+
postValue(localizedResponse.coupons.filter { coupon ->
129+
coupon.isValid
124130
})
125131
source.postValue(CouponSource.Online)
126132
}

0 commit comments

Comments
 (0)