Manos Chorianopoulos

CategoryOffersViewController part1

......@@ -57,7 +57,11 @@ let package = Package(
.process("cells/MyRewardsOfferCollectionViewCell/MyRewardsOfferCollectionViewCell.xib"),
.process("cells/MyRewardsBannerOffersScrollTableViewCell/MyRewardsBannerOffersScrollTableViewCell.xib"),
.process("screens/MyCouponsViewController/MyCouponsViewController.xib"),
.process("cells/MyCouponsHeaderTableViewCell/MyCouponsHeaderTableViewCell.xib")
.process("cells/MyCouponsHeaderTableViewCell/MyCouponsHeaderTableViewCell.xib"),
.process("cells/CategoryOfferCollectionViewCell/CategoryOfferCollectionViewCell.xib"),
.process("cells/CategoryOffersHeaderTableViewCell/CategoryOffersHeaderTableViewCell.xib"),
.process("cells/CategoryOffersGridTableViewCell/CategoryOffersGridTableViewCell.xib"),
.process("screens/CategoryOffersViewController/CategoryOffersViewController.xib")
]
),
]
......
//
// CategoryOfferCollectionViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 19/3/26.
//
import UIKit
@objc(CategoryOfferCollectionViewCell)
public class CategoryOfferCollectionViewCell: UICollectionViewCell {
public override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="CategoryOfferCollectionViewCell" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
</collectionViewCell>
</objects>
</document>
//
// CategoryOffersGridTableViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 19/3/26.
//
import UIKit
@objc(CategoryOffersGridTableViewCell)
public class CategoryOffersGridTableViewCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var collectionViewHeightConstraint: NSLayoutConstraint!
var data: SectionModel?
weak var parentViewController: UIViewController?
public override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
setupCollectionView()
}
public override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
private func setupCollectionView() {
collectionView.delegate = self
collectionView.dataSource = self
collectionView.backgroundColor = .clear
collectionView.isScrollEnabled = false // Scroll is handled by the outer TableView
XIBLoader.registerCollectionViewCell(
collectionView,
cellClass: UICollectionViewCell.self,
nibName: "CategoryOfferCollectionViewCell",
identifier: "CategoryOfferCollectionViewCell"
)
if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
layout.minimumInteritemSpacing = 16
layout.minimumLineSpacing = 16
layout.sectionInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
}
}
func configureCell(with sectionData: SectionModel?, parentViewController: UIViewController?) {
self.data = sectionData
self.parentViewController = parentViewController
collectionView.reloadData()
// Use layoutIfNeeded to calculate content size and set the height constraint
collectionView.layoutIfNeeded()
let height = collectionView.collectionViewLayout.collectionViewContentSize.height
collectionViewHeightConstraint.constant = height
}
}
extension CategoryOffersGridTableViewCell: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
public func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.data?.itemCount ?? 0
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CategoryOfferCollectionViewCell", for: indexPath) as! CategoryOfferCollectionViewCell
guard let data = self.data,
let items = data.items,
indexPath.row < items.count else {
return cell
}
switch data.itemType {
case .couponSets:
if let couponSet = items[indexPath.row] as? CouponSetItemModel {
cell.configureCell(data: couponSet)
}
default:
if let offer = items[indexPath.row] as? OfferModel {
cell.configureCell(data: offer)
}
}
return cell
}
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let data = self.data,
let items = data.items,
indexPath.row < items.count else {
return
}
// Handle navigation based on item type
switch data.itemType {
case .couponSets:
if let couponSet = items[indexPath.row] as? CouponSetItemModel {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.frameworkResourceBundle)
if let vc = storyboard.instantiateViewController(withIdentifier: "CouponsetViewController") as? CouponsetViewController {
vc.couponset = couponSet
self.parentViewController?.navigationController?.pushViewController(vc, animated: true)
}
}
default:
if let offer = items[indexPath.row] as? OfferModel {
// Determine if it's a campaign or other offer and navigate appropriately
// (Using existing patterns from MyRewardsViewController)
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.frameworkResourceBundle)
if let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as? CampaignViewController {
vc.campaignUrl = offer.campaignUrl // Assuming OfferModel has this
self.parentViewController?.navigationController?.pushViewController(vc, animated: true)
}
}
}
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// Calculate width for 2 columns with spacing
let padding: CGFloat = 16 * 3 // left + middle + right padding
let availableWidth = collectionView.frame.width - padding
let itemWidth = availableWidth / 2
// Adjust height as needed based on design (aspect ratio or fixed)
let itemHeight = itemWidth * 1.3 // Approximation from screenshot
return CGSize(width: itemWidth, height: itemHeight)
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="CategoryOffersGridTableViewCell" customModule="SwiftWarplyFramework" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="200"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="200"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="6q1-8v-H6d">
<rect key="frame" x="0.0" y="0.0" width="320" height="200"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="200" id="E2S-dE-z3n"/>
</constraints>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="g5b-eS-1Jq">
<size key="itemSize" width="128" height="128"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
</collectionView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="6q1-8v-H6d" secondAttribute="bottom" id="D01-9c-29T"/>
<constraint firstAttribute="trailing" secondItem="6q1-8v-H6d" secondAttribute="trailing" id="D3B-e1-2jZ"/>
<constraint firstItem="6q1-8v-H6d" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="O63-T2-B2y"/>
<constraint firstItem="6q1-8v-H6d" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="YjY-W1-T3M"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<connections>
<outlet property="collectionView" destination="6q1-8v-H6d" id="N8a-1a-1yO"/>
<outlet property="collectionViewHeightConstraint" destination="E2S-dE-z3n" id="A8b-Zc-3rZ"/>
</connections>
<point key="canvasLocation" x="141" y="20"/>
</tableViewCell>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
//
// CategoryOffersHeaderTableViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 19/3/26.
//
import UIKit
@objc(CategoryOffersHeaderTableViewCell)
public class CategoryOffersHeaderTableViewCell: UITableViewCell {
@IBOutlet weak var headerLabel: UILabel!
@IBOutlet weak var filtersView: UIView!
@IBOutlet weak var filtersLabel: UILabel!
@IBOutlet weak var filtersImage: UIImageView!
@IBOutlet weak var mapView: UIView!
@IBOutlet weak var mapImage: UIImageView!
public override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.headerLabel.text = ""
self.headerLabel.font = UIFont(name: "PingLCG-Bold", size: 24)
self.headerLabel.textColor = UIColor(rgb: 0x0D1B29)
self.headerLabel.frame.size.width = self.headerLabel.intrinsicContentSize.width
self.headerLabel.frame.size.height = self.headerLabel.intrinsicContentSize.height
self.filtersView.backgroundColor = UIColor(rgb: 0xF1F2F4)
self.filtersView.layer.cornerRadius = 16 // Assuming height is 32 or similar based on standard chip design
self.filtersView.layer.masksToBounds = true
self.filtersLabel.text = "Αναζήτηση"
self.filtersLabel.font = UIFont(name: "PingLCG-Regular", size: 16)
self.filtersLabel.textColor = UIColor(rgb: 0x000F1E)
self.filtersLabel.frame.size.width = self.filtersLabel.intrinsicContentSize.width
self.filtersLabel.frame.size.height = self.filtersLabel.intrinsicContentSize.height
self.filtersImage.image = UIImage(named: "filter", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
if mapView != nil {
self.mapView.backgroundColor = UIColor(rgb: 0xF1F2F4)
self.mapView.layer.cornerRadius = 22 // Assuming height is 44
self.mapView.layer.masksToBounds = true
}
if mapImage != nil {
self.mapImage.image = UIImage(named: "ic_map", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
}
}
public override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
//
// CategoryOffersViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 19/3/26.
//
import UIKit
@objc public class CategoryOffersViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
public var sectionData: SectionModel?
public override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.setNavigationBarHidden(false, animated: false)
setBackButton()
setupTableView()
}
private func setupTableView() {
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .none
tableView.backgroundColor = .white
tableView.register(UINib(nibName: "CategoryOffersHeaderTableViewCell", bundle: Bundle.frameworkResourceBundle), forCellReuseIdentifier: "CategoryOffersHeaderTableViewCell")
tableView.register(UINib(nibName: "CategoryOffersGridTableViewCell", bundle: Bundle.frameworkResourceBundle), forCellReuseIdentifier: "CategoryOffersGridTableViewCell")
}
}
extension CategoryOffersViewController: UITableViewDelegate, UITableViewDataSource {
public func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2 // Header + Grid
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "CategoryOffersHeaderTableViewCell", for: indexPath) as! CategoryOffersHeaderTableViewCell
if let title = sectionData?.title {
cell.headerLabel.text = title
}
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "CategoryOffersGridTableViewCell", for: indexPath) as! CategoryOffersGridTableViewCell
cell.configureCell(with: sectionData, parentViewController: self)
return cell
}
}
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0 {
return UITableView.automaticDimension
} else {
return UITableView.automaticDimension // Or a calculated height depending on content
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CategoryOffersViewController" customModule="SwiftWarplyFramework" customModuleProvider="target">
<connections>
<outlet property="tableView" destination="xJ1-8b-ZQa" id="zFv-3o-xR8"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<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">
<rect key="frame" x="0.0" y="59" width="393" height="759"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</tableView>
</subviews>
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="xJ1-8b-ZQa" secondAttribute="bottom" id="D5R-hF-Lz4"/>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="xJ1-8b-ZQa" secondAttribute="trailing" id="LhI-M4-0eB"/>
<constraint firstItem="xJ1-8b-ZQa" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="O6f-Kk-Ufe"/>
<constraint firstItem="xJ1-8b-ZQa" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="aT8-Zg-Kk4"/>
</constraints>
<point key="canvasLocation" x="65" y="154"/>
</view>
</objects>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>