Showing
3 changed files
with
134 additions
and
6 deletions
No preview for this file type
| ... | @@ -10,6 +10,11 @@ import UIKit | ... | @@ -10,6 +10,11 @@ import UIKit |
| 10 | 10 | ||
| 11 | @objc public class MyRewardsViewController: UIViewController { | 11 | @objc public class MyRewardsViewController: UIViewController { |
| 12 | @IBOutlet weak var tableView: UITableView! | 12 | @IBOutlet weak var tableView: UITableView! |
| 13 | + @IBOutlet weak var myCouponsView: UIView! | ||
| 14 | + @IBOutlet weak var myCouponsLabel: UILabel! | ||
| 15 | + @IBOutlet weak var myCouponsCountView: UIView! | ||
| 16 | + @IBOutlet weak var myCouponsCountLabel: UILabel! | ||
| 17 | + @IBOutlet weak var myCouponsButton: UIButton! | ||
| 13 | 18 | ||
| 14 | // MARK: - Initializers | 19 | // MARK: - Initializers |
| 15 | public convenience init() { | 20 | public convenience init() { |
| ... | @@ -55,6 +60,8 @@ import UIKit | ... | @@ -55,6 +60,8 @@ import UIKit |
| 55 | // Profile data | 60 | // Profile data |
| 56 | var profileModel: ProfileModel? | 61 | var profileModel: ProfileModel? |
| 57 | var profileSection: SectionModel? | 62 | var profileSection: SectionModel? |
| 63 | + | ||
| 64 | + var activeCoupons: [CouponItemModel] = [] | ||
| 58 | 65 | ||
| 59 | public override func viewDidLoad() { | 66 | public override func viewDidLoad() { |
| 60 | super.viewDidLoad() | 67 | super.viewDidLoad() |
| ... | @@ -82,8 +89,40 @@ import UIKit | ... | @@ -82,8 +89,40 @@ import UIKit |
| 82 | loadProfile() // Load Profile | 89 | loadProfile() // Load Profile |
| 83 | loadCampaigns() // Load campaigns | 90 | loadCampaigns() // Load campaigns |
| 84 | loadCouponSets() // Load couponsets | 91 | loadCouponSets() // Load couponsets |
| 92 | + loadCoupons() | ||
| 93 | + | ||
| 94 | + setupUI() | ||
| 85 | } | 95 | } |
| 86 | 96 | ||
| 97 | + private func setupUI() { | ||
| 98 | + | ||
| 99 | + self.myCouponsView.backgroundColor = UIColor(rgb: 0x8F8F8F) | ||
| 100 | + self.myCouponsView.layer.cornerRadius = 28 | ||
| 101 | + self.myCouponsView.layer.masksToBounds = true | ||
| 102 | + | ||
| 103 | + self.myCouponsCountView.layer.borderWidth = 2.0 | ||
| 104 | + self.myCouponsCountView.layer.borderColor = UIColor(rgb: 0xFFFFFF).cgColor | ||
| 105 | + self.myCouponsCountView.layer.cornerRadius = 10.5 | ||
| 106 | + | ||
| 107 | + self.myCouponsLabel.text = "My coupons" | ||
| 108 | + self.myCouponsLabel.font = UIFont(name: "PingLCG-Regular", size: 15) | ||
| 109 | + self.myCouponsLabel.textColor = UIColor(rgb: 0xFFFFFF) | ||
| 110 | + self.myCouponsLabel.frame.size.width = self.myCouponsLabel.intrinsicContentSize.width | ||
| 111 | + self.myCouponsLabel.frame.size.height = self.myCouponsLabel.intrinsicContentSize.height | ||
| 112 | + | ||
| 113 | + self.myCouponsCountLabel.text = "0" | ||
| 114 | + self.myCouponsCountLabel.font = UIFont(name: "PingLCG-Bold", size: 14) | ||
| 115 | + self.myCouponsCountLabel.textColor = UIColor(rgb: 0xFFFFFF) | ||
| 116 | + self.myCouponsCountLabel.frame.size.width = self.myCouponsCountLabel.intrinsicContentSize.width | ||
| 117 | + self.myCouponsCountLabel.frame.size.height = self.myCouponsCountLabel.intrinsicContentSize.height | ||
| 118 | + | ||
| 119 | + self.myCouponsButton.addTarget(self, action: #selector(myCouponsButtonTapped), for: .touchUpInside) | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + @objc private func myCouponsButtonTapped() { | ||
| 123 | + // TODO: open CouponsVC | ||
| 124 | + } | ||
| 125 | + | ||
| 87 | // NEW: Safe XIB registration method | 126 | // NEW: Safe XIB registration method |
| 88 | private func registerTableViewCells() { | 127 | private func registerTableViewCells() { |
| 89 | let cellConfigs = [ | 128 | let cellConfigs = [ |
| ... | @@ -219,6 +258,38 @@ import UIKit | ... | @@ -219,6 +258,38 @@ import UIKit |
| 219 | } | 258 | } |
| 220 | } | 259 | } |
| 221 | 260 | ||
| 261 | + // MARK: - Coupons Loading | ||
| 262 | + private func loadCoupons() { | ||
| 263 | + WarplySDK.shared.getCouponsUniversal({ [weak self] couponsData in | ||
| 264 | + guard let self = self else { return } | ||
| 265 | + | ||
| 266 | + if let coupons = couponsData { | ||
| 267 | + print("✅ [MyRewardsVC] Fetched \(coupons.count) coupons") | ||
| 268 | + | ||
| 269 | + let tempActive = coupons.filter { $0.status == 1 } | ||
| 270 | + self.activeCoupons = tempActive | ||
| 271 | + self.myCouponsCountLabel.text = String(tempActive.count) | ||
| 272 | + self.myCouponsCountLabel.frame.size.width = self.myCouponsCountLabel.intrinsicContentSize.width | ||
| 273 | + self.myCouponsCountLabel.frame.size.height = self.myCouponsCountLabel.intrinsicContentSize.height | ||
| 274 | + | ||
| 275 | + // Debug: Print coupon statuses | ||
| 276 | + let activeCount = tempActive.count | ||
| 277 | + let redeemedCount = coupons.filter { $0.status == 0 }.count | ||
| 278 | + let expiredCount = coupons.filter { $0.status == -1 }.count | ||
| 279 | + print(" Active: \(activeCount), Redeemed: \(redeemedCount), Expired: \(expiredCount)") | ||
| 280 | + } else { | ||
| 281 | + self.activeCoupons = [] | ||
| 282 | + print("⚠️ [MyRewardsVC] No coupons received") | ||
| 283 | + } | ||
| 284 | + | ||
| 285 | + }, failureCallback: { [weak self] errorCode in | ||
| 286 | + guard let self = self else { return } | ||
| 287 | + | ||
| 288 | + print("❌ [MyRewardsVC] Failed to fetch coupons, error: \(errorCode)") | ||
| 289 | + self.activeCoupons = [] | ||
| 290 | + }) | ||
| 291 | + } | ||
| 292 | + | ||
| 222 | // MARK: - Merchants Loading | 293 | // MARK: - Merchants Loading |
| 223 | private func loadMerchants() { | 294 | private func loadMerchants() { |
| 224 | // Load merchants from WarplySDK (using enhanced getMerchants method) | 295 | // Load merchants from WarplySDK (using enhanced getMerchants method) | ... | ... |
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23094" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> | 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"/> | 3 | <device id="retina6_12" orientation="portrait" appearance="light"/> |
| 4 | <dependencies> | 4 | <dependencies> |
| 5 | - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23084"/> | 5 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24504"/> |
| 6 | <capability name="Safe area layout guides" minToolsVersion="9.0"/> | 6 | <capability name="Safe area layout guides" minToolsVersion="9.0"/> |
| 7 | <capability name="System colors in document resources" minToolsVersion="11.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"/> | 8 | <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> |
| ... | @@ -10,6 +10,11 @@ | ... | @@ -10,6 +10,11 @@ |
| 10 | <objects> | 10 | <objects> |
| 11 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MyRewardsViewController"> | 11 | <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MyRewardsViewController"> |
| 12 | <connections> | 12 | <connections> |
| 13 | + <outlet property="myCouponsButton" destination="x30-Ow-4au" id="9Sh-x9-7A4"/> | ||
| 14 | + <outlet property="myCouponsCountLabel" destination="184-6W-Qqw" id="uUt-b8-tei"/> | ||
| 15 | + <outlet property="myCouponsCountView" destination="ffh-5P-v7j" id="GBc-E2-NHG"/> | ||
| 16 | + <outlet property="myCouponsLabel" destination="MIc-50-FWF" id="euF-vG-OHc"/> | ||
| 17 | + <outlet property="myCouponsView" destination="Y7D-E2-Apc" id="Ta5-Py-rpH"/> | ||
| 13 | <outlet property="tableView" destination="2it-5M-CR6" id="uM3-ZJ-zKB"/> | 18 | <outlet property="tableView" destination="2it-5M-CR6" id="uM3-ZJ-zKB"/> |
| 14 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | 19 | <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> |
| 15 | </connections> | 20 | </connections> |
| ... | @@ -20,10 +25,10 @@ | ... | @@ -20,10 +25,10 @@ |
| 20 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | 25 | <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> |
| 21 | <subviews> | 26 | <subviews> |
| 22 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="scR-yg-okd" userLabel="Main View"> | 27 | <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="scR-yg-okd" userLabel="Main View"> |
| 23 | - <rect key="frame" x="0.0" y="59" width="393" height="793"/> | 28 | + <rect key="frame" x="0.0" y="118" width="393" height="734"/> |
| 24 | <subviews> | 29 | <subviews> |
| 25 | <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" estimatedSectionHeaderHeight="-1" sectionFooterHeight="28" estimatedSectionFooterHeight="-1" contentViewInsetsToSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2it-5M-CR6"> | 30 | <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" estimatedSectionHeaderHeight="-1" sectionFooterHeight="28" estimatedSectionFooterHeight="-1" contentViewInsetsToSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2it-5M-CR6"> |
| 26 | - <rect key="frame" x="0.0" y="0.0" width="393" height="793"/> | 31 | + <rect key="frame" x="0.0" y="0.0" width="393" height="734"/> |
| 27 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | 32 | <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> |
| 28 | <color key="separatorColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | 33 | <color key="separatorColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> |
| 29 | <color key="sectionIndexBackgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | 34 | <color key="sectionIndexBackgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> |
| ... | @@ -32,18 +37,70 @@ | ... | @@ -32,18 +37,70 @@ |
| 32 | <outlet property="delegate" destination="-1" id="tmq-4b-xNt"/> | 37 | <outlet property="delegate" destination="-1" id="tmq-4b-xNt"/> |
| 33 | </connections> | 38 | </connections> |
| 34 | </tableView> | 39 | </tableView> |
| 40 | + <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Y7D-E2-Apc" userLabel="MyCouponsView"> | ||
| 41 | + <rect key="frame" x="243" y="655" width="142" height="61"/> | ||
| 42 | + <subviews> | ||
| 43 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MIc-50-FWF" userLabel="MyCouponsLabel"> | ||
| 44 | + <rect key="frame" x="18" y="20" width="42" height="21"/> | ||
| 45 | + <fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
| 46 | + <nil key="textColor"/> | ||
| 47 | + <nil key="highlightedColor"/> | ||
| 48 | + </label> | ||
| 49 | + <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ffh-5P-v7j" userLabel="MyCouponsCountView"> | ||
| 50 | + <rect key="frame" x="72" y="20" width="52" height="21"/> | ||
| 51 | + <subviews> | ||
| 52 | + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="184-6W-Qqw" userLabel="MyCouponsCountLabel"> | ||
| 53 | + <rect key="frame" x="5" y="0.0" width="42" height="21"/> | ||
| 54 | + <fontDescription key="fontDescription" type="system" pointSize="17"/> | ||
| 55 | + <nil key="textColor"/> | ||
| 56 | + <nil key="highlightedColor"/> | ||
| 57 | + </label> | ||
| 58 | + </subviews> | ||
| 59 | + <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
| 60 | + <constraints> | ||
| 61 | + <constraint firstItem="184-6W-Qqw" firstAttribute="centerY" secondItem="ffh-5P-v7j" secondAttribute="centerY" id="2qJ-Il-0xH"/> | ||
| 62 | + <constraint firstAttribute="trailing" secondItem="184-6W-Qqw" secondAttribute="trailing" constant="5" id="Jie-gl-D9e"/> | ||
| 63 | + <constraint firstItem="184-6W-Qqw" firstAttribute="leading" secondItem="ffh-5P-v7j" secondAttribute="leading" constant="5" id="e4u-Wg-ddP"/> | ||
| 64 | + <constraint firstAttribute="height" constant="21" id="mVE-b7-QOY"/> | ||
| 65 | + </constraints> | ||
| 66 | + </view> | ||
| 67 | + <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="x30-Ow-4au" userLabel="MyCouponsButton"> | ||
| 68 | + <rect key="frame" x="0.0" y="0.0" width="142" height="61"/> | ||
| 69 | + <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
| 70 | + <state key="normal" title="Button"/> | ||
| 71 | + <buttonConfiguration key="configuration" style="plain" title="Button"> | ||
| 72 | + <color key="baseForegroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
| 73 | + </buttonConfiguration> | ||
| 74 | + </button> | ||
| 75 | + </subviews> | ||
| 76 | + <color key="backgroundColor" systemColor="systemBackgroundColor"/> | ||
| 77 | + <constraints> | ||
| 78 | + <constraint firstItem="MIc-50-FWF" firstAttribute="centerY" secondItem="Y7D-E2-Apc" secondAttribute="centerY" id="2A0-F1-5oa"/> | ||
| 79 | + <constraint firstAttribute="height" constant="61" id="8ip-Sd-Eat"/> | ||
| 80 | + <constraint firstItem="x30-Ow-4au" firstAttribute="top" secondItem="Y7D-E2-Apc" secondAttribute="top" id="9m9-e6-2jB"/> | ||
| 81 | + <constraint firstAttribute="bottom" secondItem="x30-Ow-4au" secondAttribute="bottom" id="GZ5-8q-abu"/> | ||
| 82 | + <constraint firstItem="ffh-5P-v7j" firstAttribute="leading" secondItem="MIc-50-FWF" secondAttribute="trailing" constant="12" id="JHH-GK-KXp"/> | ||
| 83 | + <constraint firstAttribute="trailing" secondItem="x30-Ow-4au" secondAttribute="trailing" id="S8y-5e-24n"/> | ||
| 84 | + <constraint firstItem="x30-Ow-4au" firstAttribute="leading" secondItem="Y7D-E2-Apc" secondAttribute="leading" id="a7C-iB-rAx"/> | ||
| 85 | + <constraint firstItem="ffh-5P-v7j" firstAttribute="centerY" secondItem="Y7D-E2-Apc" secondAttribute="centerY" id="bvD-jp-OA5"/> | ||
| 86 | + <constraint firstItem="MIc-50-FWF" firstAttribute="leading" secondItem="Y7D-E2-Apc" secondAttribute="leading" constant="18" id="jmW-QS-k6q"/> | ||
| 87 | + <constraint firstAttribute="trailing" secondItem="ffh-5P-v7j" secondAttribute="trailing" constant="18" id="wal-Ti-h5T"/> | ||
| 88 | + </constraints> | ||
| 89 | + </view> | ||
| 35 | </subviews> | 90 | </subviews> |
| 36 | - <color key="backgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.94901960780000005" alpha="1" colorSpace="calibratedRGB"/> | 91 | + <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> |
| 37 | <constraints> | 92 | <constraints> |
| 38 | <constraint firstItem="2it-5M-CR6" firstAttribute="top" secondItem="scR-yg-okd" secondAttribute="top" id="8Qy-L0-5ab"/> | 93 | <constraint firstItem="2it-5M-CR6" firstAttribute="top" secondItem="scR-yg-okd" secondAttribute="top" id="8Qy-L0-5ab"/> |
| 39 | <constraint firstAttribute="trailing" secondItem="2it-5M-CR6" secondAttribute="trailing" id="AXe-zP-ef8"/> | 94 | <constraint firstAttribute="trailing" secondItem="2it-5M-CR6" secondAttribute="trailing" id="AXe-zP-ef8"/> |
| 40 | <constraint firstItem="2it-5M-CR6" firstAttribute="leading" secondItem="scR-yg-okd" secondAttribute="leading" id="NeU-gh-skU"/> | 95 | <constraint firstItem="2it-5M-CR6" firstAttribute="leading" secondItem="scR-yg-okd" secondAttribute="leading" id="NeU-gh-skU"/> |
| 41 | <constraint firstAttribute="bottom" secondItem="2it-5M-CR6" secondAttribute="bottom" id="bpx-U5-A8r"/> | 96 | <constraint firstAttribute="bottom" secondItem="2it-5M-CR6" secondAttribute="bottom" id="bpx-U5-A8r"/> |
| 97 | + <constraint firstAttribute="trailing" secondItem="Y7D-E2-Apc" secondAttribute="trailing" constant="8" id="piU-mj-9Ew"/> | ||
| 98 | + <constraint firstAttribute="bottom" secondItem="Y7D-E2-Apc" secondAttribute="bottom" constant="18" id="rep-DE-xIt"/> | ||
| 42 | </constraints> | 99 | </constraints> |
| 43 | </view> | 100 | </view> |
| 44 | </subviews> | 101 | </subviews> |
| 45 | <viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/> | 102 | <viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/> |
| 46 | - <color key="backgroundColor" systemColor="systemBackgroundColor"/> | 103 | + <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> |
| 47 | <constraints> | 104 | <constraints> |
| 48 | <constraint firstItem="scR-yg-okd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="Nwv-jZ-0HT"/> | 105 | <constraint firstItem="scR-yg-okd" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="Nwv-jZ-0HT"/> |
| 49 | <constraint firstItem="scR-yg-okd" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="OFK-BH-zlp"/> | 106 | <constraint firstItem="scR-yg-okd" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="OFK-BH-zlp"/> | ... | ... |
-
Please register or login to post a comment