Manos Chorianopoulos

ProfileViewController filter functionality

...@@ -17,6 +17,8 @@ protocol ProfileCouponFiltersTableViewCellDelegate: AnyObject { ...@@ -17,6 +17,8 @@ protocol ProfileCouponFiltersTableViewCellDelegate: AnyObject {
17 17
18 weak var delegate: ProfileCouponFiltersTableViewCellDelegate? 18 weak var delegate: ProfileCouponFiltersTableViewCellDelegate?
19 var data: [CouponFilterModel]? 19 var data: [CouponFilterModel]?
20 + var couponFilterSelected: CouponFilterModel?
21 +// var couponFilterSelected: CouponFilterModel = CouponFilterModel(title: "Ενεργά")
20 22
21 public override func awakeFromNib() { 23 public override func awakeFromNib() {
22 super.awakeFromNib() 24 super.awakeFromNib()
...@@ -72,8 +74,9 @@ protocol ProfileCouponFiltersTableViewCellDelegate: AnyObject { ...@@ -72,8 +74,9 @@ protocol ProfileCouponFiltersTableViewCellDelegate: AnyObject {
72 // Configure the view for the selected state 74 // Configure the view for the selected state
73 } 75 }
74 76
75 - func configureCell(data: [CouponFilterModel]?) { 77 + func configureCell(data: [CouponFilterModel]?, couponFilterSelected: CouponFilterModel) {
76 self.data = data 78 self.data = data
79 + self.couponFilterSelected = couponFilterSelected
77 80
78 self.collectionView.reloadData(); 81 self.collectionView.reloadData();
79 } 82 }
...@@ -93,8 +96,9 @@ extension ProfileCouponFiltersTableViewCell: UICollectionViewDataSource, UIColle ...@@ -93,8 +96,9 @@ extension ProfileCouponFiltersTableViewCell: UICollectionViewDataSource, UIColle
93 public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 96 public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
94 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProfileFilterCollectionViewCell", for: indexPath) as! ProfileFilterCollectionViewCell 97 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProfileFilterCollectionViewCell", for: indexPath) as! ProfileFilterCollectionViewCell
95 if let filter = self.data?[indexPath.row] { 98 if let filter = self.data?[indexPath.row] {
96 - // TODO: Fix dynamic 99 +// let isSelected = self.data?[indexPath.row].title == "Ενεργά"
97 - let isSelected = self.data?[indexPath.row].title == "Ενεργά" 100 +// let isSelected = self.data?[indexPath.row].title == self.couponFilterSelected.title
101 + let isSelected = self.data?[indexPath.row].title == self.couponFilterSelected?.title ?? "Ενεργά"
98 cell.configureCell(data: filter, isSelected: isSelected) 102 cell.configureCell(data: filter, isSelected: isSelected)
99 } 103 }
100 return cell; 104 return cell;
......
...@@ -242,7 +242,7 @@ import UIKit ...@@ -242,7 +242,7 @@ import UIKit
242 // Favorite Offers 242 // Favorite Offers
243 let redeemedOffers = allOffers.filter { $0.redeemed ?? false } 243 let redeemedOffers = allOffers.filter { $0.redeemed ?? false }
244 redeemedOffersSection = SectionModel( 244 redeemedOffersSection = SectionModel(
245 - title: "Αγαπημένα", 245 + title: "Εξαργυρωμένα",
246 count: redeemedOffers.count, 246 count: redeemedOffers.count,
247 offers: redeemedOffers 247 offers: redeemedOffers
248 ) 248 )
...@@ -256,6 +256,19 @@ import UIKit ...@@ -256,6 +256,19 @@ import UIKit
256 256
257 self.navigationController?.pushViewController(vc, animated: true) 257 self.navigationController?.pushViewController(vc, animated: true)
258 } 258 }
259 +
260 + private func handleFilterPress(with filter: CouponFilterModel) {
261 + switch (filter.title) {
262 + case "Ενεργά":
263 + self.filteredOffersSection = activeOffersSection
264 + case "Αγαπημένα":
265 + self.filteredOffersSection = favoriteOffersSection
266 + case "Εξαργυρωμένα":
267 + self.filteredOffersSection = redeemedOffersSection
268 + default:
269 + self.filteredOffersSection = activeOffersSection
270 + }
271 + }
259 } 272 }
260 273
261 // MARK: - TableView 274 // MARK: - TableView
...@@ -328,7 +341,7 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -328,7 +341,7 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource {
328 let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCouponFiltersTableViewCell", for: indexPath) as! ProfileCouponFiltersTableViewCell 341 let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileCouponFiltersTableViewCell", for: indexPath) as! ProfileCouponFiltersTableViewCell
329 342
330 cell.delegate = self // Set the offers delegate 343 cell.delegate = self // Set the offers delegate
331 - cell.configureCell(data: self.couponFilters) 344 + cell.configureCell(data: self.couponFilters, couponFilterSelected: self.couponFilterSelected)
332 345
333 return cell 346 return cell
334 347
...@@ -343,25 +356,12 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource { ...@@ -343,25 +356,12 @@ extension ProfileViewController: UITableViewDelegate, UITableViewDataSource {
343 } 356 }
344 357
345 public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 358 public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
346 - if (indexPath.section == 0) { 359 + if (indexPath.section <= 3) {
347 - // Do nothing - Each button is handled differently
348 -
349 - } else if (indexPath.section == 1) {
350 - // Do nothing
351 - } else if (indexPath.section == 2) {
352 - // Do nothing
353 - } else if (indexPath.section == 3) {
354 - // Do nothing
355 - } else if (indexPath.section == 4) {
356 - // Do nothing
357 - } else if (indexPath.section == 5) {
358 - // Do nothing
359 - } else if (indexPath.section == 6) {
360 - // Do nothing
361 - } else if (indexPath.section == 7) {
362 // Do nothing 360 // Do nothing
363 } else { 361 } else {
364 - // Do nothing 362 + if let offer = self.filteredOffersSection?.offers[indexPath.row] {
363 + openCouponViewController(with: offer)
364 + }
365 } 365 }
366 } 366 }
367 } 367 }
...@@ -378,6 +378,7 @@ extension ProfileViewController: MyRewardsOffersScrollTableViewCellDelegate { ...@@ -378,6 +378,7 @@ extension ProfileViewController: MyRewardsOffersScrollTableViewCellDelegate {
378 extension ProfileViewController: ProfileCouponFiltersTableViewCellDelegate { 378 extension ProfileViewController: ProfileCouponFiltersTableViewCellDelegate {
379 func didSelectFilter(_ filter: CouponFilterModel) { 379 func didSelectFilter(_ filter: CouponFilterModel) {
380 self.couponFilterSelected = filter 380 self.couponFilterSelected = filter
381 + handleFilterPress(with: filter)
381 self.tableView.reloadData() 382 self.tableView.reloadData()
382 } 383 }
383 } 384 }
......