Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2024-10-15 15:32:51 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
514d24b2e891a5ccccd8fe72722c93dd76f9b444
514d24b2
1 parent
1cc12977
add SM Coupons to UnifiedCouponsViewController
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
468 additions
and
25 deletions
SwiftWarplyFramework/Pods/Pods.xcodeproj/xcuserdata/manos.xcuserdatad/xcschemes/xcschememanagement.plist
SwiftWarplyFramework/SwiftWarplyFramework.xcodeproj/xcuserdata/manos.xcuserdatad/xcschemes/xcschememanagement.plist
SwiftWarplyFramework/SwiftWarplyFramework.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
SwiftWarplyFramework/SwiftWarplyFramework/CouponsTableViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/Main.storyboard
SwiftWarplyFramework/SwiftWarplyFramework/UnifiedCouponsViewController.swift
SwiftWarplyFramework/Pods/Pods.xcodeproj/xcuserdata/manos.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
514d24b
...
...
@@ -7,7 +7,7 @@
<key>
Pods-SwiftWarplyFramework.xcscheme_^#shared#^_
</key>
<dict>
<key>
orderHint
</key>
<integer>
1
</integer>
<integer>
0
</integer>
</dict>
</dict>
</dict>
...
...
SwiftWarplyFramework/SwiftWarplyFramework.xcodeproj/xcuserdata/manos.xcuserdatad/xcschemes/xcschememanagement.plist
View file @
514d24b
...
...
@@ -7,7 +7,7 @@
<key>
SwiftWarplyFramework.xcscheme_^#shared#^_
</key>
<dict>
<key>
orderHint
</key>
<integer>
0
</integer>
<integer>
1
</integer>
</dict>
</dict>
</dict>
...
...
SwiftWarplyFramework/SwiftWarplyFramework.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
View file @
514d24b
No preview for this file type
SwiftWarplyFramework/SwiftWarplyFramework/CouponsTableViewCell.swift
View file @
514d24b
...
...
@@ -20,12 +20,32 @@ import UIKit
@IBOutlet
weak
var
expirationRedImage
:
UIImageView
!
@IBOutlet
weak
var
expirationRedLabel
:
UILabel
!
// Variables for the view, image, and button
var
selectView
:
UIView
!
var
selectImageView
:
UIImageView
!
var
selectButton
:
UIButton
!
// Boolean to track if the selectView should be visible
var
isSelectViewVisible
:
Bool
=
false
{
didSet
{
selectView
.
isHidden
=
!
isSelectViewVisible
}
}
// Boolean to track the selection state of the cell
var
isSelectedCell
:
Bool
=
false
{
didSet
{
updateSelectionState
()
}
}
// Action closure for button tap inside the cell
var
selectButtonAction
:
(()
->
Void
)?
var
postImageURL
:
String
?
{
didSet
{
if
let
url
=
postImageURL
{
// TODO: DELETE LOGS
print
(
"=== postImageURL: "
,
url
)
self
.
couponImage
.
image
=
UIImage
()
// UIImage(named: "loading")
UIImage
.
loadImageUsingCacheWithUrlString
(
url
)
{
image
in
...
...
@@ -49,6 +69,8 @@ import UIKit
couponBgImage
.
image
=
UIImage
(
named
:
"coupon_bg_2"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
borderView
.
addDashedBorderVertical
(
color
:
UIColor
(
red
:
0.62
,
green
:
0.62
,
blue
:
0.61
,
alpha
:
1.00
),
width
:
1.0
,
height
:
110.0
)
setupSelectButton
()
}
public
override
func
setSelected
(
_
selected
:
Bool
,
animated
:
Bool
)
{
...
...
@@ -64,6 +86,69 @@ import UIKit
contentView
.
frame
=
contentView
.
frame
.
inset
(
by
:
margins
)
}
// Setup Select Button UI and layout
func
setupSelectButton
()
{
// Create the container view (selectView)
selectView
=
UIView
()
selectView
.
translatesAutoresizingMaskIntoConstraints
=
false
contentView
.
addSubview
(
selectView
)
// Set selectView constraints
NSLayoutConstraint
.
activate
([
selectView
.
widthAnchor
.
constraint
(
equalToConstant
:
26
),
selectView
.
heightAnchor
.
constraint
(
equalToConstant
:
26
),
selectView
.
topAnchor
.
constraint
(
equalTo
:
contentView
.
topAnchor
,
constant
:
6
),
selectView
.
trailingAnchor
.
constraint
(
equalTo
:
contentView
.
trailingAnchor
,
constant
:
-
16
)
])
// Create the UIImageView inside selectView
selectImageView
=
UIImageView
()
selectImageView
.
contentMode
=
.
scaleAspectFit
selectImageView
.
translatesAutoresizingMaskIntoConstraints
=
false
selectView
.
addSubview
(
selectImageView
)
// Set imageView constraints to match the size of the selectView
NSLayoutConstraint
.
activate
([
selectImageView
.
leadingAnchor
.
constraint
(
equalTo
:
selectView
.
leadingAnchor
),
selectImageView
.
trailingAnchor
.
constraint
(
equalTo
:
selectView
.
trailingAnchor
),
selectImageView
.
topAnchor
.
constraint
(
equalTo
:
selectView
.
topAnchor
),
selectImageView
.
bottomAnchor
.
constraint
(
equalTo
:
selectView
.
bottomAnchor
)
])
// Create the transparent button on top of the imageView
selectButton
=
UIButton
(
type
:
.
custom
)
selectButton
.
backgroundColor
=
.
clear
// Make the button transparent
selectButton
.
translatesAutoresizingMaskIntoConstraints
=
false
selectButton
.
addTarget
(
self
,
action
:
#selector(
selectButtonTapped
)
,
for
:
.
touchUpInside
)
selectView
.
addSubview
(
selectButton
)
// Set button constraints to match the size of the selectView
NSLayoutConstraint
.
activate
([
selectButton
.
leadingAnchor
.
constraint
(
equalTo
:
selectView
.
leadingAnchor
),
selectButton
.
trailingAnchor
.
constraint
(
equalTo
:
selectView
.
trailingAnchor
),
selectButton
.
topAnchor
.
constraint
(
equalTo
:
selectView
.
topAnchor
),
selectButton
.
bottomAnchor
.
constraint
(
equalTo
:
selectView
.
bottomAnchor
)
])
// Initially hide the selectView (selectView)
selectView
.
isHidden
=
true
}
// Button action handler
@objc
func
selectButtonTapped
()
{
// Trigger the action closure when the button is pressed
selectButtonAction
?()
}
// Update the cell's appearance based on selection state
func
updateSelectionState
()
{
// Update the image based on the new state
if
(
isSelectedCell
)
{
selectImageView
.
image
=
UIImage
(
named
:
"circle_checked"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
// Selected image
}
else
{
selectImageView
.
image
=
UIImage
(
named
:
"circle_unchecked"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
// Unselected image
}
}
func
configureCell
(
coupon
:
swiftApi
.
CouponItemModel
)
{
// COUPONSET: desc, img_preview, name, terms, merchant_uuid, discount_type, final_price
...
...
@@ -240,4 +325,22 @@ import UIKit
}
// Configure the cell with visibility of the selectView, a selected state, and select Button Action
func
showSelectButton
(
isSelectViewVisible
:
Bool
,
isSelected
:
Bool
,
buttonAction
:
@escaping
()
->
Void
)
{
self
.
isSelectViewVisible
=
isSelectViewVisible
self
.
isSelectedCell
=
isSelected
self
.
selectButtonAction
=
buttonAction
if
(
isSelected
)
{
couponBgImage
.
image
=
UIImage
(
named
:
"coupon_bg_2_selected"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
}
else
{
couponBgImage
.
image
=
UIImage
(
named
:
"coupon_bg_2"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
}
// Set nameLabel constraints to not overlap selectView
NSLayoutConstraint
.
activate
([
nameLabel
.
trailingAnchor
.
constraint
(
equalTo
:
selectView
.
leadingAnchor
,
constant
:
-
5
)
])
}
}
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Main.storyboard
View file @
514d24b
...
...
@@ -4651,13 +4651,14 @@
<imageView
clipsSubviews=
"YES"
userInteractionEnabled=
"NO"
contentMode=
"scaleToFill"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
image=
"coupons_scrollview_dark"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"QKV-Lk-E2a"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"414"
height=
"848"
/>
</imageView>
<tableView
clipsSubviews=
"YES"
contentMode=
"scaleToFill"
alwaysBounceVertical=
"YES"
dataMode=
"prototypes"
style=
"
plain"
separatorStyle=
"none"
rowHeight=
"-1"
estimatedRowHeight=
"-1"
sectionHeaderHeight=
"-1"
estimatedSectionHeaderHeight=
"-1"
sectionFooterHeight=
"-1"
estimatedSectionFooterHeight=
"-1
"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"YVv-xm-y2W"
>
<tableView
clipsSubviews=
"YES"
contentMode=
"scaleToFill"
alwaysBounceVertical=
"YES"
dataMode=
"prototypes"
style=
"
grouped"
separatorStyle=
"none"
rowHeight=
"-1"
estimatedRowHeight=
"-1"
sectionHeaderHeight=
"1"
estimatedSectionHeaderHeight=
"-1"
sectionFooterHeight=
"1"
estimatedSectionFooterHeight=
"-1"
contentViewInsetsToSafeArea=
"NO
"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"YVv-xm-y2W"
>
<rect
key=
"frame"
x=
"0.0"
y=
"2"
width=
"414"
height=
"846"
/>
<color
key=
"backgroundColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<color
key=
"separatorColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<color
key=
"sectionIndexBackgroundColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<prototypes>
<tableViewCell
clipsSubviews=
"YES"
contentMode=
"scaleToFill"
preservesSuperviewLayoutMargins=
"YES"
selectionStyle=
"none"
indentationWidth=
"10"
reuseIdentifier=
"UnifiedCouponsTableViewCellId"
id=
"D63-Nr-YbN"
customClass=
"UnifiedCouponsTableViewCell"
customModule=
"SwiftWarplyFramework"
>
<rect
key=
"frame"
x=
"0.0"
y=
"5
0
"
width=
"414"
height=
"64.5"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"5
5.5
"
width=
"414"
height=
"64.5"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<tableViewCellContentView
key=
"contentView"
opaque=
"NO"
clipsSubviews=
"YES"
multipleTouchEnabled=
"YES"
contentMode=
"center"
preservesSuperviewLayoutMargins=
"YES"
insetsLayoutMarginsFromSafeArea=
"NO"
tableViewCell=
"D63-Nr-YbN"
id=
"Fzs-bb-ogj"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"414"
height=
"64.5"
/>
...
...
@@ -4754,6 +4755,108 @@
<outlet
property=
"nameLabel"
destination=
"GFK-EC-8kT"
id=
"Bbm-E9-hGO"
/>
</connections>
</tableViewCell>
<tableViewCell
clipsSubviews=
"YES"
contentMode=
"scaleToFill"
insetsLayoutMarginsFromSafeArea=
"NO"
selectionStyle=
"none"
hidesAccessoryWhenEditing=
"NO"
indentationLevel=
"1"
indentationWidth=
"0.0"
reuseIdentifier=
"CouponsTableViewCellId"
id=
"PIt-2t-7fO"
customClass=
"CouponsTableViewCell"
customModule=
"SwiftWarplyFramework"
customModuleProvider=
"target"
>
<rect
key=
"frame"
x=
"0.0"
y=
"120"
width=
"414"
height=
"64.5"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<tableViewCellContentView
key=
"contentView"
opaque=
"NO"
clipsSubviews=
"YES"
multipleTouchEnabled=
"YES"
contentMode=
"center"
insetsLayoutMarginsFromSafeArea=
"NO"
tableViewCell=
"PIt-2t-7fO"
id=
"ECe-u7-APW"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"414"
height=
"64.5"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<subviews>
<view
contentMode=
"scaleToFill"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"rvV-78-dYR"
>
<rect
key=
"frame"
x=
"10"
y=
"0.0"
width=
"394"
height=
"64.5"
/>
<subviews>
<imageView
clipsSubviews=
"YES"
userInteractionEnabled=
"NO"
contentMode=
"scaleToFill"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
image=
"coupon_bg"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"ayq-SS-U8t"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"394"
height=
"64.5"
/>
</imageView>
<imageView
clipsSubviews=
"YES"
userInteractionEnabled=
"NO"
contentMode=
"scaleAspectFit"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"x8f-2v-Jao"
>
<rect
key=
"frame"
x=
"20"
y=
"10"
width=
"79"
height=
"44.5"
/>
<color
key=
"backgroundColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
</imageView>
<view
contentMode=
"scaleToFill"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"oIZ-eF-M5Z"
>
<rect
key=
"frame"
x=
"104"
y=
"10"
width=
"10"
height=
"44.5"
/>
<color
key=
"backgroundColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<constraints>
<constraint
firstAttribute=
"width"
constant=
"10"
id=
"rkI-WU-bsK"
/>
</constraints>
</view>
<label
opaque=
"NO"
userInteractionEnabled=
"NO"
contentMode=
"left"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
text=
"Label"
textAlignment=
"natural"
lineBreakMode=
"tailTruncation"
baselineAdjustment=
"alignBaselines"
adjustsFontSizeToFit=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"wRq-jP-x8E"
>
<rect
key=
"frame"
x=
"119"
y=
"-13"
width=
"255"
height=
"20"
/>
<fontDescription
key=
"fontDescription"
name=
"BTCosmo-Bold"
family=
"BTCosmo"
pointSize=
"17"
/>
<color
key=
"textColor"
red=
"0.12941176469999999"
green=
"0.12941176469999999"
blue=
"0.12941176469999999"
alpha=
"1"
colorSpace=
"calibratedRGB"
/>
<nil
key=
"highlightedColor"
/>
</label>
<stackView
opaque=
"NO"
contentMode=
"scaleToFill"
alignment=
"center"
spacing=
"5"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"pAV-li-7RR"
>
<rect
key=
"frame"
x=
"119"
y=
"12"
width=
"255"
height=
"40.5"
/>
<subviews>
<label
opaque=
"NO"
userInteractionEnabled=
"NO"
contentMode=
"left"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
text=
"Label"
textAlignment=
"natural"
lineBreakMode=
"tailTruncation"
baselineAdjustment=
"alignBaselines"
adjustsFontSizeToFit=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"3HE-ik-tKt"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"127.5"
height=
"40.5"
/>
<fontDescription
key=
"fontDescription"
name=
"BTCosmo-Bold"
family=
"BTCosmo"
pointSize=
"35"
/>
<color
key=
"textColor"
red=
"0.12941176469999999"
green=
"0.12941176469999999"
blue=
"0.12941176469999999"
alpha=
"1"
colorSpace=
"calibratedRGB"
/>
<nil
key=
"highlightedColor"
/>
</label>
<label
opaque=
"NO"
userInteractionEnabled=
"NO"
contentMode=
"left"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
text=
"Label"
lineBreakMode=
"tailTruncation"
numberOfLines=
"3"
baselineAdjustment=
"alignBaselines"
adjustsFontSizeToFit=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"WcV-JM-VIz"
>
<rect
key=
"frame"
x=
"132.5"
y=
"13"
width=
"122.5"
height=
"15"
/>
<fontDescription
key=
"fontDescription"
name=
"PeridotPE-Regular"
family=
"Peridot PE"
pointSize=
"12"
/>
<color
key=
"textColor"
red=
"0.12941176469999999"
green=
"0.12941176469999999"
blue=
"0.12941176469999999"
alpha=
"1"
colorSpace=
"calibratedRGB"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
<color
key=
"backgroundColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<constraints>
<constraint
firstItem=
"3HE-ik-tKt"
firstAttribute=
"width"
secondItem=
"pAV-li-7RR"
secondAttribute=
"width"
multiplier=
"0.5"
id=
"1J7-Ed-pvc"
/>
</constraints>
</stackView>
<label
opaque=
"NO"
userInteractionEnabled=
"NO"
contentMode=
"left"
horizontalHuggingPriority=
"251"
verticalHuggingPriority=
"251"
text=
"Label"
textAlignment=
"natural"
lineBreakMode=
"tailTruncation"
baselineAdjustment=
"alignBaselines"
adjustsFontSizeToFit=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"O37-kL-mV9"
>
<rect
key=
"frame"
x=
"119"
y=
"57.5"
width=
"255"
height=
"15"
/>
<fontDescription
key=
"fontDescription"
name=
"PeridotPE-Regular"
family=
"Peridot PE"
pointSize=
"12"
/>
<color
key=
"textColor"
red=
"0.12941176469999999"
green=
"0.12941176469999999"
blue=
"0.12941176469999999"
alpha=
"1"
colorSpace=
"calibratedRGB"
/>
<nil
key=
"highlightedColor"
/>
</label>
</subviews>
<color
key=
"backgroundColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<constraints>
<constraint
firstItem=
"O37-kL-mV9"
firstAttribute=
"leading"
secondItem=
"oIZ-eF-M5Z"
secondAttribute=
"trailing"
constant=
"5"
id=
"0wP-g6-tOx"
/>
<constraint
firstItem=
"ayq-SS-U8t"
firstAttribute=
"top"
secondItem=
"rvV-78-dYR"
secondAttribute=
"top"
id=
"4CK-ZW-x7Q"
/>
<constraint
firstItem=
"pAV-li-7RR"
firstAttribute=
"leading"
secondItem=
"oIZ-eF-M5Z"
secondAttribute=
"trailing"
constant=
"5"
id=
"5in-wK-Zg5"
/>
<constraint
firstItem=
"oIZ-eF-M5Z"
firstAttribute=
"top"
secondItem=
"rvV-78-dYR"
secondAttribute=
"top"
constant=
"10"
id=
"FYN-gf-brd"
/>
<constraint
firstItem=
"pAV-li-7RR"
firstAttribute=
"top"
secondItem=
"wRq-jP-x8E"
secondAttribute=
"bottom"
constant=
"5"
id=
"FbO-ru-ycd"
/>
<constraint
firstAttribute=
"trailing"
secondItem=
"O37-kL-mV9"
secondAttribute=
"trailing"
constant=
"20"
id=
"Gee-F6-bBT"
/>
<constraint
firstItem=
"ayq-SS-U8t"
firstAttribute=
"leading"
secondItem=
"rvV-78-dYR"
secondAttribute=
"leading"
id=
"M37-JQ-ufI"
/>
<constraint
firstItem=
"oIZ-eF-M5Z"
firstAttribute=
"leading"
secondItem=
"x8f-2v-Jao"
secondAttribute=
"trailing"
constant=
"5"
id=
"Py3-9p-Twv"
/>
<constraint
firstAttribute=
"bottom"
secondItem=
"oIZ-eF-M5Z"
secondAttribute=
"bottom"
constant=
"10"
id=
"VXN-mF-iuh"
/>
<constraint
firstAttribute=
"trailing"
secondItem=
"ayq-SS-U8t"
secondAttribute=
"trailing"
id=
"WT9-Mq-vNm"
/>
<constraint
firstItem=
"x8f-2v-Jao"
firstAttribute=
"leading"
secondItem=
"rvV-78-dYR"
secondAttribute=
"leading"
constant=
"20"
id=
"Whf-Fb-Kaz"
/>
<constraint
firstAttribute=
"bottom"
secondItem=
"ayq-SS-U8t"
secondAttribute=
"bottom"
id=
"XYp-ov-MHb"
/>
<constraint
firstAttribute=
"trailing"
secondItem=
"pAV-li-7RR"
secondAttribute=
"trailing"
constant=
"20"
id=
"dXA-Lj-qLC"
/>
<constraint
firstAttribute=
"trailing"
secondItem=
"wRq-jP-x8E"
secondAttribute=
"trailing"
constant=
"20"
id=
"hM1-BX-baT"
/>
<constraint
firstItem=
"O37-kL-mV9"
firstAttribute=
"top"
secondItem=
"pAV-li-7RR"
secondAttribute=
"bottom"
constant=
"5"
id=
"iZl-tJ-qE7"
/>
<constraint
firstItem=
"wRq-jP-x8E"
firstAttribute=
"leading"
secondItem=
"oIZ-eF-M5Z"
secondAttribute=
"trailing"
constant=
"5"
id=
"m3u-Om-cxu"
/>
<constraint
firstItem=
"x8f-2v-Jao"
firstAttribute=
"width"
secondItem=
"rvV-78-dYR"
secondAttribute=
"width"
multiplier=
"0.2"
id=
"mu0-QV-68e"
/>
<constraint
firstItem=
"pAV-li-7RR"
firstAttribute=
"centerY"
secondItem=
"rvV-78-dYR"
secondAttribute=
"centerY"
id=
"rPj-ld-u6g"
/>
<constraint
firstAttribute=
"bottom"
secondItem=
"x8f-2v-Jao"
secondAttribute=
"bottom"
constant=
"10"
id=
"w2y-KM-3as"
/>
<constraint
firstItem=
"x8f-2v-Jao"
firstAttribute=
"top"
secondItem=
"rvV-78-dYR"
secondAttribute=
"top"
constant=
"10"
id=
"wZT-ye-Ybt"
/>
</constraints>
</view>
</subviews>
<color
key=
"backgroundColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<constraints>
<constraint
firstAttribute=
"trailing"
secondItem=
"rvV-78-dYR"
secondAttribute=
"trailing"
constant=
"10"
id=
"S6z-tz-kfM"
/>
<constraint
firstAttribute=
"bottom"
secondItem=
"rvV-78-dYR"
secondAttribute=
"bottom"
id=
"kgH-YM-XNm"
/>
<constraint
firstItem=
"rvV-78-dYR"
firstAttribute=
"top"
secondItem=
"ECe-u7-APW"
secondAttribute=
"top"
id=
"pq8-g0-5sp"
/>
<constraint
firstItem=
"rvV-78-dYR"
firstAttribute=
"leading"
secondItem=
"ECe-u7-APW"
secondAttribute=
"leading"
constant=
"10"
id=
"yop-7a-7O1"
/>
</constraints>
</tableViewCellContentView>
<color
key=
"backgroundColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<connections>
<outlet
property=
"borderView"
destination=
"oIZ-eF-M5Z"
id=
"3yn-Ck-n9c"
/>
<outlet
property=
"couponBgImage"
destination=
"ayq-SS-U8t"
id=
"Xkb-00-8LO"
/>
<outlet
property=
"couponImage"
destination=
"x8f-2v-Jao"
id=
"Nar-6D-BkI"
/>
<outlet
property=
"dicountLabel"
destination=
"3HE-ik-tKt"
id=
"HRc-lF-Erm"
/>
<outlet
property=
"discriptionLabel"
destination=
"WcV-JM-VIz"
id=
"raY-xP-Duz"
/>
<outlet
property=
"expirationLabel"
destination=
"O37-kL-mV9"
id=
"lBr-9Y-C4f"
/>
<outlet
property=
"nameLabel"
destination=
"wRq-jP-x8E"
id=
"W7L-DZ-95L"
/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet
property=
"dataSource"
destination=
"3uV-Le-crf"
id=
"Qf4-jf-XhM"
/>
...
...
SwiftWarplyFramework/SwiftWarplyFramework/UnifiedCouponsViewController.swift
View file @
514d24b
...
...
@@ -17,6 +17,15 @@ import SwiftEventBus
@IBOutlet
weak
var
emptyLabel
:
UILabel
!
public
var
unifiedCoupons
:
Array
<
swiftApi
.
UnifiedCouponModel
>
=
[]
public
var
smCoupons
:
Array
<
swiftApi
.
CouponItemModel
>
=
[]
public
var
smCouponsSelected
:
Array
<
swiftApi
.
CouponItemModel
>
=
[]
// A reference to the Select All image view for later use
var
circleImageView
:
UIImageView
!
// Track the selection state
var
isSelectAllActive
:
Bool
=
false
public
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
@@ -29,7 +38,23 @@ import SwiftEventBus
self
.
unifiedCoupons
=
swiftApi
()
.
getUnifiedCouponList
()
self
.
tableView
.
reloadData
()
if
(
self
.
unifiedCoupons
.
count
==
0
)
{
if
(
self
.
unifiedCoupons
.
count
==
0
&&
self
.
smCoupons
.
count
==
0
)
{
self
.
emptyView
.
isHidden
=
false
self
.
emptyViewHeight
.
constant
=
self
.
emptyView
.
intrinsicContentSize
.
height
}
else
{
self
.
emptyView
.
isHidden
=
true
self
.
emptyViewHeight
.
constant
=
0
}
}
}
SwiftEventBus
.
onBackgroundThread
(
self
,
name
:
"sm_coupons_fetched"
)
{
result
in
DispatchQueue
.
main
.
async
{
self
.
smCoupons
=
swiftApi
()
.
getSMCouponList
()
self
.
tableView
.
reloadData
()
if
(
self
.
unifiedCoupons
.
count
==
0
&&
self
.
smCoupons
.
count
==
0
)
{
self
.
emptyView
.
isHidden
=
false
self
.
emptyViewHeight
.
constant
=
self
.
emptyView
.
intrinsicContentSize
.
height
}
else
{
...
...
@@ -50,7 +75,9 @@ import SwiftEventBus
// tableView.clipsToBounds = true
// tableView.layer.cornerRadius = 30
// tableView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
tableView
.
contentInset
.
top
=
30
// tableView.contentInset.top = 30
// TODO: Change
tableView
.
contentInset
.
bottom
=
115
emptyLabel
.
text
=
"Αυτήν τη στιγμή δεν έχεις κάποιο ενεργό κουπόνι. Στην ενότητα FOR YOU μπορείς να βρεις κουπόνια αποκλειστικά για σένα!"
}
...
...
@@ -61,9 +88,10 @@ import SwiftEventBus
swiftApi
()
.
logTrackersEvent
(
"screen"
,
"ActiveUnifiedCouponsScreen"
)
self
.
unifiedCoupons
=
swiftApi
()
.
getUnifiedCouponList
()
self
.
smCoupons
=
swiftApi
()
.
getSMCouponList
()
self
.
tableView
.
reloadData
()
if
(
self
.
unifiedCoupons
.
count
==
0
)
{
if
(
self
.
unifiedCoupons
.
count
==
0
&&
self
.
smCoupons
.
count
==
0
)
{
self
.
emptyView
.
isHidden
=
false
self
.
emptyViewHeight
.
constant
=
self
.
emptyView
.
intrinsicContentSize
.
height
}
else
{
...
...
@@ -75,39 +103,248 @@ import SwiftEventBus
}
// MARK: - Functions
// Button action for "select all"
@objc
func
selectAllTapped
()
{
// Toggle the selection state
isSelectAllActive
.
toggle
()
// Update the image based on the new state
if
(
isSelectAllActive
)
{
circleImageView
.
image
=
UIImage
(
named
:
"circle_checked"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
// Selected image
smCouponsSelected
=
smCoupons
}
else
{
circleImageView
.
image
=
UIImage
(
named
:
"circle_unchecked"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
// Unselected image
smCouponsSelected
=
[]
}
// Reload the SM Coupons section only
tableView
.
reloadSections
(
IndexSet
(
integer
:
1
),
with
:
.
automatic
)
}
func
handleSelectCouponAction
(
indexPath
:
IndexPath
)
{
let
currentCoupon
=
self
.
smCoupons
[
indexPath
.
row
]
let
isCouponSelected
=
self
.
smCouponsSelected
.
contains
{
$0
.
coupon
==
currentCoupon
.
coupon
}
if
(
isCouponSelected
)
{
self
.
smCouponsSelected
=
self
.
smCouponsSelected
.
filter
({
return
$0
.
coupon
!=
currentCoupon
.
coupon
})
if
(
isSelectAllActive
)
{
isSelectAllActive
=
false
// Reload the SM Coupons section only
tableView
.
reloadSections
(
IndexSet
(
integer
:
1
),
with
:
.
automatic
)
}
else
{
tableView
.
reloadRows
(
at
:
[
indexPath
],
with
:
.
automatic
)
// Reload the specific row
}
}
else
{
self
.
smCouponsSelected
.
append
(
currentCoupon
)
if
(
self
.
smCouponsSelected
.
count
==
self
.
smCoupons
.
count
)
{
isSelectAllActive
=
true
// Reload the SM Coupons section only
tableView
.
reloadSections
(
IndexSet
(
integer
:
1
),
with
:
.
automatic
)
}
else
{
tableView
.
reloadRows
(
at
:
[
indexPath
],
with
:
.
automatic
)
// Reload the specific row
}
}
}
}
// MARK: - TableView
extension
UnifiedCouponsViewController
:
UITableViewDelegate
,
UITableViewDataSource
{
public
func
numberOfSections
(
in
tableView
:
UITableView
)
->
Int
{
return
1
return
2
}
public
func
tableView
(
_
tableView
:
UITableView
,
numberOfRowsInSection
section
:
Int
)
->
Int
{
return
self
.
unifiedCoupons
.
count
if
(
section
==
0
)
{
return
self
.
unifiedCoupons
.
count
}
else
if
(
section
==
1
)
{
return
self
.
smCoupons
.
count
}
else
{
return
0
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
heightForRowAt
indexPath
:
IndexPath
)
->
CGFloat
{
return
130.0
+
8.0
// return UITableViewAutomaticDimension
if
(
indexPath
.
section
==
0
)
{
return
130.0
+
8.0
// return UITableViewAutomaticDimension
}
else
if
(
indexPath
.
section
==
1
)
{
return
130.0
+
8.0
}
else
{
return
0.0
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
cellForRowAt
indexPath
:
IndexPath
)
->
UITableViewCell
{
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"UnifiedCouponsTableViewCellId"
,
for
:
indexPath
)
as!
UnifiedCouponsTableViewCell
cell
.
configureCell
(
coupon
:
unifiedCoupons
[
indexPath
.
row
])
return
cell
if
(
indexPath
.
section
==
0
)
{
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"UnifiedCouponsTableViewCellId"
,
for
:
indexPath
)
as!
UnifiedCouponsTableViewCell
cell
.
configureCell
(
coupon
:
unifiedCoupons
[
indexPath
.
row
])
return
cell
}
else
{
let
currentCoupon
=
self
.
smCoupons
[
indexPath
.
row
]
let
isCouponSelected
=
self
.
smCouponsSelected
.
contains
{
$0
.
coupon
==
currentCoupon
.
coupon
}
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"CouponsTableViewCellId"
,
for
:
indexPath
)
as!
CouponsTableViewCell
cell
.
configureCell
(
coupon
:
smCoupons
[
indexPath
.
row
])
cell
.
showSelectButton
(
isSelectViewVisible
:
true
,
isSelected
:
isCouponSelected
)
{
self
.
handleSelectCouponAction
(
indexPath
:
indexPath
)
}
return
cell
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
didSelectRowAt
indexPath
:
IndexPath
)
{
let
couponBarcode
=
unifiedCoupons
[
indexPath
.
row
]
.
_barcode
swiftApi
()
.
logTrackersEvent
(
"click"
,
(
"UnifiedCoupon:"
+
couponBarcode
))
let
storyboard
=
UIStoryboard
(
name
:
"Main"
,
bundle
:
Bundle
(
for
:
MyEmptyClass
.
self
))
let
vc
=
storyboard
.
instantiateViewController
(
withIdentifier
:
"UnifiedCouponBarcodeViewController"
)
as!
SwiftWarplyFramework
.
UnifiedCouponBarcodeViewController
vc
.
coupon
=
unifiedCoupons
[
indexPath
.
row
]
vc
.
isFromWallet
=
true
self
.
navigationController
?
.
pushViewController
(
vc
,
animated
:
true
)
if
(
indexPath
.
section
==
0
)
{
let
couponBarcode
=
unifiedCoupons
[
indexPath
.
row
]
.
_barcode
swiftApi
()
.
logTrackersEvent
(
"click"
,
(
"UnifiedCoupon:"
+
couponBarcode
))
let
storyboard
=
UIStoryboard
(
name
:
"Main"
,
bundle
:
Bundle
(
for
:
MyEmptyClass
.
self
))
let
vc
=
storyboard
.
instantiateViewController
(
withIdentifier
:
"UnifiedCouponBarcodeViewController"
)
as!
SwiftWarplyFramework
.
UnifiedCouponBarcodeViewController
vc
.
coupon
=
unifiedCoupons
[
indexPath
.
row
]
vc
.
isFromWallet
=
true
self
.
navigationController
?
.
pushViewController
(
vc
,
animated
:
true
)
}
else
if
(
indexPath
.
section
==
1
)
{
let
couponSetData
:
swiftApi
.
CouponSetItemModel
?
=
smCoupons
[
indexPath
.
row
]
.
couponset_data
let
couponName
=
couponSetData
?
.
name
??
""
swiftApi
()
.
logTrackersEvent
(
"click"
,
(
"Coupon:"
+
couponName
))
let
storyboard
=
UIStoryboard
(
name
:
"Main"
,
bundle
:
Bundle
(
for
:
MyEmptyClass
.
self
))
let
vc
=
storyboard
.
instantiateViewController
(
withIdentifier
:
"CouponBarcodeViewController"
)
as!
SwiftWarplyFramework
.
CouponBarcodeViewController
vc
.
coupon
=
smCoupons
[
indexPath
.
row
]
vc
.
isFromWallet
=
true
self
.
navigationController
?
.
pushViewController
(
vc
,
animated
:
true
)
}
else
{
// Do nothing
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
viewForHeaderInSection
section
:
Int
)
->
UIView
?
{
if
(
section
==
0
)
{
if
(
self
.
unifiedCoupons
.
count
>
0
)
{
let
view
=
UIView
(
frame
:
CGRect
(
x
:
0
,
y
:
0
,
width
:
tableView
.
frame
.
width
,
height
:
70
))
view
.
backgroundColor
=
.
clear
let
titleLabel
=
UILabel
(
frame
:
CGRect
(
x
:
16
,
y
:
25
,
width
:
view
.
frame
.
width
-
32
,
height
:
25
))
titleLabel
.
font
=
UIFont
(
name
:
"BTCosmo-Bold"
,
size
:
17
)
// titleLabel.textColor = UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)
titleLabel
.
textColor
=
UIColor
(
rgb
:
0x212121
)
titleLabel
.
text
=
"Ενιαία κουπόνια"
view
.
addSubview
(
titleLabel
)
return
view
}
else
{
return
nil
}
}
else
if
(
section
==
1
)
{
if
(
self
.
smCoupons
.
count
>
0
)
{
let
headerView
=
UIView
()
headerView
.
backgroundColor
=
.
clear
// Create the title label (Κουπόνια)
let
titleLabel
=
UILabel
()
titleLabel
.
text
=
"Κουπόνια"
titleLabel
.
font
=
UIFont
(
name
:
"BTCosmo-Bold"
,
size
:
17
)
// Create the select-all label (Επιλογή όλων)
let
selectAllLabel
=
UILabel
()
selectAllLabel
.
text
=
"Επιλογή όλων"
selectAllLabel
.
font
=
UIFont
(
name
:
"PeridotPE-SBold"
,
size
:
17
)
// Create a UIImageView for the circle image
circleImageView
=
UIImageView
()
// let circleImage = UIImage(named: "circle_unchecked", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
// Update the image based on the new state
if
(
isSelectAllActive
)
{
circleImageView
.
image
=
UIImage
(
named
:
"circle_checked"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
// Selected image
}
else
{
circleImageView
.
image
=
UIImage
(
named
:
"circle_unchecked"
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
// Unselected image
}
// circleImageView.image = circleImage
circleImageView
.
contentMode
=
.
scaleAspectFit
circleImageView
.
translatesAutoresizingMaskIntoConstraints
=
false
// Set size for the imageView
circleImageView
.
widthAnchor
.
constraint
(
equalToConstant
:
30
)
.
isActive
=
true
circleImageView
.
heightAnchor
.
constraint
(
equalToConstant
:
30
)
.
isActive
=
true
// Create a transparent UIButton on top of the image
let
selectAllButton
=
UIButton
(
type
:
.
custom
)
selectAllButton
.
backgroundColor
=
.
clear
// Keep it transparent
selectAllButton
.
addTarget
(
self
,
action
:
#selector(
selectAllTapped
)
,
for
:
.
touchUpInside
)
selectAllButton
.
translatesAutoresizingMaskIntoConstraints
=
false
// Set the button size to match the image size
selectAllButton
.
widthAnchor
.
constraint
(
equalToConstant
:
30
)
.
isActive
=
true
selectAllButton
.
heightAnchor
.
constraint
(
equalToConstant
:
30
)
.
isActive
=
true
// Create a horizontal stack view to align the title, label, and image
let
mainStackView
=
UIStackView
(
arrangedSubviews
:
[
titleLabel
,
selectAllLabel
,
circleImageView
])
mainStackView
.
axis
=
.
horizontal
mainStackView
.
alignment
=
.
center
// Centers them vertically
mainStackView
.
spacing
=
10
// Add the stack view to the header view
headerView
.
addSubview
(
mainStackView
)
headerView
.
addSubview
(
selectAllButton
)
// Add the button separately on top of the image view
// Set constraints for stack view
mainStackView
.
translatesAutoresizingMaskIntoConstraints
=
false
mainStackView
.
leadingAnchor
.
constraint
(
equalTo
:
headerView
.
leadingAnchor
,
constant
:
16
)
.
isActive
=
true
mainStackView
.
trailingAnchor
.
constraint
(
equalTo
:
headerView
.
trailingAnchor
,
constant
:
-
16
)
.
isActive
=
true
mainStackView
.
topAnchor
.
constraint
(
equalTo
:
headerView
.
topAnchor
,
constant
:
8
)
.
isActive
=
true
mainStackView
.
bottomAnchor
.
constraint
(
equalTo
:
headerView
.
bottomAnchor
,
constant
:
-
8
)
.
isActive
=
true
// Set button position on top of the imageView
selectAllButton
.
centerXAnchor
.
constraint
(
equalTo
:
circleImageView
.
centerXAnchor
)
.
isActive
=
true
selectAllButton
.
centerYAnchor
.
constraint
(
equalTo
:
circleImageView
.
centerYAnchor
)
.
isActive
=
true
return
headerView
}
else
{
return
nil
}
}
else
{
return
nil
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
heightForHeaderInSection
section
:
Int
)
->
CGFloat
{
if
(
section
==
0
)
{
if
(
self
.
unifiedCoupons
.
count
>
0
)
{
return
70.0
}
else
{
return
0.0
}
}
else
if
(
section
==
1
)
{
if
(
self
.
smCoupons
.
count
>
0
)
{
return
70.0
}
else
{
return
0.0
}
}
else
{
return
0.0
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
heightForFooterInSection
section
:
Int
)
->
CGFloat
{
// return CGFloat.leastNormalMagnitude
return
0.0
}
public
func
tableView
(
_
tableView
:
UITableView
,
viewForFooterInSection
section
:
Int
)
->
UIView
?
{
return
nil
}
}
...
...
Please
register
or
login
to post a comment