Manos Chorianopoulos

CategoryOffersViewController part1

...@@ -57,7 +57,11 @@ let package = Package( ...@@ -57,7 +57,11 @@ let package = Package(
57 .process("cells/MyRewardsOfferCollectionViewCell/MyRewardsOfferCollectionViewCell.xib"), 57 .process("cells/MyRewardsOfferCollectionViewCell/MyRewardsOfferCollectionViewCell.xib"),
58 .process("cells/MyRewardsBannerOffersScrollTableViewCell/MyRewardsBannerOffersScrollTableViewCell.xib"), 58 .process("cells/MyRewardsBannerOffersScrollTableViewCell/MyRewardsBannerOffersScrollTableViewCell.xib"),
59 .process("screens/MyCouponsViewController/MyCouponsViewController.xib"), 59 .process("screens/MyCouponsViewController/MyCouponsViewController.xib"),
60 - .process("cells/MyCouponsHeaderTableViewCell/MyCouponsHeaderTableViewCell.xib") 60 + .process("cells/MyCouponsHeaderTableViewCell/MyCouponsHeaderTableViewCell.xib"),
61 + .process("cells/CategoryOfferCollectionViewCell/CategoryOfferCollectionViewCell.xib"),
62 + .process("cells/CategoryOffersHeaderTableViewCell/CategoryOffersHeaderTableViewCell.xib"),
63 + .process("cells/CategoryOffersGridTableViewCell/CategoryOffersGridTableViewCell.xib"),
64 + .process("screens/CategoryOffersViewController/CategoryOffersViewController.xib")
61 ] 65 ]
62 ), 66 ),
63 ] 67 ]
......
1 +//
2 +// CategoryOfferCollectionViewCell.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 19/3/26.
6 +//
7 +
8 +import UIKit
9 +
10 +@objc(CategoryOfferCollectionViewCell)
11 +public class CategoryOfferCollectionViewCell: UICollectionViewCell {
12 +
13 + public override func awakeFromNib() {
14 + super.awakeFromNib()
15 + // Initialization code
16 + }
17 +
18 +}
1 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3 + <dependencies>
4 + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
5 + <capability name="Safe area layout guides" minToolsVersion="9.0"/>
6 + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7 + </dependencies>
8 + <objects>
9 + <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
10 + <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
11 + <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="CategoryOfferCollectionViewCell" customModuleProvider="target">
12 + <rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
13 + <autoresizingMask key="autoresizingMask"/>
14 + <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
15 + <rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
16 + <color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
17 + </view>
18 + <viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
19 + </collectionViewCell>
20 + </objects>
21 +</document>
1 +//
2 +// CategoryOffersGridTableViewCell.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 19/3/26.
6 +//
7 +
8 +import UIKit
9 +
10 +@objc(CategoryOffersGridTableViewCell)
11 +public class CategoryOffersGridTableViewCell: UITableViewCell {
12 +
13 + @IBOutlet weak var collectionView: UICollectionView!
14 + @IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint!
15 +
16 + var data: SectionModel?
17 + weak var parentViewController: UIViewController?
18 +
19 + public override func awakeFromNib() {
20 + super.awakeFromNib()
21 + // Initialization code
22 +
23 + setupCollectionView()
24 + }
25 +
26 + public override func setSelected(_ selected: Bool, animated: Bool) {
27 + super.setSelected(selected, animated: animated)
28 + // Configure the view for the selected state
29 + }
30 +
31 + private func setupCollectionView() {
32 + collectionView.delegate = self
33 + collectionView.dataSource = self
34 + collectionView.backgroundColor = .clear
35 + collectionView.isScrollEnabled = false // Scroll is handled by the outer TableView
36 +
37 + XIBLoader.registerCollectionViewCell(
38 + collectionView,
39 + cellClass: UICollectionViewCell.self,
40 + nibName: "CategoryOfferCollectionViewCell",
41 + identifier: "CategoryOfferCollectionViewCell"
42 + )
43 +
44 + if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
45 + layout.minimumInteritemSpacing = 16
46 + layout.minimumLineSpacing = 16
47 + layout.sectionInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
48 + }
49 + }
50 +
51 + func configureCell(with sectionData: SectionModel?, parentViewController: UIViewController?) {
52 + self.data = sectionData
53 + self.parentViewController = parentViewController
54 +
55 + collectionView.reloadData()
56 +
57 + // Use layoutIfNeeded to calculate content size and set the height constraint
58 + collectionView.layoutIfNeeded()
59 + let height = collectionView.collectionViewLayout.collectionViewContentSize.height
60 + collectionViewHeightConstraint.constant = height
61 + }
62 +}
63 +
64 +extension CategoryOffersGridTableViewCell: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
65 +
66 + public func numberOfSections(in collectionView: UICollectionView) -> Int {
67 + return 1
68 + }
69 +
70 + public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
71 + return self.data?.itemCount ?? 0
72 + }
73 +
74 + public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
75 + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CategoryOfferCollectionViewCell", for: indexPath) as! CategoryOfferCollectionViewCell
76 +
77 + guard let data = self.data,
78 + let items = data.items,
79 + indexPath.row < items.count else {
80 + return cell
81 + }
82 +
83 + switch data.itemType {
84 + case .couponSets:
85 + if let couponSet = items[indexPath.row] as? CouponSetItemModel {
86 + cell.configureCell(data: couponSet)
87 + }
88 + default:
89 + if let offer = items[indexPath.row] as? OfferModel {
90 + cell.configureCell(data: offer)
91 + }
92 + }
93 +
94 + return cell
95 + }
96 +
97 + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
98 + guard let data = self.data,
99 + let items = data.items,
100 + indexPath.row < items.count else {
101 + return
102 + }
103 +
104 + // Handle navigation based on item type
105 + switch data.itemType {
106 + case .couponSets:
107 + if let couponSet = items[indexPath.row] as? CouponSetItemModel {
108 + let storyboard = UIStoryboard(name: "Main", bundle: Bundle.frameworkResourceBundle)
109 + if let vc = storyboard.instantiateViewController(withIdentifier: "CouponsetViewController") as? CouponsetViewController {
110 + vc.couponset = couponSet
111 + self.parentViewController?.navigationController?.pushViewController(vc, animated: true)
112 + }
113 + }
114 + default:
115 + if let offer = items[indexPath.row] as? OfferModel {
116 + // Determine if it's a campaign or other offer and navigate appropriately
117 + // (Using existing patterns from MyRewardsViewController)
118 + let storyboard = UIStoryboard(name: "Main", bundle: Bundle.frameworkResourceBundle)
119 + if let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as? CampaignViewController {
120 + vc.campaignUrl = offer.campaignUrl // Assuming OfferModel has this
121 + self.parentViewController?.navigationController?.pushViewController(vc, animated: true)
122 + }
123 + }
124 + }
125 + }
126 +
127 + public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
128 + // Calculate width for 2 columns with spacing
129 + let padding: CGFloat = 16 * 3 // left + middle + right padding
130 + let availableWidth = collectionView.frame.width - padding
131 + let itemWidth = availableWidth / 2
132 +
133 + // Adjust height as needed based on design (aspect ratio or fixed)
134 + let itemHeight = itemWidth * 1.3 // Approximation from screenshot
135 +
136 + return CGSize(width: itemWidth, height: itemHeight)
137 + }
138 +}
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="24506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3 + <device id="retina6_12" orientation="portrait" appearance="light"/>
4 + <dependencies>
5 + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24504"/>
6 + <capability name="Safe area layout guides" minToolsVersion="9.0"/>
7 + <capability name="System colors in document resources" minToolsVersion="11.0"/>
8 + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9 + </dependencies>
10 + <objects>
11 + <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
12 + <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
13 + <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="CategoryOffersGridTableViewCell" customModule="SwiftWarplyFramework" customModuleProvider="target">
14 + <rect key="frame" x="0.0" y="0.0" width="320" height="200"/>
15 + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
16 + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
17 + <rect key="frame" x="0.0" y="0.0" width="320" height="200"/>
18 + <autoresizingMask key="autoresizingMask"/>
19 + <subviews>
20 + <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="6q1-8v-H6d">
21 + <rect key="frame" x="0.0" y="0.0" width="320" height="200"/>
22 + <color key="backgroundColor" systemColor="systemBackgroundColor"/>
23 + <constraints>
24 + <constraint firstAttribute="height" constant="200" id="E2S-dE-z3n"/>
25 + </constraints>
26 + <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="g5b-eS-1Jq">
27 + <size key="itemSize" width="128" height="128"/>
28 + <size key="headerReferenceSize" width="0.0" height="0.0"/>
29 + <size key="footerReferenceSize" width="0.0" height="0.0"/>
30 + <inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
31 + </collectionViewFlowLayout>
32 + </collectionView>
33 + </subviews>
34 + <constraints>
35 + <constraint firstAttribute="bottom" secondItem="6q1-8v-H6d" secondAttribute="bottom" id="D01-9c-29T"/>
36 + <constraint firstAttribute="trailing" secondItem="6q1-8v-H6d" secondAttribute="trailing" id="D3B-e1-2jZ"/>
37 + <constraint firstItem="6q1-8v-H6d" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="O63-T2-B2y"/>
38 + <constraint firstItem="6q1-8v-H6d" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="YjY-W1-T3M"/>
39 + </constraints>
40 + </tableViewCellContentView>
41 + <viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
42 + <connections>
43 + <outlet property="collectionView" destination="6q1-8v-H6d" id="N8a-1a-1yO"/>
44 + <outlet property="collectionViewHeightConstraint" destination="E2S-dE-z3n" id="A8b-Zc-3rZ"/>
45 + </connections>
46 + <point key="canvasLocation" x="141" y="20"/>
47 + </tableViewCell>
48 + </objects>
49 + <resources>
50 + <systemColor name="systemBackgroundColor">
51 + <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
52 + </systemColor>
53 + </resources>
54 +</document>
1 +//
2 +// CategoryOffersHeaderTableViewCell.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 19/3/26.
6 +//
7 +
8 +import UIKit
9 +
10 +@objc(CategoryOffersHeaderTableViewCell)
11 +public class CategoryOffersHeaderTableViewCell: UITableViewCell {
12 + @IBOutlet weak var headerLabel: UILabel!
13 + @IBOutlet weak var filtersView: UIView!
14 + @IBOutlet weak var filtersLabel: UILabel!
15 + @IBOutlet weak var filtersImage: UIImageView!
16 + @IBOutlet weak var mapView: UIView!
17 + @IBOutlet weak var mapImage: UIImageView!
18 +
19 + public override func awakeFromNib() {
20 + super.awakeFromNib()
21 + // Initialization code
22 +
23 + self.headerLabel.text = ""
24 + self.headerLabel.font = UIFont(name: "PingLCG-Bold", size: 24)
25 + self.headerLabel.textColor = UIColor(rgb: 0x0D1B29)
26 + self.headerLabel.frame.size.width = self.headerLabel.intrinsicContentSize.width
27 + self.headerLabel.frame.size.height = self.headerLabel.intrinsicContentSize.height
28 +
29 + self.filtersView.backgroundColor = UIColor(rgb: 0xF1F2F4)
30 + self.filtersView.layer.cornerRadius = 16 // Assuming height is 32 or similar based on standard chip design
31 + self.filtersView.layer.masksToBounds = true
32 +
33 + self.filtersLabel.text = "Αναζήτηση"
34 + self.filtersLabel.font = UIFont(name: "PingLCG-Regular", size: 16)
35 + self.filtersLabel.textColor = UIColor(rgb: 0x000F1E)
36 + self.filtersLabel.frame.size.width = self.filtersLabel.intrinsicContentSize.width
37 + self.filtersLabel.frame.size.height = self.filtersLabel.intrinsicContentSize.height
38 +
39 + self.filtersImage.image = UIImage(named: "filter", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
40 +
41 + if mapView != nil {
42 + self.mapView.backgroundColor = UIColor(rgb: 0xF1F2F4)
43 + self.mapView.layer.cornerRadius = 22 // Assuming height is 44
44 + self.mapView.layer.masksToBounds = true
45 + }
46 +
47 + if mapImage != nil {
48 + self.mapImage.image = UIImage(named: "ic_map", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
49 + }
50 + }
51 +
52 + public override func setSelected(_ selected: Bool, animated: Bool) {
53 + super.setSelected(selected, animated: animated)
54 +
55 + // Configure the view for the selected state
56 + }
57 +}
1 +//
2 +// CategoryOffersViewController.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 19/3/26.
6 +//
7 +
8 +import UIKit
9 +
10 +@objc public class CategoryOffersViewController: UIViewController {
11 +
12 + @IBOutlet weak var tableView: UITableView!
13 +
14 + public var sectionData: SectionModel?
15 +
16 + public override func viewDidLoad() {
17 + super.viewDidLoad()
18 +
19 + self.navigationController?.setNavigationBarHidden(false, animated: false)
20 + setBackButton()
21 +
22 + setupTableView()
23 + }
24 +
25 + private func setupTableView() {
26 + tableView.delegate = self
27 + tableView.dataSource = self
28 +
29 + tableView.separatorStyle = .none
30 + tableView.backgroundColor = .white
31 +
32 + tableView.register(UINib(nibName: "CategoryOffersHeaderTableViewCell", bundle: Bundle.frameworkResourceBundle), forCellReuseIdentifier: "CategoryOffersHeaderTableViewCell")
33 + tableView.register(UINib(nibName: "CategoryOffersGridTableViewCell", bundle: Bundle.frameworkResourceBundle), forCellReuseIdentifier: "CategoryOffersGridTableViewCell")
34 + }
35 +}
36 +
37 +extension CategoryOffersViewController: UITableViewDelegate, UITableViewDataSource {
38 + public func numberOfSections(in tableView: UITableView) -> Int {
39 + return 1
40 + }
41 +
42 + public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
43 + return 2 // Header + Grid
44 + }
45 +
46 + public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
47 + if indexPath.row == 0 {
48 + let cell = tableView.dequeueReusableCell(withIdentifier: "CategoryOffersHeaderTableViewCell", for: indexPath) as! CategoryOffersHeaderTableViewCell
49 + if let title = sectionData?.title {
50 + cell.headerLabel.text = title
51 + }
52 + return cell
53 + } else {
54 + let cell = tableView.dequeueReusableCell(withIdentifier: "CategoryOffersGridTableViewCell", for: indexPath) as! CategoryOffersGridTableViewCell
55 + cell.configureCell(with: sectionData, parentViewController: self)
56 + return cell
57 + }
58 + }
59 +
60 + public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
61 + if indexPath.row == 0 {
62 + return UITableView.automaticDimension
63 + } else {
64 + return UITableView.automaticDimension // Or a calculated height depending on content
65 + }
66 + }
67 +}
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="24506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3 + <device id="retina6_12" orientation="portrait" appearance="light"/>
4 + <dependencies>
5 + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24504"/>
6 + <capability name="Safe area layout guides" minToolsVersion="9.0"/>
7 + <capability name="System colors in document resources" minToolsVersion="11.0"/>
8 + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9 + </dependencies>
10 + <objects>
11 + <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CategoryOffersViewController" customModule="SwiftWarplyFramework" customModuleProvider="target">
12 + <connections>
13 + <outlet property="tableView" destination="xJ1-8b-ZQa" id="zFv-3o-xR8"/>
14 + <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
15 + </connections>
16 + </placeholder>
17 + <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
18 + <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
19 + <rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
20 + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
21 + <subviews>
22 + <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="xJ1-8b-ZQa">
23 + <rect key="frame" x="0.0" y="59" width="393" height="759"/>
24 + <color key="backgroundColor" systemColor="systemBackgroundColor"/>
25 + </tableView>
26 + </subviews>
27 + <viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
28 + <color key="backgroundColor" systemColor="systemBackgroundColor"/>
29 + <constraints>
30 + <constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="xJ1-8b-ZQa" secondAttribute="bottom" id="D5R-hF-Lz4"/>
31 + <constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="xJ1-8b-ZQa" secondAttribute="trailing" id="LhI-M4-0eB"/>
32 + <constraint firstItem="xJ1-8b-ZQa" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="O6f-Kk-Ufe"/>
33 + <constraint firstItem="xJ1-8b-ZQa" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="aT8-Zg-Kk4"/>
34 + </constraints>
35 + <point key="canvasLocation" x="65" y="154"/>
36 + </view>
37 + </objects>
38 + <resources>
39 + <systemColor name="systemBackgroundColor">
40 + <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
41 + </systemColor>
42 + </resources>
43 +</document>