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
2025-01-21 14:45:28 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
aeebabec9672ef6c3772f3a7eb9ae191aa128273
aeebabec
1 parent
e0518632
MarketPassViewController dynamic data
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
145 additions
and
29 deletions
SwiftWarplyFramework/SwiftWarplyFramework/MarketPassViewController.swift
SwiftWarplyFramework/SwiftWarplyFramework/MarketPassViewController.swift
View file @
aeebabe
...
...
@@ -21,6 +21,10 @@ import AVFoundation
@IBOutlet
weak
var
smLogosView
:
UIView
!
@IBOutlet
weak
var
mapButton
:
UIButton
!
var
marketPassDetails
:
swiftApi
.
MarketPassDetailsModel
?
let
spinner
=
SpinnerViewController
()
let
uiscreen
:
CGRect
=
UIScreen
.
main
.
bounds
public
override
func
viewDidLoad
()
{
...
...
@@ -28,6 +32,9 @@ import AVFoundation
self
.
hidesBottomBarWhenPushed
=
true
passContainerView
.
isHidden
=
true
getMarketPassDetailsRequest
()
setBackButton
()
setNavigationTitle
(
"SUPERMARKET DEALS"
)
// Setup the info button with an action
...
...
@@ -74,38 +81,35 @@ import AVFoundation
barcodeView
.
layer
.
borderWidth
=
2
barcodeView
.
layer
.
borderColor
=
UIColor
(
rgb
:
0xDADDE4
)
.
cgColor
//TODO: FIX
// let barcodeString = constructBarcode(coupon: coupon) ?? ""
// let barcodeString = coupon?._barcode ?? ""
let
barcodeString
=
"4006381333931"
let
barcodeString
=
""
barcodeLabel
.
text
=
barcodeString
barcodeLabel
.
font
=
UIFont
(
name
:
"PeridotPE-Regular"
,
size
:
19.0
)
barcodeLabel
.
textColor
=
UIColor
(
rgb
:
0x212121
)
if
let
barcodeUIImage
=
RSUnifiedCodeGenerator
.
shared
.
generateCode
(
barcodeString
,
machineReadableCodeObjectType
:
AVMetadataObject
.
ObjectType
.
ean13
.
rawValue
,
targetSize
:
CGSize
(
width
:
self
.
uiscreen
.
width
*
0.8
,
height
:
self
.
uiscreen
.
height
*
0.12
))
{
// if let barcodeUIImage = RSUnifiedCodeGenerator.shared.generateCode(barcodeString, machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue, targetSize: CGSize(width: 110, height: 83)) {
barcodeImage
.
image
=
barcodeUIImage
//
if let barcodeUIImage = RSUnifiedCodeGenerator.shared.generateCode(barcodeString, machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue, targetSize: CGSize(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.12)) {
//
//
if let barcodeUIImage = RSUnifiedCodeGenerator.shared.generateCode(barcodeString, machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue, targetSize: CGSize(width: 110, height: 83)) {
//
barcodeImage.image = barcodeUIImage
barcodeImageHeight
.
constant
=
self
.
uiscreen
.
height
*
0.12
// barcodeImageHeight.constant = 83
//
barcodeImageHeight.constant = self.uiscreen.height * 0.12
//
//
barcodeImageHeight.constant = 83
}
else
{
barcodeImageHeight
.
constant
=
0
}
//
} else {
//
barcodeImageHeight.constant = 0
//
}
// TODO: FIX
let
couponsValueString
=
"30"
let
attrRegular
=
[
NSAttributedString
.
Key
.
font
:
UIFont
(
name
:
"PeridotPE-Regular"
,
size
:
17
)
??
UIFont
.
systemFont
(
ofSize
:
16
),
NSAttributedString
.
Key
.
foregroundColor
:
UIColor
.
white
]
let
attrBold
=
[
NSAttributedString
.
Key
.
font
:
UIFont
(
name
:
"PeridotPE-Bold"
,
size
:
17
)
??
UIFont
.
boldSystemFont
(
ofSize
:
16
),
NSAttributedString
.
Key
.
foregroundColor
:
UIColor
.
white
]
//
let couponsValueString = "30"
//
let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
//
let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
let
couponsValueNormalText1
=
"Έχεις κουπόνια συνολικής αξίας "
let
couponsValueBoldText
=
couponsValueString
+
"€"
//
let couponsValueNormalText1 = "Έχεις κουπόνια συνολικής αξίας "
//
let couponsValueBoldText = couponsValueString + "€"
let
couponsValueAttributedString
=
NSMutableAttributedString
(
string
:
couponsValueNormalText1
,
attributes
:
attrRegular
)
let
couponsValueBoldString
=
NSMutableAttributedString
(
string
:
couponsValueBoldText
,
attributes
:
attrBold
)
//
let couponsValueAttributedString = NSMutableAttributedString(string:couponsValueNormalText1, attributes:attrRegular)
//
let couponsValueBoldString = NSMutableAttributedString(string: couponsValueBoldText, attributes:attrBold)
couponsValueAttributedString
.
append
(
couponsValueBoldString
)
couponsValueLabel
.
attributedText
=
couponsValueAttributedString
//
couponsValueAttributedString.append(couponsValueBoldString)
//
couponsValueLabel.attributedText = couponsValueAttributedString
mapButton
.
titleLabel
?
.
font
=
UIFont
(
name
:
"PeridotPE-SBold"
,
size
:
16
)
mapButton
.
setTitle
(
"Δες στο χάρτη"
,
for
:
.
normal
)
...
...
@@ -122,9 +126,69 @@ import AVFoundation
smLogosView
.
layer
.
maskedCorners
=
[
.
layerMinXMaxYCorner
,
.
layerMaxXMaxYCorner
]
// Bottom left, right corner radius
// TODO: FIX - Replace with dynamic images
let
imageNames
=
[
"active_code_logo_2"
,
"active_code_logo_2"
,
"active_code_logo_2"
]
// let images = imageNames.compactMap { UIImage(named: $0) }
let
images
=
imageNames
.
compactMap
{
UIImage
(
named
:
$0
,
in
:
MyEmptyClass
.
resourceBundle
(),
compatibleWith
:
nil
)
}
// let imageNames = ["active_code_logo_2", "active_code_logo_2", "active_code_logo_2"]
// // let images = imageNames.compactMap { UIImage(named: $0) }
// let images = imageNames.compactMap { UIImage(named: $0, in: MyEmptyClass.resourceBundle(), compatibleWith: nil) }
// // Create a horizontal stack view
// let stackView = UIStackView()
// stackView.axis = .horizontal
// stackView.spacing = 15 // Spacing between images
// stackView.alignment = .center
// stackView.distribution = .equalSpacing
// // Add UIImageViews to the stack view
// for image in images {
// let imageView = UIImageView(image: image)
// imageView.contentMode = .scaleAspectFit
// imageView.widthAnchor.constraint(equalToConstant: 40).isActive = true // Set a width
// imageView.heightAnchor.constraint(equalToConstant: 40).isActive = true // Set a height
// stackView.addArrangedSubview(imageView)
// }
// // Add the stack view to your main view
// smLogosView.addSubview(stackView)
// // Set up constraints for the stack view
// stackView.translatesAutoresizingMaskIntoConstraints = false
// NSLayoutConstraint.activate([
// stackView.leadingAnchor.constraint(equalTo: smLogosView.leadingAnchor, constant: 25),
// stackView.centerYAnchor.constraint(equalTo: smLogosView.centerYAnchor),
// ])
}
func
updateUI
()
{
// let barcodeString = constructBarcode(coupon: marketPassDetails?._barcode) ?? ""
let
barcodeString
=
marketPassDetails
?
.
_barcode
??
""
barcodeLabel
.
text
=
barcodeString
barcodeLabel
.
frame
.
size
.
width
=
barcodeLabel
.
intrinsicContentSize
.
width
barcodeLabel
.
frame
.
size
.
height
=
barcodeLabel
.
intrinsicContentSize
.
height
if
let
barcodeUIImage
=
RSUnifiedCodeGenerator
.
shared
.
generateCode
(
barcodeString
,
machineReadableCodeObjectType
:
AVMetadataObject
.
ObjectType
.
ean13
.
rawValue
,
targetSize
:
CGSize
(
width
:
self
.
uiscreen
.
width
*
0.8
,
height
:
self
.
uiscreen
.
height
*
0.12
))
{
// if let barcodeUIImage = RSUnifiedCodeGenerator.shared.generateCode(barcodeString, machineReadableCodeObjectType: AVMetadataObject.ObjectType.ean13.rawValue, targetSize: CGSize(width: 110, height: 83)) {
barcodeImage
.
image
=
barcodeUIImage
barcodeImageHeight
.
constant
=
self
.
uiscreen
.
height
*
0.12
// barcodeImageHeight.constant = 83
}
else
{
barcodeImageHeight
.
constant
=
0
}
let
couponsValueString
=
String
(
marketPassDetails
?
.
_total_available_discount
??
0.0
)
let
attrRegular
=
[
NSAttributedString
.
Key
.
font
:
UIFont
(
name
:
"PeridotPE-Regular"
,
size
:
17
)
??
UIFont
.
systemFont
(
ofSize
:
16
),
NSAttributedString
.
Key
.
foregroundColor
:
UIColor
.
white
]
let
attrBold
=
[
NSAttributedString
.
Key
.
font
:
UIFont
(
name
:
"PeridotPE-Bold"
,
size
:
17
)
??
UIFont
.
boldSystemFont
(
ofSize
:
16
),
NSAttributedString
.
Key
.
foregroundColor
:
UIColor
.
white
]
let
couponsValueNormalText1
=
"Έχεις κουπόνια συνολικής αξίας "
let
couponsValueBoldText
=
couponsValueString
+
"€"
let
couponsValueAttributedString
=
NSMutableAttributedString
(
string
:
couponsValueNormalText1
,
attributes
:
attrRegular
)
let
couponsValueBoldString
=
NSMutableAttributedString
(
string
:
couponsValueBoldText
,
attributes
:
attrBold
)
couponsValueAttributedString
.
append
(
couponsValueBoldString
)
couponsValueLabel
.
attributedText
=
couponsValueAttributedString
let
supermarkets
:
Array
<
swiftApi
.
SupermarketModel
>
=
marketPassDetails
?
.
_supermarkets
??
[]
// Create a horizontal stack view
let
stackView
=
UIStackView
()
...
...
@@ -133,12 +197,16 @@ import AVFoundation
stackView
.
alignment
=
.
center
stackView
.
distribution
=
.
equalSpacing
//
Add UIImageViews to the stack view
for
image
in
image
s
{
let
imageView
=
UIImageView
(
image
:
image
)
//
Load images dynamically
for
sm
in
supermarket
s
{
let
imageView
=
UIImageView
()
imageView
.
contentMode
=
.
scaleAspectFit
imageView
.
widthAnchor
.
constraint
(
equalToConstant
:
40
)
.
isActive
=
true
// Set a width
imageView
.
heightAnchor
.
constraint
(
equalToConstant
:
40
)
.
isActive
=
true
// Set a height
imageView
.
widthAnchor
.
constraint
(
equalToConstant
:
40
)
.
isActive
=
true
imageView
.
heightAnchor
.
constraint
(
equalToConstant
:
40
)
.
isActive
=
true
imageView
.
load
(
link
:
sm
.
_logo
,
placeholder
:
UIImage
(),
cache
:
URLCache
())
// Add image view to the stack view
stackView
.
addArrangedSubview
(
imageView
)
}
...
...
@@ -151,6 +219,29 @@ import AVFoundation
stackView
.
leadingAnchor
.
constraint
(
equalTo
:
smLogosView
.
leadingAnchor
,
constant
:
25
),
stackView
.
centerYAnchor
.
constraint
(
equalTo
:
smLogosView
.
centerYAnchor
),
])
passContainerView
.
isHidden
=
false
self
.
view
.
layoutIfNeeded
()
}
func
showSpinner
()
{
// add the spinner view controller
// addChild(spinner)
// spinner.view.frame = view.frame
// view.addSubview(spinner.view)
// spinner.didMove(toParent: self)
addChild
(
spinner
)
spinner
.
view
.
frame
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
self
.
view
.
frame
.
width
,
height
:
self
.
view
.
frame
.
height
)
self
.
view
.
addSubview
(
spinner
.
view
)
spinner
.
didMove
(
toParent
:
self
)
}
func
hideSpinner
()
{
// remove the spinner view controller
spinner
.
willMove
(
toParent
:
nil
)
spinner
.
view
.
removeFromSuperview
()
spinner
.
removeFromParent
()
}
func
constructBarcode
()
->
String
?
{
...
...
@@ -189,6 +280,31 @@ import AVFoundation
return
""
}
// MARK: - API Functions
func
getMarketPassDetailsRequest
()
{
showSpinner
()
swiftApi
()
.
getMarketPassDetailsAsync
(
getMarketPassDetailsCallback
,
failureCallback
:
{
errorCode
in
print
(
"========= getMarketPassDetailsRequest ERROR CODE ========="
,
errorCode
)
self
.
hideSpinner
()
})
}
func
getMarketPassDetailsCallback
(
_
marketPassDetailsData
:
swiftApi
.
MarketPassDetailsModel
?)
->
Void
{
self
.
hideSpinner
()
if
(
marketPassDetailsData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
if
let
tempMarketPassDetailsData
=
marketPassDetailsData
{
self
.
marketPassDetails
=
tempMarketPassDetailsData
self
.
updateUI
()
}
}
}
else
{
}
}
// MARK: - API Functions
// MARK: - Actions
@IBAction
func
mapButtonAction
(
_
sender
:
Any
)
{
swiftApi
()
.
openSupermarketMap
(
self
)
...
...
Please
register
or
login
to post a comment