Showing
9 changed files
with
194 additions
and
4 deletions
| ... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
| 7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
| 8 | <dict> | 8 | <dict> |
| 9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
| 10 | - <integer>1</integer> | 10 | + <integer>0</integer> |
| 11 | </dict> | 11 | </dict> |
| 12 | </dict> | 12 | </dict> |
| 13 | </dict> | 13 | </dict> | ... | ... |
| ... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
| 7 | objects = { | 7 | objects = { |
| 8 | 8 | ||
| 9 | /* Begin PBXBuildFile section */ | 9 | /* Begin PBXBuildFile section */ |
| 10 | + 1E74838D28378AF40042A589 /* CouponBarcodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E74838C28378AF40042A589 /* CouponBarcodeViewController.swift */; }; | ||
| 10 | 1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */; }; | 11 | 1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */; }; |
| 11 | 7630AD9A6242D60846D6750C /* Pods_SwiftWarplyFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */; }; | 12 | 7630AD9A6242D60846D6750C /* Pods_SwiftWarplyFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */; }; |
| 12 | E6A77853282933340045BBA8 /* SwiftWarplyFramework.docc in Sources */ = {isa = PBXBuildFile; fileRef = E6A77852282933340045BBA8 /* SwiftWarplyFramework.docc */; }; | 13 | E6A77853282933340045BBA8 /* SwiftWarplyFramework.docc in Sources */ = {isa = PBXBuildFile; fileRef = E6A77852282933340045BBA8 /* SwiftWarplyFramework.docc */; }; |
| ... | @@ -138,6 +139,7 @@ | ... | @@ -138,6 +139,7 @@ |
| 138 | /* End PBXBuildFile section */ | 139 | /* End PBXBuildFile section */ |
| 139 | 140 | ||
| 140 | /* Begin PBXFileReference section */ | 141 | /* Begin PBXFileReference section */ |
| 142 | + 1E74838C28378AF40042A589 /* CouponBarcodeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponBarcodeViewController.swift; sourceTree = "<group>"; }; | ||
| 141 | 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponsTableViewCell.swift; sourceTree = "<group>"; }; | 143 | 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponsTableViewCell.swift; sourceTree = "<group>"; }; |
| 142 | A9B7BE01A4E812DE49866EF8 /* Pods-SwiftWarplyFramework.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftWarplyFramework.debug.xcconfig"; path = "Target Support Files/Pods-SwiftWarplyFramework/Pods-SwiftWarplyFramework.debug.xcconfig"; sourceTree = "<group>"; }; | 144 | A9B7BE01A4E812DE49866EF8 /* Pods-SwiftWarplyFramework.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftWarplyFramework.debug.xcconfig"; path = "Target Support Files/Pods-SwiftWarplyFramework/Pods-SwiftWarplyFramework.debug.xcconfig"; sourceTree = "<group>"; }; |
| 143 | B9EB8A451EF0C5AD75094EEE /* Pods-SwiftWarplyFramework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftWarplyFramework.release.xcconfig"; path = "Target Support Files/Pods-SwiftWarplyFramework/Pods-SwiftWarplyFramework.release.xcconfig"; sourceTree = "<group>"; }; | 145 | B9EB8A451EF0C5AD75094EEE /* Pods-SwiftWarplyFramework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftWarplyFramework.release.xcconfig"; path = "Target Support Files/Pods-SwiftWarplyFramework/Pods-SwiftWarplyFramework.release.xcconfig"; sourceTree = "<group>"; }; |
| ... | @@ -324,6 +326,7 @@ | ... | @@ -324,6 +326,7 @@ |
| 324 | E6A7785E282933E40045BBA8 /* CouponsViewController.swift */, | 326 | E6A7785E282933E40045BBA8 /* CouponsViewController.swift */, |
| 325 | 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */, | 327 | 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */, |
| 326 | E6A7785D282933E40045BBA8 /* CouponViewController.swift */, | 328 | E6A7785D282933E40045BBA8 /* CouponViewController.swift */, |
| 329 | + 1E74838C28378AF40042A589 /* CouponBarcodeViewController.swift */, | ||
| 327 | E6A77863282933E50045BBA8 /* DetailsViewController.swift */, | 330 | E6A77863282933E50045BBA8 /* DetailsViewController.swift */, |
| 328 | E6A778DE282933E60045BBA8 /* GiftsViewController.swift */, | 331 | E6A778DE282933E60045BBA8 /* GiftsViewController.swift */, |
| 329 | E6A778DB282933E60045BBA8 /* MFYViewController.swift */, | 332 | E6A778DB282933E60045BBA8 /* MFYViewController.swift */, |
| ... | @@ -729,6 +732,7 @@ | ... | @@ -729,6 +732,7 @@ |
| 729 | E6A7791E282933E60045BBA8 /* WLSMSActionHanlder.m in Sources */, | 732 | E6A7791E282933E60045BBA8 /* WLSMSActionHanlder.m in Sources */, |
| 730 | E6A778F5282933E60045BBA8 /* WLCustomNativeAdTableViewCell.m in Sources */, | 733 | E6A778F5282933E60045BBA8 /* WLCustomNativeAdTableViewCell.m in Sources */, |
| 731 | E6A77901282933E60045BBA8 /* WLBaseItem.m in Sources */, | 734 | E6A77901282933E60045BBA8 /* WLBaseItem.m in Sources */, |
| 735 | + 1E74838D28378AF40042A589 /* CouponBarcodeViewController.swift in Sources */, | ||
| 732 | E6A778F0282933E60045BBA8 /* WLNativeAdsCollectionMode.m in Sources */, | 736 | E6A778F0282933E60045BBA8 /* WLNativeAdsCollectionMode.m in Sources */, |
| 733 | E6A7791C282933E60045BBA8 /* WLSMSActionHandlerDeprecated.m in Sources */, | 737 | E6A7791C282933E60045BBA8 /* WLSMSActionHandlerDeprecated.m in Sources */, |
| 734 | E6A77934282933E70045BBA8 /* UIActivityIndicatorView+AFNetworking.m in Sources */, | 738 | E6A77934282933E70045BBA8 /* UIActivityIndicatorView+AFNetworking.m in Sources */, | ... | ... |
| ... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
| 7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
| 8 | <dict> | 8 | <dict> |
| 9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
| 10 | - <integer>0</integer> | 10 | + <integer>1</integer> |
| 11 | </dict> | 11 | </dict> |
| 12 | </dict> | 12 | </dict> |
| 13 | </dict> | 13 | </dict> | ... | ... |
No preview for this file type
| 1 | +// | ||
| 2 | +// CouponBarcodeViewController.swift | ||
| 3 | +// SwiftWarplyFramework | ||
| 4 | +// | ||
| 5 | +// Created by Manos Chorianopoulos on 20/5/22. | ||
| 6 | +// | ||
| 7 | + | ||
| 8 | +import UIKit | ||
| 9 | +import WarplySDKFrameworkIOS | ||
| 10 | + | ||
| 11 | +@objc class CouponBarcodeViewController: UIViewController { | ||
| 12 | + @IBOutlet weak var backgroundImage: UIImageView! | ||
| 13 | + @IBOutlet weak var scrollView: UIScrollView! | ||
| 14 | + @IBOutlet weak var scrollContentView: UIView! | ||
| 15 | + @IBOutlet weak var couponImage: UIImageView! | ||
| 16 | + @IBOutlet weak var couponImageHeight: NSLayoutConstraint! | ||
| 17 | + @IBOutlet weak var nameLabel: UILabel! | ||
| 18 | + @IBOutlet weak var discriptionLabel: UILabel! | ||
| 19 | + @IBOutlet weak var couponView: UIView! | ||
| 20 | + @IBOutlet weak var couponNumberLabel: UILabel! | ||
| 21 | + @IBOutlet weak var barcodeLabel: UILabel! | ||
| 22 | + @IBOutlet weak var expirationLabel: UILabel! | ||
| 23 | + @IBOutlet weak var redeemButton: UIButton! | ||
| 24 | + @IBOutlet weak var termsButton: UIButton! | ||
| 25 | + @IBOutlet weak var termsTextView: UITextView! | ||
| 26 | + @IBOutlet weak var termsTextViewHeight: NSLayoutConstraint! | ||
| 27 | + | ||
| 28 | + let uiscreen: CGRect = UIScreen.main.bounds | ||
| 29 | + | ||
| 30 | + var termsVisible: Bool = false; | ||
| 31 | + | ||
| 32 | + var coupon: swiftApi.CouponItemModel? | ||
| 33 | + | ||
| 34 | + override func viewDidLoad() { | ||
| 35 | + super.viewDidLoad() | ||
| 36 | + | ||
| 37 | + // Do any additional setup after loading the view. | ||
| 38 | + setBackButton() | ||
| 39 | + setNavigationTitle("Εκπτωτικό κουπόνι") | ||
| 40 | + | ||
| 41 | + backgroundImage.image = UIImage(named: "coupons_scrollview_white") | ||
| 42 | + | ||
| 43 | + scrollView.clipsToBounds = true | ||
| 44 | + scrollView.layer.cornerRadius = 30 | ||
| 45 | + scrollView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius | ||
| 46 | + | ||
| 47 | + // COUPONSET: desc, img_preview, name, terms | ||
| 48 | + // COUPON: coupon, expiration, discount, status | ||
| 49 | + | ||
| 50 | + let couponSetData: swiftApi.CouponSetItemModel? = coupon?.couponset_data | ||
| 51 | + | ||
| 52 | + couponImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache()) | ||
| 53 | + couponImage.contentMode = .scaleAspectFill | ||
| 54 | + couponImageHeight.constant = self.uiscreen.height * 0.25 | ||
| 55 | + | ||
| 56 | + nameLabel.text = couponSetData?.name ?? "" | ||
| 57 | + discriptionLabel.text = couponSetData?.short_description ?? "" | ||
| 58 | + | ||
| 59 | + couponView.layer.cornerRadius = 10 | ||
| 60 | + couponNumberLabel.text = coupon?.coupon ?? "" | ||
| 61 | + | ||
| 62 | + let barcodeString = constructBarcode() ?? "" | ||
| 63 | + barcodeLabel.text = barcodeString | ||
| 64 | + | ||
| 65 | + expirationLabel.text = "Το κουπόνι ισχύει έως " + (coupon?.expiration ?? "") | ||
| 66 | + | ||
| 67 | + redeemButton.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .medium) | ||
| 68 | + | ||
| 69 | + termsButton.titleLabel?.font = .systemFont(ofSize: 15.0, weight: .semibold) | ||
| 70 | +// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5) | ||
| 71 | + | ||
| 72 | + let htmlText = couponSetData?.terms ?? "" | ||
| 73 | + termsTextView.attributedText = htmlText.htmlToAttributedString | ||
| 74 | + termsTextView.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular) | ||
| 75 | + termsTextView.textColor = UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00) | ||
| 76 | + termsTextView.textAlignment = .center | ||
| 77 | + termsTextView.isScrollEnabled = false | ||
| 78 | + | ||
| 79 | + toggleTerms() | ||
| 80 | + | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + // MARK: - Functions | ||
| 84 | + func toggleTerms() { | ||
| 85 | + if (termsVisible) { | ||
| 86 | + termsTextView.isHidden = false | ||
| 87 | + let targetSize = CGSize(width: termsTextView.frame.width, height: CGFloat(MAXFLOAT)) | ||
| 88 | + termsTextViewHeight.constant = termsTextView.sizeThatFits(targetSize).height | ||
| 89 | + | ||
| 90 | + termsButton.setImage(UIImage(named: "ic_up_dark.png"), for: .normal) | ||
| 91 | + } else { | ||
| 92 | + termsTextView.isHidden = true | ||
| 93 | + termsTextViewHeight.constant = CGFloat(0) | ||
| 94 | + | ||
| 95 | + termsButton.setImage(UIImage(named: "ic_down_dark.png"), for: .normal) | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + func constructBarcode() -> String? { | ||
| 100 | + // EAN 13 barcode construction | ||
| 101 | + let couponData = coupon?.couponset_data | ||
| 102 | + let couponString = coupon?.coupon ?? "" | ||
| 103 | + | ||
| 104 | + if (!couponString.isEmpty) { | ||
| 105 | + var checkDigit = 0; | ||
| 106 | + var result = 0; | ||
| 107 | + | ||
| 108 | + var fixedCouponCode = couponString; | ||
| 109 | + if (fixedCouponCode.count < 12) { | ||
| 110 | + let loops = 12 - fixedCouponCode.count; | ||
| 111 | + var zerosStr = ""; | ||
| 112 | + for i in 0 ..< loops { | ||
| 113 | + zerosStr += "0" | ||
| 114 | + } | ||
| 115 | + fixedCouponCode = zerosStr + fixedCouponCode; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + var multiplier = 3; | ||
| 119 | + for idx in (0 ... (fixedCouponCode.count - 1)).reversed() { | ||
| 120 | + let curChar = fixedCouponCode[idx]; | ||
| 121 | + result += (Int(curChar) ?? 0) * multiplier; | ||
| 122 | + multiplier = multiplier == 3 ? 1 : 3; | ||
| 123 | + } | ||
| 124 | + checkDigit = 10 - (result % 10); | ||
| 125 | + | ||
| 126 | + let barcodeStr = fixedCouponCode + String(checkDigit); | ||
| 127 | + return barcodeStr; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + return "" | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + // MARK: - Actions | ||
| 134 | + | ||
| 135 | + @IBAction func redeemButtomAction(_ sender: Any) { | ||
| 136 | + // TODO: Add redeem action | ||
| 137 | + | ||
| 138 | + let alert = UIAlertController(title: "Το κουπόνι σου ενεργοποιήθηκε", message: "Μπορείς να το βρεις στην αρχική οθόνη της εφαρμογής και στην ενότητα ενεργά δώρα!", preferredStyle: .alert) | ||
| 139 | + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in | ||
| 140 | + switch action.style{ | ||
| 141 | + case .default: | ||
| 142 | + print("default") | ||
| 143 | + | ||
| 144 | + case .cancel: | ||
| 145 | + print("cancel") | ||
| 146 | + | ||
| 147 | + case .destructive: | ||
| 148 | + print("destructive") | ||
| 149 | + | ||
| 150 | + } | ||
| 151 | + })) | ||
| 152 | + self.present(alert, animated: true, completion: nil) | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + @IBAction func termsButtonAction(_ sender: Any) { | ||
| 156 | + termsVisible = !termsVisible | ||
| 157 | + toggleTerms() | ||
| 158 | + } | ||
| 159 | +} |
| ... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | ||
| 8 | import UIKit | 8 | import UIKit |
| 9 | 9 | ||
| 10 | -class CouponViewController: UIViewController { | 10 | +@objc class CouponViewController: UIViewController { |
| 11 | @IBOutlet weak var mainView: UIView! | 11 | @IBOutlet weak var mainView: UIView! |
| 12 | @IBOutlet weak var backgroundImage: UIImageView! | 12 | @IBOutlet weak var backgroundImage: UIImageView! |
| 13 | @IBOutlet weak var scrollView: UIScrollView! | 13 | @IBOutlet weak var scrollView: UIScrollView! | ... | ... |
| ... | @@ -9,7 +9,7 @@ import Foundation | ... | @@ -9,7 +9,7 @@ import Foundation |
| 9 | import UIKit | 9 | import UIKit |
| 10 | import WarplySDKFrameworkIOS | 10 | import WarplySDKFrameworkIOS |
| 11 | 11 | ||
| 12 | -class CouponsTableViewCell: UITableViewCell { | 12 | +@objc class CouponsTableViewCell: UITableViewCell { |
| 13 | @IBOutlet weak var couponBgImage: UIImageView! | 13 | @IBOutlet weak var couponBgImage: UIImageView! |
| 14 | @IBOutlet weak var couponImage: UIImageView! | 14 | @IBOutlet weak var couponImage: UIImageView! |
| 15 | @IBOutlet weak var borderView: UIView! | 15 | @IBOutlet weak var borderView: UIView! | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -64,6 +64,33 @@ extension String { | ... | @@ -64,6 +64,33 @@ extension String { |
| 64 | } | 64 | } |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | +extension String { | ||
| 68 | + | ||
| 69 | + var length: Int { | ||
| 70 | + return count | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + subscript (i: Int) -> String { | ||
| 74 | + return self[i ..< i + 1] | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + func substring(fromIndex: Int) -> String { | ||
| 78 | + return self[min(fromIndex, length) ..< length] | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + func substring(toIndex: Int) -> String { | ||
| 82 | + return self[0 ..< max(0, toIndex)] | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + subscript (r: Range<Int>) -> String { | ||
| 86 | + let range = Range(uncheckedBounds: (lower: max(0, min(length, r.lowerBound)), | ||
| 87 | + upper: min(length, max(0, r.upperBound)))) | ||
| 88 | + let start = index(startIndex, offsetBy: range.lowerBound) | ||
| 89 | + let end = index(start, offsetBy: range.upperBound - range.lowerBound) | ||
| 90 | + return String(self[start ..< end]) | ||
| 91 | + } | ||
| 92 | +} | ||
| 93 | + | ||
| 67 | extension UIView { | 94 | extension UIView { |
| 68 | 95 | ||
| 69 | func addDashedBorderVertical(color: UIColor, width: CGFloat, height: CGFloat) { | 96 | func addDashedBorderVertical(color: UIColor, width: CGFloat, height: CGFloat) { | ... | ... |
-
Please register or login to post a comment