File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
core/src/main/java/io/snabble/sdk Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff 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
3340data 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 }
You can’t perform that action at this time.
0 commit comments