Merge branch 'master' of https://git.warp.ly/open-source/warply_sdk_framework
Showing
8 changed files
with
89 additions
and
3 deletions
No preview for this file type
1 | +{ | ||
2 | + "images" : [ | ||
3 | + { | ||
4 | + "filename" : "ic_wallet.png", | ||
5 | + "idiom" : "universal", | ||
6 | + "scale" : "1x" | ||
7 | + }, | ||
8 | + { | ||
9 | + "filename" : "ic_wallet-1.png", | ||
10 | + "idiom" : "universal", | ||
11 | + "scale" : "2x" | ||
12 | + }, | ||
13 | + { | ||
14 | + "filename" : "ic_wallet-2.png", | ||
15 | + "idiom" : "universal", | ||
16 | + "scale" : "3x" | ||
17 | + } | ||
18 | + ], | ||
19 | + "info" : { | ||
20 | + "author" : "xcode", | ||
21 | + "version" : 1 | ||
22 | + } | ||
23 | +} |
3.34 KB
3.34 KB
3.34 KB
No preview for this file type
... | @@ -14,6 +14,34 @@ import UIKit | ... | @@ -14,6 +14,34 @@ import UIKit |
14 | // import AVFoundation | 14 | // import AVFoundation |
15 | 15 | ||
16 | 16 | ||
17 | + | ||
18 | +extension String { | ||
19 | + | ||
20 | + var length: Int { | ||
21 | + return count | ||
22 | + } | ||
23 | + | ||
24 | + subscript (i: Int) -> String { | ||
25 | + return self[i ..< i + 1] | ||
26 | + } | ||
27 | + | ||
28 | + func substring(fromIndex: Int) -> String { | ||
29 | + return self[min(fromIndex, length) ..< length] | ||
30 | + } | ||
31 | + | ||
32 | + func substring(toIndex: Int) -> String { | ||
33 | + return self[0 ..< max(0, toIndex)] | ||
34 | + } | ||
35 | + | ||
36 | + subscript (r: Range<Int>) -> String { | ||
37 | + let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)), | ||
38 | + upper: min(length, max(0, r.upperBound)))) | ||
39 | + let start = index(startIndex, offsetBy: range.lowerBound) | ||
40 | + let end = index(start, offsetBy: range.upperBound - range.lowerBound) | ||
41 | + return String(self[start ..< end]) | ||
42 | + } | ||
43 | +} | ||
44 | + | ||
17 | extension CouponBarcodeView { | 45 | extension CouponBarcodeView { |
18 | struct headerView: View { | 46 | struct headerView: View { |
19 | var goBack: () -> () | 47 | var goBack: () -> () |
... | @@ -94,6 +122,41 @@ extension CouponBarcodeView { | ... | @@ -94,6 +122,41 @@ extension CouponBarcodeView { |
94 | 122 | ||
95 | return nil | 123 | return nil |
96 | } | 124 | } |
125 | + | ||
126 | + | ||
127 | + func constructBarcode() -> String? { | ||
128 | + // EAN 13 barcode construction | ||
129 | + let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""] | ||
130 | + let couponString = couponData["coupon"] as? String ?? "" | ||
131 | + | ||
132 | + if (!couponString.isEmpty) { | ||
133 | + var checkDigit = 0; | ||
134 | + var result = 0; | ||
135 | + | ||
136 | + var fixedCouponCode = couponString; | ||
137 | + if (fixedCouponCode.count < 12) { | ||
138 | + let loops = 12 - fixedCouponCode.count; | ||
139 | + var zerosStr = ""; | ||
140 | + for i in 0 ..< loops { | ||
141 | + zerosStr += "0" | ||
142 | + } | ||
143 | + fixedCouponCode = zerosStr + fixedCouponCode; | ||
144 | + } | ||
145 | + | ||
146 | + var multiplier = 3; | ||
147 | + for idx in (0 ... (fixedCouponCode.count - 1)).reversed() { | ||
148 | + let curChar = fixedCouponCode[idx]; | ||
149 | + result += (Int(curChar) ?? 0) * multiplier; | ||
150 | + multiplier = multiplier == 3 ? 1 : 3; | ||
151 | + } | ||
152 | + checkDigit = 10 - (result % 10); | ||
153 | + | ||
154 | + let barcodeStr = fixedCouponCode + String(checkDigit); | ||
155 | + return barcodeStr; | ||
156 | + } | ||
157 | + | ||
158 | + return "" | ||
159 | + } | ||
97 | 160 | ||
98 | 161 | ||
99 | var body: some View { | 162 | var body: some View { |
... | @@ -197,7 +260,7 @@ extension CouponBarcodeView { | ... | @@ -197,7 +260,7 @@ extension CouponBarcodeView { |
197 | // .aspectRatio(contentMode: .fit) | 260 | // .aspectRatio(contentMode: .fit) |
198 | // .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1) | 261 | // .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1) |
199 | 262 | ||
200 | - Text(couponData["coupon"] as? String ?? "") | 263 | + Text(constructBarcode() ?? "") |
201 | .fontWeight(.regular) | 264 | .fontWeight(.regular) |
202 | .font(.system(size: 22)) | 265 | .font(.system(size: 22)) |
203 | .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | 266 | .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ... | ... |
... | @@ -519,7 +519,7 @@ extension GiftsView { | ... | @@ -519,7 +519,7 @@ extension GiftsView { |
519 | .frame(width: 1) | 519 | .frame(width: 1) |
520 | .padding(.leading, 10) | 520 | .padding(.leading, 10) |
521 | 521 | ||
522 | - VStack(alignment: .leading) { | 522 | + VStack(alignment: .leading, spacing: 8.0) { |
523 | Text(item.name ?? "") | 523 | Text(item.name ?? "") |
524 | .fontWeight(.medium) | 524 | .fontWeight(.medium) |
525 | .font(.system(size: 16)) | 525 | .font(.system(size: 16)) |
... | @@ -548,7 +548,7 @@ extension GiftsView { | ... | @@ -548,7 +548,7 @@ extension GiftsView { |
548 | // .padding(.leading, 10) | 548 | // .padding(.leading, 10) |
549 | } | 549 | } |
550 | // .padding(.vertical, 5) | 550 | // .padding(.vertical, 5) |
551 | - .frame(maxHeight: .infinity) | 551 | + // .frame(maxHeight: .infinity) |
552 | 552 | ||
553 | Text("Ισχύει έως "+(item.expiration ?? "")) | 553 | Text("Ισχύει έως "+(item.expiration ?? "")) |
554 | .fontWeight(.medium) | 554 | .fontWeight(.medium) | ... | ... |
-
Please register or login to post a comment