WalletActiveCouponsScrollTableViewCell.swift
8.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//
// WalletActiveCouponsScrollTableViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 8/5/24.
//
import UIKit
import SwiftEventBus
@objc public class WalletActiveCouponsScrollTableViewCell: UITableViewCell {
@IBOutlet weak var sectionTitleLabel: UILabel!
@IBOutlet weak var historyButtonImage: UIImageView!
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var dotLeft: UIView!
@IBOutlet weak var dotLeftWidth: NSLayoutConstraint!
@IBOutlet weak var dotLeftHeight: NSLayoutConstraint!
@IBOutlet weak var dotRight: UIView!
@IBOutlet weak var dotRightWidth: NSLayoutConstraint!
@IBOutlet weak var dotRightHeight: NSLayoutConstraint!
var parent: UIViewController?
public var activeCouponBadges:Array<swiftApi.WalletActiveCouponBadgeModel> = []
public override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
// Section Header
sectionTitleLabel.text = "Κουπόνια"
historyButtonImage.image = UIImage(named: "wallet_history_blue", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
historyButtonImage.image = historyButtonImage.image?.withRenderingMode(.alwaysTemplate)
historyButtonImage.tintColor = UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)
collectionView.contentInset.left = 17
collectionView.contentInset.right = 17
dotLeftWidth.constant = 12
dotLeftHeight.constant = 12
dotLeft.layer.cornerRadius = 6
dotRightWidth.constant = 8
dotRightHeight.constant = 8
dotRight.layer.cornerRadius = 4
}
public override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func configureCell(dfyCount: Int, smCount: Int, gfyCount: Int, boxCount: Int) {
sortBadges(dfyCount, smCount, gfyCount, boxCount)
}
func sortBadges(_ dfyCount: Int, _ smCount: Int, _ gfyCount: Int, _ boxCount: Int) {
// deals weight 3
// sm weight 2
// free weight 1
// box weight 0
let DFYBadge = swiftApi.WalletActiveCouponBadgeModel()
DFYBadge._id = "dfy"
DFYBadge._count = dfyCount
DFYBadge._weight = 3
let SMBadge = swiftApi.WalletActiveCouponBadgeModel()
SMBadge._id = "sm"
SMBadge._count = smCount
SMBadge._weight = 2
let GFYBadge = swiftApi.WalletActiveCouponBadgeModel()
GFYBadge._id = "gfy"
GFYBadge._count = gfyCount
GFYBadge._weight = 1
let BOXBadge = swiftApi.WalletActiveCouponBadgeModel()
BOXBadge._id = "box"
BOXBadge._count = boxCount
BOXBadge._weight = 0
let tempActiveCouponBadges:Array<swiftApi.WalletActiveCouponBadgeModel> = [DFYBadge, SMBadge, GFYBadge, BOXBadge]
// var tempActiveCouponBadges:Array<swiftApi.WalletActiveCouponBadgeModel> = []
// tempActiveCouponBadges.append(DFYBadge)
// tempActiveCouponBadges.append(SMBadge)
// tempActiveCouponBadges.append(GFYBadge)
// tempActiveCouponBadges.append(BOXBadge)
let sortedActiveCouponBadges = tempActiveCouponBadges.sorted {
($0._weight) > ($1._weight)
}
.sorted {
($0._count) > ($1._count)
}
activeCouponBadges = sortedActiveCouponBadges
collectionView.reloadData();
}
}
extension WalletActiveCouponsScrollTableViewCell: UIScrollViewDelegate {
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
let contentOffsetX = scrollView.contentOffset.x
if contentOffsetX >= (scrollView.contentSize.width - scrollView.bounds.width) - 20 {
dotLeftWidth.constant = 8
dotLeftHeight.constant = 8
dotLeft.layer.cornerRadius = 4
dotRightWidth.constant = 12
dotRightHeight.constant = 12
dotRight.layer.cornerRadius = 6
} else {
dotLeftWidth.constant = 12
dotLeftHeight.constant = 12
dotLeft.layer.cornerRadius = 6
dotRightWidth.constant = 8
dotRightHeight.constant = 8
dotRight.layer.cornerRadius = 4
}
}
}
extension WalletActiveCouponsScrollTableViewCell: UICollectionViewDataSource,UICollectionViewDelegate {
public func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return activeCouponBadges.count
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let badgeId = activeCouponBadges[indexPath.row]._id;
let badgeCount = activeCouponBadges[indexPath.row]._count;
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "WalletActiveCouponCollectionViewCellId", for: indexPath) as! WalletActiveCouponCollectionViewCell
cell.configureCell(badgeId: badgeId, badgeCount: badgeCount)
return cell;
}
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let badgeId = activeCouponBadges[indexPath.row]._id
if (badgeId == "dfy") {
print("Active DFY coupon banner Tapped!")
swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveDealsBanner"))
let couponDetails = swiftApi.ActiveDFYCouponEventModel()
couponDetails._isPressed = true
SwiftEventBus.post("dfy_coupon_details", sender: couponDetails)
} else if (badgeId == "sm") {
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
firebaseEvent._eventName = "did_tap_market_active_badge"
firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
SwiftEventBus.post("firebase", sender: firebaseEvent)
swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveMarketBanner"))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "UnifiedCouponsViewController") as! SwiftWarplyFramework.UnifiedCouponsViewController
parent?.navigationController?.pushViewController(vc, animated: true)
} else if (badgeId == "gfy") {
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
firebaseEvent._eventName = "did_tap_gifts_for_you_active_badge"
firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
SwiftEventBus.post("firebase", sender: firebaseEvent)
swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveLoyaltyBanner"))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: SwiftWarplyFramework.CouponsViewController.self))
if let vc = storyboard.instantiateViewController(withIdentifier: "CouponsViewController") as? SwiftWarplyFramework.CouponsViewController{
parent?.navigationController?.pushViewController(vc,animated: true)
}
} else if (badgeId == "box") {
print("Active BOX coupon banner Tapped!")
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
firebaseEvent._eventName = "did_tap_box_active_badge"
firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
SwiftEventBus.post("firebase", sender: firebaseEvent)
swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveBoxBanner"))
// SwiftEventBus.post("box_coupon_details")
let couponDetails = swiftApi.ActiveBoxCouponEventModel()
couponDetails._isPressed = true
SwiftEventBus.post("box_coupon_details", sender: couponDetails)
}
}
// Distance Between Item Cells
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 5
}
// Cell Margin
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0)
}
}