Manos Chorianopoulos

add CouponsViewController

Showing 17 changed files with 232 additions and 10 deletions
......@@ -7,7 +7,7 @@
<key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
......
......@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */; };
7630AD9A6242D60846D6750C /* Pods_SwiftWarplyFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */; };
E6A77853282933340045BBA8 /* SwiftWarplyFramework.docc in Sources */ = {isa = PBXBuildFile; fileRef = E6A77852282933340045BBA8 /* SwiftWarplyFramework.docc */; };
E6A77854282933340045BBA8 /* SwiftWarplyFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = E6A77851282933340045BBA8 /* SwiftWarplyFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
......@@ -137,6 +138,7 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponsTableViewCell.swift; sourceTree = "<group>"; };
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>"; };
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>"; };
C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SwiftWarplyFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -320,6 +322,7 @@
isa = PBXGroup;
children = (
E6A7785E282933E40045BBA8 /* CouponsViewController.swift */,
1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */,
E6A7785D282933E40045BBA8 /* CouponViewController.swift */,
E6A77863282933E50045BBA8 /* DetailsViewController.swift */,
E6A778DE282933E60045BBA8 /* GiftsViewController.swift */,
......@@ -750,6 +753,7 @@
E6A77935282933E70045BBA8 /* UIWebView+AFNetworking.m in Sources */,
E6A77925282933E70045BBA8 /* UIProgressView+AFNetworking.m in Sources */,
E6A77944282933E70045BBA8 /* AFSecurityPolicy.m in Sources */,
1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */,
E6A77A32282BA9C60045BBA8 /* CampaignViewController.swift in Sources */,
E6A77917282933E60045BBA8 /* UIViewController+WLAdditions.m in Sources */,
E6A77943282933E70045BBA8 /* AFNetworkReachabilityManager.m in Sources */,
......
......@@ -7,7 +7,7 @@
<key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
......
......@@ -9,6 +9,7 @@ import UIKit
class CouponViewController: UIViewController {
@IBOutlet weak var mainView: UIView!
@IBOutlet weak var backgroundImage: UIImageView!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var scrollContentView: UIView!
@IBOutlet weak var couponImageHeight: NSLayoutConstraint!
......@@ -28,6 +29,8 @@ class CouponViewController: UIViewController {
setBackButton()
setNavigationTitle("Εκπτωτικό κουπόνι")
backgroundImage.image = UIImage(named: "coupons_scrollview_white")
scrollView.clipsToBounds = true
scrollView.layer.cornerRadius = 30
scrollView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
......
//
// CouponsTableViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/5/22.
//
import Foundation
import UIKit
import WarplySDKFrameworkIOS
class CouponsTableViewCell: UITableViewCell {
@IBOutlet weak var couponBgImage: UIImageView!
@IBOutlet weak var couponImage: UIImageView!
@IBOutlet weak var borderView: UIView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var dicountLabel: UILabel!
@IBOutlet weak var discriptionLabel: UILabel!
@IBOutlet weak var expirationLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
couponBgImage.image = UIImage(named: "coupon_bg")
borderView.addDashedBorderVertical(color: UIColor(red: 0.44, green: 0.44, blue: 0.44, alpha: 1.00), width: 1.0, height: 110.0)
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
override func layoutSubviews() {
super.layoutSubviews()
//set the values for top,left,bottom,right margins
let margins = UIEdgeInsets(top: 0, left: 0, bottom: 30, right: 0)
contentView.frame = contentView.frame.inset(by: margins)
}
func configureCell(coupon: swiftApi.CouponItemModel) {
// COUPONSET: desc, img_preview, name, terms
// COUPON: coupon, expiration, discount, status
let couponSetData: swiftApi.CouponSetItemModel? = coupon.couponset_data
couponImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
nameLabel.text = couponSetData?.name ?? ""
dicountLabel.text = (coupon.discount ?? "") + "€"
discriptionLabel.text = couponSetData?.short_description ?? ""
expirationLabel.text = "Ισχύει έως "+(coupon.expiration ?? "")
}
}
......@@ -7,21 +7,86 @@
import Foundation
import UIKit
import WarplySDKFrameworkIOS
@objc public class CouponsViewController: UIViewController {
@IBOutlet weak var backgroundImage: UIImageView!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var couponButton: UIButton!
var coupons:Array<swiftApi.CouponItemModel> = []
override func viewDidLoad() {
super.viewDidLoad()
getCouponsRequest()
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setBackButton()
setNavigationTitle("Εκπτωτικό κουπόνι")
setNavigationTitle("Ενεργά κουπόνια")
backgroundImage.image = UIImage(named: "coupons_scrollview_dark")
tableView.delegate = self
tableView.dataSource = self
tableView.clipsToBounds = true
tableView.layer.cornerRadius = 30
tableView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
tableView.contentInset.top = 50
}
@IBAction func navigateToCoupon(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "CouponViewController") as UIViewController
self.navigationController?.pushViewController(vc, animated: true)
// MARK: - API Functions
func getCouponsRequest() {
swiftApi().getCouponsAsync(getCouponsCallback)
}
func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
if (couponsData != nil) {
let activeCouponData = swiftApi().filterActiveCoupons(couponsData ?? [])
self.coupons = activeCouponData
DispatchQueue.main.async {
self.tableView.reloadData()
}
} else {
self.coupons = []
}
}
}
// MARK: - TableView
extension CouponsViewController: UITableViewDelegate, UITableViewDataSource{
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.coupons.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 120.0 + 30.0
// return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CouponsTableViewCellId", for: indexPath) as! CouponsTableViewCell
cell.configureCell(coupon: coupons[indexPath.row])
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// TODO: navigate to CouponBarcode
// let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
// let vc = storyboard.instantiateViewController(withIdentifier: "CouponBarcodeViewController") as UIViewController
// self.navigationController?.pushViewController(vc, animated: true)
}
}
......
{
"images" : [
{
"filename" : "coupon_bg.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "coupon_bg-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "coupon_bg-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "coupons_scrollview_dark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "coupons_scrollview_dark-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "coupons_scrollview_dark-2.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -63,3 +63,49 @@ extension String {
return htmlToAttributedString?.string ?? ""
}
}
extension UIView {
func addDashedBorderVertical(color: UIColor, width: CGFloat, height: CGFloat) {
let color = color.cgColor
let frameSize = self.frame.size
let lineLayer = CAShapeLayer()
lineLayer.strokeColor = color
lineLayer.lineWidth = width
lineLayer.lineDashPattern = [5,5]
let path = CGMutablePath()
path.addLines(between: [CGPoint(x: frameSize.width/2, y: 0), CGPoint(x: frameSize.width/2, y: height)])
lineLayer.path = path
self.layer.addSublayer(lineLayer)
}
}
extension UIImageView {
func load(link: String, placeholder: UIImage?, cache: URLCache? = nil) {
guard let url = URL(string: link) else { return }
let cache = cache ?? URLCache.shared
let request = URLRequest(url: url)
if let data = cache.cachedResponse(for: request)?.data, let image = UIImage(data: data) {
DispatchQueue.main.async {
self.image = image
}
} else {
self.image = placeholder
URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in
if let data = data, let response = response, ((response as? HTTPURLResponse)?.statusCode ?? 500) < 300, let image = UIImage(data: data) {
let cachedData = CachedURLResponse(response: response, data: data)
cache.storeCachedResponse(cachedData, for: request)
DispatchQueue.main.async {
self.image = image
}
}
}).resume()
}
}
}
......