LoyaltyViewController.swift
4.37 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
//
// LoyaltyViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 7/2/24.
//
import UIKit
@objc public class LoyaltyViewController: UIViewController {
@IBOutlet weak var headerView: UIView!
@IBOutlet weak var closeImage: UIImageView!
@IBOutlet weak var logoImage: UIImageView!
@IBOutlet weak var filtersView: UIView!
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var containerView: UIView!
var selectedScreen: String = "Offers"
var filtersList: Array<String> = ["Screen", "Όλα", "Σπίτι", "Έξοδος", "Υγεία"]
var selectedFilter: String = "Όλα"
public override func viewDidLoad() {
super.viewDidLoad()
headerView.applyGradient(colours: [UIColor(rgb: 0x081748), UIColor(rgb: 0x204EAC)], gradient: GradientOrientation.horizontal, cornerRadius: 0.0)
closeImage.image = UIImage(named: "close_btn_white", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
logoImage.image = UIImage(named: "epistrofi_logo", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
closeImage.isHidden = true
// Add shadow
filtersView.layer.shadowColor = UIColor(rgb: 0x000000).cgColor
filtersView.layer.shadowOffset = CGSize(width: 0.0, height: 10.0)
filtersView.layer.shadowOpacity = 0.05
filtersView.layer.shadowRadius = 6.0
collectionView.contentInset.left = 20
collectionView.contentInset.right = 20
loadVC(vcName: "OffersViewController");
}
func loadVC(vcName: String) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
var vc: UIViewController;
if (vcName == "OffersViewController") {
vc = storyboard.instantiateViewController(withIdentifier: "OffersViewController") as! SwiftWarplyFramework.OffersViewController
} else {
vc = storyboard.instantiateViewController(withIdentifier: "MapViewController") as! SwiftWarplyFramework.MapViewController
}
addChild(vc)
vc.view.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(vc.view)
NSLayoutConstraint.activate([
vc.view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 0),
vc.view.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: 0),
vc.view.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 0),
vc.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: 0)
])
vc.didMove(toParent: self)
}
}
extension LoyaltyViewController: UICollectionViewDataSource,UICollectionViewDelegate {
public func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return filtersList.count
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (indexPath.row == 0) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ScreenCollectionViewCellId", for: indexPath) as! ScreenCollectionViewCell
cell.configureCell(screen: selectedScreen)
return cell;
} else {
let currentFilter = filtersList[indexPath.row];
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FiltersCollectionViewCellId", for: indexPath) as! FiltersCollectionViewCell
cell.configureCell(filterName: currentFilter, isSelected: currentFilter == selectedFilter)
return cell;
}
}
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if (indexPath.row == 0) {
let offersSelected = selectedScreen == "Offers";
selectedScreen = offersSelected ? "Map" : "Offers"
loadVC(vcName: selectedScreen == "Offers" ? "OffersViewController" : "MapViewController");
} else {
let currentFilter = filtersList[indexPath.row];
selectedFilter = currentFilter;
}
collectionView.reloadData();
}
}