MyRewardsViewController.swift
16.9 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
//
// MyRewardsViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 22/5/25.
//
import UIKit
struct SectionModel {
let title: String
let count: Int
let offers: [OfferModel]
}
struct OfferModel {
let category: String
let title: String
let description: String
let discount: String
let discountType: String // e.g., "price", "percentage", "free", "buyOneGetOne", etc.
let bannerImage: String
let merchantLogo: String
let expirationDate: String
let color: UInt
var isFavorite: Bool
}
@objc public class MyRewardsViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
// MARK: - Dummy Data
let allOffers: [OfferModel] = [
// Banner Offers
OfferModel(
category: "Διαγωνισμός",
title: "Διαγωνισμός Κού-πονς!",
description: "13 Απίθανα ΔΩΡΑ σε περιμένουν!",
discount: "",
discountType: "contest",
bannerImage: "contest_banner",
merchantLogo: "contest_logo",
expirationDate: "30/06/2025",
color: 0x8A2BE2,
isFavorite: false
),
OfferModel(
category: "Διαγωνισμός",
title: "Διαγωνισμός Κού-πονς!",
description: "13 Απίθανα ΔΩΡΑ σε περιμένουν!",
discount: "",
discountType: "contest",
bannerImage: "contest_banner",
merchantLogo: "contest_logo",
expirationDate: "30/06/2025",
color: 0x8A2BE2,
isFavorite: false
),
OfferModel(
category: "Διαγωνισμός",
title: "Διαγωνισμός Κού-πονς!",
description: "13 Απίθανα ΔΩΡΑ σε περιμένουν!",
discount: "",
discountType: "contest",
bannerImage: "contest_banner",
merchantLogo: "contest_logo",
expirationDate: "30/06/2025",
color: 0x8A2BE2,
isFavorite: false
),
// Top offers
OfferModel(
category: "Top offers",
title: "Μόνο 17.95",
description: "2 πίτσες & Coca-COLA 1,5lt",
discount: "17.95€",
discountType: "price",
bannerImage: "pizza_banner",
merchantLogo: "dominos_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: true
),
OfferModel(
category: "Top offers",
title: "20% έκπτωση",
description: "για όλες τις online αγορές σας",
discount: "20%",
discountType: "percentage",
bannerImage: "furniture_banner",
merchantLogo: "ikea_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: false
),
// OfferModel(
// category: "Top offers",
// title: "Δωρεάν μεταφορικά",
// description: "για αγορές άνω των 50€",
// discount: "Δωρεάν",
// discountType: "free",
// bannerImage: "delivery_banner",
// merchantLogo: "skroutz_logo",
// expirationDate: "έως 30/09",
// color: 0xEE417D,
// isFavorite: false
// ),
// Αγαπημένα
// OfferModel(
// category: "Αγαπημένα",
// title: "15% έκπτωση",
// description: "στην ενοικίαση αυτοκινήτου",
// discount: "15%",
// discountType: "percentage",
// bannerImage: "car_rental_banner",
// merchantLogo: "avis_logo",
// expirationDate: "έως 30/09",
// color: 0xEE417D,
// isFavorite: true
// ),
// OfferModel(
// category: "Αγαπημένα",
// title: "20€ έως και",
// description: "έκπτωση στα πακέτα",
// discount: "20€",
// discountType: "amount",
// bannerImage: "hotel_banner",
// merchantLogo: "booking_logo",
// expirationDate: "έως 30/09",
// color: 0xEE417D,
// isFavorite: true
// ),
// Βιωσιμότητα
OfferModel(
category: "Βιωσιμότητα",
title: "15% έκπτωση",
description: "σε όλα τα προϊόντα",
discount: "15%",
discountType: "percentage",
bannerImage: "musa_banner",
merchantLogo: "musa_logo",
expirationDate: "έως 30/09",
color: 0x09914E,
isFavorite: false
),
OfferModel(
category: "Βιωσιμότητα",
title: "20% έκπτωση",
description: "στην παραγγελία",
discount: "20%",
discountType: "percentage",
bannerImage: "musa_banner",
merchantLogo: "musa_logo",
expirationDate: "έως 30/09",
color: 0x09914E,
isFavorite: true
),
// Family
OfferModel(
category: "Family",
title: "10% έκπτωση",
description: "στην κατασκήνωση στο The Ranch",
discount: "10%",
discountType: "percentage",
bannerImage: "ranch_banner",
merchantLogo: "ranch_logo",
expirationDate: "έως 30/09",
color: 0xFC9F25,
isFavorite: false
),
OfferModel(
category: "Family",
title: "1+1 εισιτήριο",
description: "δώρο στην είσοδο του παιδότοπου",
discount: "1+1",
discountType: "buyOneGetOne",
bannerImage: "ranch_banner",
merchantLogo: "ranch_logo",
expirationDate: "έως 30/09",
color: 0xFC9F25,
isFavorite: false
),
// Φαγητό και καφές
OfferModel(
category: "Φαγητό και καφές",
title: "2€ έκπτωση",
description: "στην αγορά σου",
discount: "2€",
discountType: "amount",
bannerImage: "coffeeisland_banner",
merchantLogo: "coffeeisland_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: false
),
OfferModel(
category: "Φαγητό και καφές",
title: "10% έκπτωση",
description: "σε γλυκά & πεϊνιρλιδες",
discount: "10%",
discountType: "percentage",
bannerImage: "coffeeisland_banner",
merchantLogo: "coffeeisland_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: false
),
// Απόδραση
OfferModel(
category: "Απόδραση",
title: "10% έκπτωση",
description: "στην διαμονή/διασκέδαση σου",
discount: "10%",
discountType: "percentage",
bannerImage: "ninemia_banner",
merchantLogo: "ninemia_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: true
),
OfferModel(
category: "Απόδραση",
title: "10% έκπτωση",
description: "σε όλες τις υπηρεσίες",
discount: "10%",
discountType: "percentage",
bannerImage: "ninemia_banner",
merchantLogo: "ninemia_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: false
),
// Παιδί
OfferModel(
category: "Παιδί",
title: "10% έκπτωση",
description: "για αγορές από τα φυσικά καταστήματα",
discount: "10%",
discountType: "percentage",
bannerImage: "moustakas_banner",
merchantLogo: "moustakas_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: false
),
OfferModel(
category: "Παιδί",
title: "1+1 Δώρο",
description: "στην είσοδο του παιδότοπου",
discount: "1+1",
discountType: "buyOneGetOne",
bannerImage: "moustakas_banner",
merchantLogo: "moustakas_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: false
),
// Αγορές
OfferModel(
category: "Αγορές",
title: "15€ έκπτωση",
description: "για αγορές",
discount: "15€",
discountType: "amount",
bannerImage: "migato_banner",
merchantLogo: "migato_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: false
),
OfferModel(
category: "Αγορές",
title: "Έως 30% έκπτωση",
description: "στις αγορές σου",
discount: "Έως 30%",
discountType: "percentage",
bannerImage: "migato_banner",
merchantLogo: "migato_logo",
expirationDate: "έως 30/09",
color: 0xEE417D,
isFavorite: false
)
]
var bannerOffersSection: SectionModel?
var topOffersSection: SectionModel?
var favoriteOffersSection: SectionModel?
var sustainableOffersSection: SectionModel?
var familyOffersSection: SectionModel?
var foodOffersSection: SectionModel?
var escapeOffersSection: SectionModel?
var childOffersSection: SectionModel?
var shoppingOffersSection: SectionModel?
public override func viewDidLoad() {
super.viewDidLoad()
// Register XIBs for table view cells
tableView.register(UINib(nibName: "MyRewardsBannerOffersScrollTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "MyRewardsBannerOffersScrollTableViewCell")
tableView.register(UINib(nibName: "MyRewardsOffersScrollTableViewCell", bundle: Bundle(for: MyEmptyClass.self)), forCellReuseIdentifier: "MyRewardsOffersScrollTableViewCell")
// Set up table view
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .none
tableView.estimatedRowHeight = 200
tableView.rowHeight = UITableView.automaticDimension
initializeSections()
}
// MARK: Function
func initializeSections() {
// Banner Offers (for the promotional banner at the top)
let bannerOffers = allOffers.filter { $0.category == "Διαγωνισμός" }
bannerOffersSection = SectionModel(
title: "Διαγωνισμός",
count: bannerOffers.count,
offers: bannerOffers
)
// Top Offers
let topOffers = allOffers.filter { $0.category == "Top offers" }
topOffersSection = SectionModel(
title: "Top offers",
count: topOffers.count,
offers: topOffers
)
// Favorite Offers
let favoriteOffers = allOffers.filter { $0.isFavorite }
favoriteOffersSection = SectionModel(
title: "Αγαπημένα",
count: favoriteOffers.count,
offers: favoriteOffers
)
// Sustainable Offers
let sustainableOffers = allOffers.filter { $0.category == "Βιωσιμότητα" }
sustainableOffersSection = SectionModel(
title: "Βιωσιμότητα",
count: sustainableOffers.count,
offers: sustainableOffers
)
// Family Offers
let familyOffers = allOffers.filter { $0.category == "Family" }
familyOffersSection = SectionModel(
title: "Family",
count: familyOffers.count,
offers: familyOffers
)
// Food Offers
let foodOffers = allOffers.filter { $0.category == "Φαγητό και καφές" }
foodOffersSection = SectionModel(
title: "Φαγητό και καφές",
count: foodOffers.count,
offers: foodOffers
)
// Escape Offers
let escapeOffers = allOffers.filter { $0.category == "Απόδραση" }
escapeOffersSection = SectionModel(
title: "Απόδραση",
count: escapeOffers.count,
offers: escapeOffers
)
// Child Offers
let childOffers = allOffers.filter { $0.category == "Παιδί" }
childOffersSection = SectionModel(
title: "Παιδί",
count: childOffers.count,
offers: childOffers
)
// Shopping Offers
let shoppingOffers = allOffers.filter { $0.category == "Αγορές" }
shoppingOffersSection = SectionModel(
title: "Αγορές",
count: shoppingOffers.count,
offers: shoppingOffers
)
self.tableView.reloadData()
}
}
// MARK: - TableView
extension MyRewardsViewController: UITableViewDelegate, UITableViewDataSource{
public func numberOfSections(in tableView: UITableView) -> Int {
return 9
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return nil
}
public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.0
}
public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
// return CGFloat.leastNormalMagnitude
return 0.0
}
public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return nil
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (indexPath.section == 0) {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyRewardsBannerOffersScrollTableViewCell", for: indexPath) as! MyRewardsBannerOffersScrollTableViewCell
cell.configureCell(data: self.bannerOffersSection)
// cell.parent = self
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyRewardsOffersScrollTableViewCell", for: indexPath) as! MyRewardsOffersScrollTableViewCell
if (indexPath.section == 1) {
cell.configureCell(data: self.topOffersSection)
} else if (indexPath.section == 2) {
cell.configureCell(data: self.favoriteOffersSection)
} else if (indexPath.section == 3) {
cell.configureCell(data: self.sustainableOffersSection)
} else if (indexPath.section == 4) {
cell.configureCell(data: self.familyOffersSection)
} else if (indexPath.section == 5) {
cell.configureCell(data: self.foodOffersSection)
} else if (indexPath.section == 6) {
cell.configureCell(data: self.escapeOffersSection)
} else if (indexPath.section == 7) {
cell.configureCell(data: self.childOffersSection)
} else {
cell.configureCell(data: self.shoppingOffersSection)
}
return cell
}
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if (indexPath.section == 0) {
// Do nothing - Each button is handled differently
} else if (indexPath.section == 1) {
// Do nothing
} else if (indexPath.section == 2) {
// Do nothing
} else if (indexPath.section == 3) {
// Do nothing
} else if (indexPath.section == 4) {
// Do nothing
} else if (indexPath.section == 5) {
// Do nothing
} else if (indexPath.section == 6) {
// Do nothing
} else if (indexPath.section == 7) {
// Do nothing
} else {
// Do nothing
}
}
}