TelcoViewController.swift
15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//
// TelcoViewController.swift
// WarplySDKFrameworkIOS
//
// Created by Manos Chorianopoulos on 16/7/22.
//
import UIKit
import SwiftEventBus
@objc public class TelcoViewController: UIViewController, UIPopoverControllerDelegate {
@IBOutlet weak var mainView: UIView!
@IBOutlet weak var backgroundImage: UIImageView!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var scrollContentView: UIView!
@IBOutlet weak var heroImage: UIImageView!
@IBOutlet weak var heroImageHeight: NSLayoutConstraint!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var activateButton: UIButton!
@IBOutlet weak var valueView: UIView!
@IBOutlet weak var valueLabel: UILabel!
@IBOutlet weak var giftTypeLabel: UILabel!
@IBOutlet weak var giftDurationView: UIView!
@IBOutlet weak var giftDurationLabel: UILabel!
@IBOutlet weak var borderLineView: UIView!
@IBOutlet weak var moreButton: UIButton!
@IBOutlet weak var moreTextView: UITextView!
@IBOutlet weak var moreTextViewHeight: NSLayoutConstraint!
@IBOutlet weak var topBorderLine: UIImageView!
let uiscreen: CGRect = UIScreen.main.bounds
public var ccms: swiftApi.LoyaltyContextualOfferModel?
public var campaign: swiftApi.CampaignItemModel?
var selectedNumber: String = ""
public var numbersList: Array<String> = []
var moreVisible: Bool = false;
public override func viewDidLoad() {
super.viewDidLoad()
self.hidesBottomBarWhenPushed = true
// Do any additional setup after loading the view.
// getProfileRequest()
numbersList = ccms?._eligibleAssets ?? []
setBackButton("ic_close_3")
setNavigationTitle(ccms?._titleOffer ?? "")
backgroundImage.image = UIImage(named: "coupons_scrollview_white", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
// let image = UIImage(named: "top_border_line", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)!
// var aspectR: CGFloat = 0.0
//
// aspectR = image.size.width/image.size.height
//
// topBorderLine.translatesAutoresizingMaskIntoConstraints = false
// topBorderLine.image = image
// topBorderLine.contentMode = .scaleAspectFill
//
// NSLayoutConstraint.activate([
// topBorderLine.topAnchor.constraint(equalTo: mainView.topAnchor, constant: 0),
// topBorderLine.leadingAnchor.constraint(equalTo: mainView.leadingAnchor, constant: 0),
// topBorderLine.trailingAnchor.constraint(equalTo: mainView.trailingAnchor, constant: 0),
// topBorderLine.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width),
// topBorderLine.heightAnchor.constraint(equalTo: topBorderLine.widthAnchor, multiplier: 1/aspectR)
// ])
// scrollView.clipsToBounds = true
// scrollView.layer.cornerRadius = 30
// scrollView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
heroImage.load(link: ccms?._imageOfferUrl ?? "", placeholder: UIImage(), cache: URLCache())
heroImage.contentMode = .scaleAspectFill
heroImageHeight.constant = 255 //230 // 253 // self.uiscreen.height * 0.25
nameLabel.text = ccms?._description ?? ""
// descriptionLabel.text = ccms?._subtitle ?? ""
valueView.gradientBorder(width: 1, colors: [UIColor(rgb: 0x07A2D1), UIColor(rgb: 0x73CA34)], startPoint: .unitCoordinate(.bottomLeft), endPoint: .unitCoordinate(.topRight), andRoundCornersWithRadius: 35)
valueLabel.text = ccms?._giftValue ?? ""
giftTypeLabel.text = ccms?._giftType ?? ""
giftDurationLabel.text = ccms?._duration ?? ""
giftDurationView.frame = CGRect(x: 0.0, y: 0.0, width: giftDurationLabel.intrinsicContentSize.width + 20, height: giftDurationView.frame.height)
giftDurationView.gradientBorder(width: 2, colors: [UIColor(rgb: 0x65DD6B), UIColor(rgb: 0x0D81B8)], startPoint: .unitCoordinate(.left), endPoint: .unitCoordinate(.right), andRoundCornersWithRadius: 35)
borderLineView.applyGradient(colours: [UIColor(rgb: 0x0AA3CD), UIColor(rgb: 0x6ECA43)], gradient: GradientOrientation.horizontal, cornerRadius: 0.0)
activateButton.titleLabel?.font = UIFont(name: "PeridotPE-SBold", size: 17)
activateButton.setTitle("Ενεργοποίηση", for: .normal)
activateButton.setTitleColor(.white, for: .normal)
activateButton.backgroundColor = UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00)
activateButton.layer.cornerRadius = 16.0
activateButton.frame = CGRect(x: 0.0, y: 0.0, width: activateButton.intrinsicContentSize.width, height: 50)
activateButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 25)
// Fix width for ipad
// if UIDevice.current.userInterfaceIdiom == .pad {
// // iPad
// activateButton.widthAnchor.constraint(equalToConstant: 250).isActive = true
// } else {
// // not iPad (iPhone, mac, tv, carPlay, unspecified)
// activateButton.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.6).isActive = true
// }
moreButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 15)
// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
moreButton.setTitle("Δες Περισσότερα", for: .normal)
moreButton.setTitleColor(UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00), for: .normal)
moreButton.setImage(UIImage(named: "ic_down_dark_2.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
moreButton.semanticContentAttribute = .forceRightToLeft
moreButton.tintColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 1.00)
moreButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
moreButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
moreButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
// let htmlText = ccms?._description ?? ""
// moreTextView.attributedText = htmlText.htmlToAttributedString
moreTextView.text = ccms?._termsAndConditions ?? ""
moreTextView.font = UIFont(name: "PeridotPE-Regular", size: 14)
moreTextView.textColor = UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)
moreTextView.textAlignment = .left
moreTextView.isScrollEnabled = false
toggleMore()
}
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
swiftApi().logTrackersEvent("screen", "TelcoScreen")
self.navigationController?.hideHairline()
}
// MARK: - Functions
func toggleMore() {
if (moreVisible) {
moreTextView.isHidden = false
let targetSize = CGSize(width: moreTextView.frame.width, height: CGFloat(MAXFLOAT))
moreTextViewHeight.constant = moreTextView.sizeThatFits(targetSize).height
moreButton.setImage(UIImage(named: "ic_up_dark_2.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
} else {
moreTextView.isHidden = true
moreTextViewHeight.constant = CGFloat(0)
moreButton.setImage(UIImage(named: "ic_down_dark_2.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
}
}
func showConfirmDialog() -> Void {
let alert = UIAlertController(title: "Ενεργοποίηση υπηρεσίας", message: "Θέλετε να γίνει ενεργοποίηση στο Κινητό μου;", preferredStyle: .alert)
let cancelButton = UIAlertAction(title: "Άκυρο", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
})
// cancelButton.setValue(UIColor(rgb: 0xFC5757), forKey: "titleTextColor")
alert.addAction(cancelButton)
alert.addAction(UIAlertAction(title: "Ενεργοποίηση", style: .default, handler: { action in
switch action.style{
case .default:
swiftApi().logTrackersEvent("click", ("ActivateTelco:" + (self.ccms?._sessionId ?? "")))
self.submitOrderRequest()
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void {
let alert = UIAlertController(title: alertTitle, message: alertSubTitle, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
// MARK: - API CALLS
func getProfileRequest() {
swiftApi().getProfileAsync(getProfileCallback, failureCallback: {errorCode in })
}
func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void {
if (profileData != nil) {
DispatchQueue.main.async {
self.numbersList = profileData?._msisdnList ?? []
}
} else {
}
}
func submitOrderRequest() {
swiftApi().submitOrderAsync(campaign_session_uuid: (campaign?.session_uuid ?? ""), user_msisdn: self.selectedNumber, businessService: (ccms?._businessService ?? ""), offerName: (ccms?._offerName ?? ""), productType: (ccms?._productType ?? ""), provDuration: (ccms?._provDuration ?? ""), noOfRecurrance: (ccms?._noOfRecurrance ?? ""), price: (ccms?._price ?? ""), discount: (ccms?._discount ?? ""), voiceCategory: (ccms?._voiceCategory ?? ""), dataCategory: (ccms?._dataCategory ?? ""), minsValue: (ccms?._minsValue ?? ""), dataValue: (ccms?._dataValue ?? ""), provStepValueMins: (ccms?._provStepValueMins ?? ""),
OfferAudienceLevel: (ccms?._offerAudienceLevel ?? ""), UACIOfferTrackingCode: (ccms?._uaciOfferTrackingCode ?? ""), OFFERCODE1: (ccms?._offerCode1 ?? ""), SCORE: (ccms?._score ?? ""), ZONE: (ccms?._zone ?? ""), WAVE: (ccms?._wave ?? ""), VALIDITY: (ccms?._validity ?? ""), TREATMENT_CODE: (ccms?._treatmentCode ?? ""), ccms_session_id: (ccms?._sessionId ?? ""), notificationMessage: (ccms?._notificationMessage ?? ""),
submitOrderCallback, failureCallback: {errorCode in
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
firebaseEvent._eventName = "loyalty_offer_activated"
firebaseEvent.setParameter = ("name", (self.ccms?._title ?? ""))
firebaseEvent.setParameter = ("type", "gift")
firebaseEvent.setParameter = ("successful", "false")
SwiftEventBus.post("firebase", sender: firebaseEvent)
self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
})
}
func submitOrderCallback (_ response: swiftApi.GenericResponseModel?) -> Void {
if (response != nil) {
DispatchQueue.main.async {
if (response?.getStatus == 1) {
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
firebaseEvent._eventName = "loyalty_offer_activated"
firebaseEvent.setParameter = ("name", (self.ccms?._title ?? ""))
firebaseEvent.setParameter = ("type", "gift")
firebaseEvent.setParameter = ("successful", "true")
SwiftEventBus.post("firebase", sender: firebaseEvent)
let ccmsEnabled = swiftApi.WarplyCCMSEnabledModel()
ccmsEnabled._isActivated = true
SwiftEventBus.post("ccms_enabled", sender: ccmsEnabled)
self.showDialog("Το αίτημά σου ολοκληρώθηκε επιτυχώς!","Θα ενημερωθείς άμεσα για την ενεργοποίηση του πακέτου σου.")
// self.postEventRequest()
} else {
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
firebaseEvent._eventName = "loyalty_offer_activated"
firebaseEvent.setParameter = ("name", (self.ccms?._title ?? ""))
firebaseEvent.setParameter = ("type", "gift")
firebaseEvent.setParameter = ("successful", "false")
SwiftEventBus.post("firebase", sender: firebaseEvent)
self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
}
}
} else {
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
firebaseEvent._eventName = "loyalty_offer_activated"
firebaseEvent.setParameter = ("name", (self.ccms?._title ?? ""))
firebaseEvent.setParameter = ("type", "gift")
firebaseEvent.setParameter = ("successful", "false")
SwiftEventBus.post("firebase", sender: firebaseEvent)
self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
}
}
// func postEventRequest() {
// swiftApi().postEventAsync(Session_ID: (campaign?.session_uuid ?? ""), OfferAudienceLevel: (ccms?._offerAudienceLevel ?? ""), msisdn: self.selectedNumber, UACIOfferTrackingCode: (ccms?._uaciOfferTrackingCode ?? ""), OFFERCODE1: (ccms?._offerCode1 ?? ""), SCORE: (ccms?._score ?? ""), ZONE: (ccms?._zone ?? ""), WAVE: (ccms?._wave ?? ""), VALIDITY: (ccms?._validity ?? ""), TREATMENT_CODE: (ccms?._treatmentCode ?? ""), postEventCallback)
// }
// func postEventCallback (_ response: swiftApi.GenericResponseModel?) -> Void {
// if (response != nil) {
// DispatchQueue.main.async {
// if (response?.getStatus == 1) {
// } else {
// }
// }
// } else {
// }
// }
// MARK: - Actions
@IBAction func activateButtomAction(_ sender: Any) {
self.numbersPopupTapped(sender)
}
@IBAction func moreButtonAction(_ sender: Any) {
moreVisible = !moreVisible
toggleMore()
}
}
// MARK: NumbersPopup
extension TelcoViewController: NumbersPopupDelegate {
@objc func numbersPopupTapped(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let pp = storyboard.instantiateViewController(withIdentifier: "NumberPopupViewController") as! SwiftWarplyFramework.NumberPopupViewController
pp.InitWithController(controller: self,
numbersList: self.numbersList,
sender: sender,
delegate: self,
headerText: "Επιλογή σύνδεσης")
}
func presentedPopup() {
// Code for when popup is presented
}
func dismissedPopup() {
// Code for when popup is dismissed
}
func optionSelected(_ option: String) {
// Code for when option is selected
self.selectedNumber = option
DispatchQueue.main.async {
self.showConfirmDialog()
}
}
}