Vasilis
{
"images" : [
{
"filename" : "ic_wallet.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_wallet-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_wallet-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -14,6 +14,34 @@ import UIKit
// import AVFoundation
extension String {
var length: Int {
return count
}
subscript (i: Int) -> String {
return self[i ..< i + 1]
}
func substring(fromIndex: Int) -> String {
return self[min(fromIndex, length) ..< length]
}
func substring(toIndex: Int) -> String {
return self[0 ..< max(0, toIndex)]
}
subscript (r: Range<Int>) -> String {
let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)),
upper: min(length, max(0, r.upperBound))))
let start = index(startIndex, offsetBy: range.lowerBound)
let end = index(start, offsetBy: range.upperBound - range.lowerBound)
return String(self[start ..< end])
}
}
extension CouponBarcodeView {
struct headerView: View {
var goBack: () -> ()
......@@ -96,6 +124,41 @@ extension CouponBarcodeView {
}
func constructBarcode() -> String? {
// EAN 13 barcode construction
let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
let couponString = couponData["coupon"] as? String ?? ""
if (!couponString.isEmpty) {
var checkDigit = 0;
var result = 0;
var fixedCouponCode = couponString;
if (fixedCouponCode.count < 12) {
let loops = 12 - fixedCouponCode.count;
var zerosStr = "";
for i in 0 ..< loops {
zerosStr += "0"
}
fixedCouponCode = zerosStr + fixedCouponCode;
}
var multiplier = 3;
for idx in (0 ... (fixedCouponCode.count - 1)).reversed() {
let curChar = fixedCouponCode[idx];
result += (Int(curChar) ?? 0) * multiplier;
multiplier = multiplier == 3 ? 1 : 3;
}
checkDigit = 10 - (result % 10);
let barcodeStr = fixedCouponCode + String(checkDigit);
return barcodeStr;
}
return ""
}
var body: some View {
let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
......@@ -197,7 +260,7 @@ extension CouponBarcodeView {
// .aspectRatio(contentMode: .fit)
// .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1)
Text(couponData["coupon"] as? String ?? "")
Text(constructBarcode() ?? "")
.fontWeight(.regular)
.font(.system(size: 22))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
......
......@@ -519,7 +519,7 @@ extension GiftsView {
.frame(width: 1)
.padding(.leading, 10)
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 8.0) {
Text(item.name ?? "")
.fontWeight(.medium)
.font(.system(size: 16))
......@@ -548,7 +548,7 @@ extension GiftsView {
// .padding(.leading, 10)
}
// .padding(.vertical, 5)
.frame(maxHeight: .infinity)
// .frame(maxHeight: .infinity)
Text("Ισχύει έως "+(item.expiration ?? ""))
.fontWeight(.medium)
......