Manos Chorianopoulos

add share coupon ui and functionality

...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
11 1E74838D28378AF40042A589 /* CouponBarcodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E74838C28378AF40042A589 /* CouponBarcodeViewController.swift */; }; 11 1E74838D28378AF40042A589 /* CouponBarcodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E74838C28378AF40042A589 /* CouponBarcodeViewController.swift */; };
12 1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */; }; 12 1EA1AF0A2835346A008998AA /* CouponsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */; };
13 1EA2BB792865BFE8003F2AB0 /* InboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA2BB782865BFE8003F2AB0 /* InboxTableViewCell.swift */; }; 13 1EA2BB792865BFE8003F2AB0 /* InboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA2BB782865BFE8003F2AB0 /* InboxTableViewCell.swift */; };
14 + 1EB236AB28816B680063777A /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB236AA28816B680063777A /* ShareViewController.swift */; };
15 + 1EB236AD28816C560063777A /* NumberPopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB236AC28816C560063777A /* NumberPopupViewController.swift */; };
16 + 1EB236AF28816CAC0063777A /* NumbersTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB236AE28816CAB0063777A /* NumbersTableViewCell.swift */; };
14 1EB5F4C828536FD60016F36E /* StepsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB5F4C728536FD60016F36E /* StepsViewController.swift */; }; 17 1EB5F4C828536FD60016F36E /* StepsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB5F4C728536FD60016F36E /* StepsViewController.swift */; };
15 1EB5F4CA285370C90016F36E /* LoyaltyAnalysisViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */; }; 18 1EB5F4CA285370C90016F36E /* LoyaltyAnalysisViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */; };
16 1EBE97212865EE460080EFF7 /* MFYInboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */; }; 19 1EBE97212865EE460080EFF7 /* MFYInboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */; };
...@@ -148,6 +151,9 @@ ...@@ -148,6 +151,9 @@
148 1E74838C28378AF40042A589 /* CouponBarcodeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponBarcodeViewController.swift; sourceTree = "<group>"; }; 151 1E74838C28378AF40042A589 /* CouponBarcodeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponBarcodeViewController.swift; sourceTree = "<group>"; };
149 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponsTableViewCell.swift; sourceTree = "<group>"; }; 152 1EA1AF092835346A008998AA /* CouponsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponsTableViewCell.swift; sourceTree = "<group>"; };
150 1EA2BB782865BFE8003F2AB0 /* InboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxTableViewCell.swift; sourceTree = "<group>"; }; 153 1EA2BB782865BFE8003F2AB0 /* InboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxTableViewCell.swift; sourceTree = "<group>"; };
154 + 1EB236AA28816B680063777A /* ShareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareViewController.swift; sourceTree = "<group>"; };
155 + 1EB236AC28816C560063777A /* NumberPopupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberPopupViewController.swift; sourceTree = "<group>"; };
156 + 1EB236AE28816CAB0063777A /* NumbersTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumbersTableViewCell.swift; sourceTree = "<group>"; };
151 1EB5F4C728536FD60016F36E /* StepsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepsViewController.swift; sourceTree = "<group>"; }; 157 1EB5F4C728536FD60016F36E /* StepsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepsViewController.swift; sourceTree = "<group>"; };
152 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoyaltyAnalysisViewController.swift; sourceTree = "<group>"; }; 158 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoyaltyAnalysisViewController.swift; sourceTree = "<group>"; };
153 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFYInboxTableViewCell.swift; sourceTree = "<group>"; }; 159 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFYInboxTableViewCell.swift; sourceTree = "<group>"; };
...@@ -350,6 +356,9 @@ ...@@ -350,6 +356,9 @@
350 E6A77A35282BB4CB0045BBA8 /* MakeItAPresentViewController.swift */, 356 E6A77A35282BB4CB0045BBA8 /* MakeItAPresentViewController.swift */,
351 E6A7785A282933E40045BBA8 /* Helpers */, 357 E6A7785A282933E40045BBA8 /* Helpers */,
352 E6A77861282933E50045BBA8 /* Main.storyboard */, 358 E6A77861282933E50045BBA8 /* Main.storyboard */,
359 + 1EB236AA28816B680063777A /* ShareViewController.swift */,
360 + 1EB236AC28816C560063777A /* NumberPopupViewController.swift */,
361 + 1EB236AE28816CAB0063777A /* NumbersTableViewCell.swift */,
353 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */, 362 1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */,
354 1EB5F4C728536FD60016F36E /* StepsViewController.swift */, 363 1EB5F4C728536FD60016F36E /* StepsViewController.swift */,
355 E6A77860282933E40045BBA8 /* MyApi.h */, 364 E6A77860282933E40045BBA8 /* MyApi.h */,
...@@ -803,6 +812,7 @@ ...@@ -803,6 +812,7 @@
803 E6A77A36282BB4CB0045BBA8 /* MakeItAPresentViewController.swift in Sources */, 812 E6A77A36282BB4CB0045BBA8 /* MakeItAPresentViewController.swift in Sources */,
804 E6A77947282933E70045BBA8 /* FMDatabaseQueue.m in Sources */, 813 E6A77947282933E70045BBA8 /* FMDatabaseQueue.m in Sources */,
805 E6A77922282933E60045BBA8 /* NSData+SSToolkitAdditions.m in Sources */, 814 E6A77922282933E60045BBA8 /* NSData+SSToolkitAdditions.m in Sources */,
815 + 1EB236AB28816B680063777A /* ShareViewController.swift in Sources */,
806 E6A778E7282933E60045BBA8 /* DetailsViewController.swift in Sources */, 816 E6A778E7282933E60045BBA8 /* DetailsViewController.swift in Sources */,
807 1EB5F4CA285370C90016F36E /* LoyaltyAnalysisViewController.swift in Sources */, 817 1EB5F4CA285370C90016F36E /* LoyaltyAnalysisViewController.swift in Sources */,
808 E6A7794A282933E70045BBA8 /* FMDatabaseAdditions.m in Sources */, 818 E6A7794A282933E70045BBA8 /* FMDatabaseAdditions.m in Sources */,
...@@ -816,7 +826,9 @@ ...@@ -816,7 +826,9 @@
816 E6A77924282933E70045BBA8 /* NSString+SSToolkitAdditions.m in Sources */, 826 E6A77924282933E70045BBA8 /* NSString+SSToolkitAdditions.m in Sources */,
817 E6A7792A282933E70045BBA8 /* AFNetworkActivityIndicatorManager.m in Sources */, 827 E6A7792A282933E70045BBA8 /* AFNetworkActivityIndicatorManager.m in Sources */,
818 E6A77914282933E60045BBA8 /* WLUserManager.m in Sources */, 828 E6A77914282933E60045BBA8 /* WLUserManager.m in Sources */,
829 + 1EB236AF28816CAC0063777A /* NumbersTableViewCell.swift in Sources */,
819 E6A7794F282933E70045BBA8 /* FMDatabasePool.m in Sources */, 830 E6A7794F282933E70045BBA8 /* FMDatabasePool.m in Sources */,
831 + 1EB236AD28816C560063777A /* NumberPopupViewController.swift in Sources */,
820 E6A778E3282933E60045BBA8 /* WalletViewController.swift in Sources */, 832 E6A778E3282933E60045BBA8 /* WalletViewController.swift in Sources */,
821 E6A7790C282933E60045BBA8 /* WLBeaconManager.m in Sources */, 833 E6A7790C282933E60045BBA8 /* WLBeaconManager.m in Sources */,
822 E6A77940282933E70045BBA8 /* AFURLSessionManager.m in Sources */, 834 E6A77940282933E70045BBA8 /* AFURLSessionManager.m in Sources */,
......
...@@ -164,25 +164,10 @@ import AVFoundation ...@@ -164,25 +164,10 @@ import AVFoundation
164 // MARK: - Actions 164 // MARK: - Actions
165 165
166 @IBAction func redeemButtomAction(_ sender: Any) { 166 @IBAction func redeemButtomAction(_ sender: Any) {
167 - // TODO: Add redeem action 167 + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
168 - 168 + let vc = storyboard.instantiateViewController(withIdentifier: "ShareViewController") as! SwiftWarplyFramework.ShareViewController
169 - // SwiftEventBus.post("couponBarcodeRedeem", sender: coupon) 169 + vc.coupon = self.coupon
170 - 170 + self.navigationController?.pushViewController(vc, animated: true)
171 - let alert = UIAlertController(title: "Το κουπόνι σου ενεργοποιήθηκε", message: "Μπορείς να το βρεις στην αρχική οθόνη της εφαρμογής και στην ενότητα ενεργά δώρα!", preferredStyle: .alert)
172 - alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
173 - switch action.style{
174 - case .default:
175 - print("default")
176 -
177 - case .cancel:
178 - print("cancel")
179 -
180 - case .destructive:
181 - print("destructive")
182 -
183 - }
184 - }))
185 - self.present(alert, animated: true, completion: nil)
186 } 171 }
187 172
188 @IBAction func termsButtonAction(_ sender: Any) { 173 @IBAction func termsButtonAction(_ sender: Any) {
......
1 +{
2 + "images" : [
3 + {
4 + "filename" : "ic_close.png",
5 + "idiom" : "universal",
6 + "scale" : "1x"
7 + },
8 + {
9 + "filename" : "ic_close-1.png",
10 + "idiom" : "universal",
11 + "scale" : "2x"
12 + },
13 + {
14 + "filename" : "ic_close-2.png",
15 + "idiom" : "universal",
16 + "scale" : "3x"
17 + }
18 + ],
19 + "info" : {
20 + "author" : "xcode",
21 + "version" : 1
22 + }
23 +}
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
87 - (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 87 - (void)cosmoteSharingAsync:(NSString*)sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
88 - (void)cosmoteRetrieveSharingAsync:(NSString*)sharingId :(NSNumber*)accept :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 88 - (void)cosmoteRetrieveSharingAsync:(NSString*)sharingId :(NSNumber*)accept :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
89 - (void)getCosmoteUserAsync:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 89 - (void)getCosmoteUserAsync:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
90 +- (void)cosmoteCouponSharingAsync:(NSString*) coupon :(NSString*)sender :(NSString*)receiver :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
90 91
91 @end 92 @end
92 #endif /* MyApi_h */ 93 #endif /* MyApi_h */
......
...@@ -1431,4 +1431,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; ...@@ -1431,4 +1431,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
1431 }]; 1431 }];
1432 } 1432 }
1433 1433
1434 +- (void)cosmoteCouponSharingAsync:(NSString*) coupon :(NSString*)sender :(NSString*)receiver :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1435 +{
1436 + [[Warply sharedService] cosmoteCouponSharingWithSuccessBlock:coupon :sender :receiver :^(NSDictionary *response) {
1437 + if (success) {
1438 + success(response);
1439 + }
1440 + } failureBlock:^(NSError *error) {
1441 + if (failure) {
1442 + failure(error);
1443 + }
1444 + }];
1445 +}
1446 +
1434 @end 1447 @end
......
1 +//
2 +// NumberPopupViewController.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 15/7/22.
6 +//
7 +
8 +import UIKit
9 +
10 +protocol NumbersPopupDelegate {
11 + func numbersPopupTapped(_ sender: Any)
12 + func presentedPopup()
13 + func dismissedPopup()
14 + func optionSelected(_ option: String)
15 +}
16 +
17 +
18 +@objc public class NumberPopupViewController: UIViewController, UIPopoverPresentationControllerDelegate {
19 + @IBOutlet weak var popupView: UIView!
20 + @IBOutlet weak var headerLabel: UILabel!
21 + @IBOutlet weak var closeButton: UIButton!
22 + @IBOutlet weak var tableView: UITableView!
23 +
24 + let uiscreen: CGRect = UIScreen.main.bounds
25 +
26 + var delegateBallon: NumbersPopupDelegate?
27 + var numbersList: Array<String> = []
28 +
29 + var widthPopup: Int = 0
30 + var heightPopup: Int = 0
31 +
32 + func InitWithController(controller: UIViewController, numbersList: Array<String>, sender: Any, delegate: NumbersPopupDelegate){
33 +
34 + //print("Ok InitWithController sender ")
35 +
36 + delegateBallon = delegate
37 +
38 + // set the presentation style
39 + self.modalPresentationStyle = UIModalPresentationStyle.popover
40 +
41 + // set up the popover presentation controller
42 +// self.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up
43 + self.popoverPresentationController?.delegate = self
44 + self.popoverPresentationController?.sourceView = (sender as! UIView ) // button
45 + //--- Better center of the arrow
46 +// let rect: CGRect = (sender as AnyObject).bounds
47 +// let rectFixed: CGRect = CGRect(x: rect.origin.x, y: rect.origin.y, width: rect.size.width-10, height: rect.size.height)
48 +// self.popoverPresentationController?.sourceRect = rectFixed
49 + self.popoverPresentationController?.backgroundColor = UIColor.clear
50 +// self.popoverPresentationController?.backgroundColor = UIColor(red: 0.22, green: 0.32, blue: 0.40, alpha: 0.58)
51 +
52 + DispatchQueue.main.async {
53 + // present the popover
54 + controller.present(self, animated: true, completion: nil)
55 + }
56 + self.numbersList = numbersList
57 + }
58 +
59 + public override func viewWillAppear(_ animated: Bool) {
60 +// self.SetInfoText(t: infoText ?? "")
61 + }
62 +
63 + public override func viewDidLoad() {
64 + super.viewDidLoad()
65 + // Do any additional setup after loading the view, typically from a nib.
66 +// setupScreens()
67 +
68 + tableView.delegate = self
69 + tableView.dataSource = self
70 +
71 + popupView.clipsToBounds = true
72 + popupView.layer.cornerRadius = 12
73 + popupView.layer.maskedCorners = [ .layerMinXMinYCorner, .layerMaxXMinYCorner] // Top left, right corner radius
74 +
75 + self.preferredContentSize = CGSize(width: widthPopup, height: heightPopup)
76 +
77 + closeButton.setImage(UIImage(named: "ic_close.png", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil), for: .normal)
78 + closeButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
79 +
80 +// self.tableView.reloadData()
81 + self.tableView.invalidateIntrinsicContentSize()
82 + }
83 +
84 + func setupScreens() {
85 +// if UIDevice.current.userInterfaceIdiom == .pad {
86 +// // Do what you want
87 +// widthPopup = 450
88 +// heightPopup = 550
89 +// textView.font = UIFont(name: Fonts.ProximaNova.semibold, size: 20)
90 +// } else if UIDevice.current.userInterfaceIdiom == .phone {
91 +// // Do what you want
92 +// widthPopup = 250
93 +// heightPopup = 360
94 +// textView.font = UIFont(name: Fonts.ProximaNova.semibold, size: 14)
95 +// }
96 + }
97 +
98 + public override func viewDidAppear(_ animated: Bool) {
99 + delegateBallon?.presentedPopup()
100 + }
101 +
102 + public override func viewDidDisappear(_ animated: Bool) {
103 + delegateBallon?.dismissedPopup()
104 + }
105 +
106 +// func SetInfoText(t: String){
107 +// infoTextView.text = t
108 +// infoTextView.scrollRangeToVisible(NSRange(location:0, length:0))
109 +// }
110 +
111 + public override func didReceiveMemoryWarning() {
112 + super.didReceiveMemoryWarning()
113 + // Dispose of any resources that can be recreated.
114 + }
115 +
116 + public override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
117 + //print("In prepare")
118 + }
119 +
120 + public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
121 + return UIModalPresentationStyle.fullScreen
122 + }
123 +
124 + public func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
125 + return UIModalPresentationStyle.fullScreen
126 +// return UIModalPresentationStyle.none
127 + }
128 +
129 + // MARK: - UIButton Action
130 + @IBAction func closeButtonAction(_ sender: Any) {
131 + self.dismiss(animated: true, completion: {
132 +
133 + })
134 + }
135 +
136 +}
137 +
138 +// MARK: - TableView
139 +extension NumberPopupViewController: UITableViewDelegate, UITableViewDataSource{
140 +
141 + public func numberOfSections(in tableView: UITableView) -> Int {
142 + return 1
143 + }
144 +
145 + public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
146 + return self.numbersList.count
147 + }
148 +
149 + public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
150 + return 50 //+ 30.0
151 +// return UITableViewAutomaticDimension
152 + }
153 +
154 + public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
155 + let cell = tableView.dequeueReusableCell(withIdentifier: "NumbersTableViewCellId", for: indexPath) as! NumbersTableViewCell
156 + let isLast = indexPath.row == (self.numbersList.count - 1)
157 +
158 + cell.configureCell(number: numbersList[indexPath.row], isLast: isLast)
159 +
160 + return cell
161 + }
162 +
163 + public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
164 + delegateBallon?.optionSelected(self.numbersList[indexPath.row])
165 + self.dismiss(animated: true, completion: {})
166 +
167 + // Logs
168 +// let couponSetData: swiftApi.CouponSetItemModel? = coupons[indexPath.row].couponset_data
169 +// print("Coupon clicked: " + (coupons[indexPath.row].coupon ?? ""))
170 +// print("Coupon Name clicked: " + (couponSetData?.name ?? ""))
171 +// print("Coupon Description clicked: " + (couponSetData?.short_description ?? ""))
172 +// print("Coupon Expiration clicked: " + (coupons[indexPath.row].expiration ?? ""))
173 +//
174 +// let storyboard = UIStoryboard(name: "Main", bundle: nil)
175 +// let vc = storyboard.instantiateViewController(withIdentifier: "CouponBarcodeViewController") as! CouponBarcodeViewController
176 +// vc.coupon = coupons[indexPath.row]
177 +// self.navigationController?.pushViewController(vc, animated: true)
178 +
179 + }
180 +
181 +}
182 +
183 +// Class for dynamic height table view
184 +@objc public class DynamicSizeTableView: UITableView
185 +{
186 + override public func layoutSubviews() {
187 + super.layoutSubviews()
188 + if bounds.size != intrinsicContentSize {
189 + invalidateIntrinsicContentSize()
190 + }
191 + }
192 +
193 + override public var intrinsicContentSize: CGSize {
194 + return contentSize
195 + }
196 +}
197 +
1 +//
2 +// NumbersTableViewCell.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 15/7/22.
6 +//
7 +
8 +import UIKit
9 +
10 +@objc public class NumbersTableViewCell: UITableViewCell {
11 + @IBOutlet weak var numberLabel: UILabel!
12 + @IBOutlet weak var borderView: UIView!
13 +
14 + public override func awakeFromNib() {
15 + super.awakeFromNib()
16 + // Initialization code
17 + }
18 +
19 + public override func setSelected(_ selected: Bool, animated: Bool) {
20 + super.setSelected(selected, animated: animated)
21 +
22 + // Configure the view for the selected state
23 + }
24 +
25 +
26 +// override func layoutSubviews() {
27 +// super.layoutSubviews()
28 +//
29 +// //set the values for top,left,bottom,right margins
30 +// let margins = UIEdgeInsets(top: 0, left: 0, bottom: 30, right: 0)
31 +// contentView.frame = contentView.frame.inset(by: margins)
32 +// }
33 +
34 +
35 + func configureCell(number: String, isLast: Bool) {
36 + numberLabel.text = number
37 + if (isLast) {
38 + borderView.isHidden = true
39 + } else {
40 + borderView.isHidden = false
41 + }
42 + }
43 +
44 +}
1 +//
2 +// ShareViewController.swift
3 +// SwiftWarplyFramework
4 +//
5 +// Created by Manos Chorianopoulos on 15/7/22.
6 +//
7 +
8 +import UIKit
9 +
10 +@objc public class ShareViewController: UIViewController, UITextFieldDelegate, UIPopoverControllerDelegate {
11 + @IBOutlet weak var mainView: UIView!
12 + @IBOutlet weak var mainViewBottom: NSLayoutConstraint!
13 + @IBOutlet weak var backgroundImage: UIImageView!
14 + @IBOutlet weak var scrollView: UIScrollView!
15 + @IBOutlet weak var scrollContentView: UIView!
16 + @IBOutlet weak var couponImage: UIImageView!
17 + @IBOutlet weak var couponImageHeight: NSLayoutConstraint!
18 + @IBOutlet weak var nameLabel: UILabel!
19 + @IBOutlet weak var descriptionLabel: UILabel!
20 + @IBOutlet weak var senderLabel: UILabel!
21 + @IBOutlet weak var senderArrowImage: UIImageView!
22 + @IBOutlet weak var senderButton: UIButton!
23 + @IBOutlet weak var numberTextField: UITextField!
24 + @IBOutlet weak var redeemButton: UIButton!
25 +
26 + let uiscreen: CGRect = UIScreen.main.bounds
27 +
28 + public var coupon: swiftApi.CouponItemModel?
29 + var selectedNumber: String = ""
30 + var numbersList: Array<String> = []
31 +
32 + public override func viewDidLoad() {
33 + super.viewDidLoad()
34 +
35 + self.hidesBottomBarWhenPushed = true
36 +
37 + NotificationCenter.default.addObserver(self,
38 + selector: #selector(self.keyboardNotification(notification:)),
39 + name: UIResponder.keyboardWillChangeFrameNotification,
40 + object: nil)
41 +
42 + self.setupToHideKeyboardOnTapOnView()
43 + numberTextField.delegate = self
44 +
45 + getProfileRequest()
46 +
47 + // Do any additional setup after loading the view.
48 + setBackButton()
49 + setNavigationTitle("Κάντο δώρο!")
50 +
51 + backgroundImage.image = UIImage(named: "coupons_scrollview_white", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil)
52 +
53 + scrollView.clipsToBounds = true
54 + scrollView.layer.cornerRadius = 30
55 + scrollView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
56 +
57 + // COUPONSET: desc, img_preview, name, terms
58 + // COUPON: coupon, expiration, discount, status
59 +
60 + let couponSetData: swiftApi.CouponSetItemModel? = coupon?.couponset_data
61 +
62 + couponImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
63 + couponImage.contentMode = .scaleAspectFill
64 + couponImageHeight.constant = self.uiscreen.height * 0.25
65 +
66 + nameLabel.text = couponSetData?.name ?? ""
67 + descriptionLabel.text = couponSetData?.short_description ?? ""
68 +
69 + senderLabel.text = "Αποστολέας"
70 + senderArrowImage.image = UIImage(named: "ic_down_dark", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil)
71 +
72 + senderButton.addTarget(self, action: #selector(self.numbersPopupTapped(_:)), for: .touchUpInside)
73 +
74 + numberTextField.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.medium)
75 + numberTextField.textColor = UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00)
76 + numberTextField.attributedPlaceholder = NSAttributedString(string: "Καταχώρηση τηλεφώνου", attributes: [NSAttributedString.Key.foregroundColor: UIColor(red: 0.68, green: 0.68, blue: 0.68, alpha: 1.00)])
77 + numberTextField.keyboardType = .asciiCapableNumberPad
78 +
79 + redeemButton.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .semibold)
80 + redeemButton.setTitle("Αποστολή με SMS", for: .normal)
81 + redeemButton.setTitleColor(.white, for: .normal)
82 + redeemButton.backgroundColor = UIColor(red: 0.47, green: 0.75, blue: 0.08, alpha: 1.00)
83 + redeemButton.layer.cornerRadius = 12.0
84 +
85 + }
86 +
87 + deinit {
88 + NotificationCenter.default.removeObserver(self)
89 + }
90 +
91 + @objc func keyboardNotification(notification: NSNotification) {
92 + guard let userInfo = notification.userInfo else { return }
93 +
94 + let endFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
95 + let endFrameY = endFrame?.origin.y ?? 0
96 + let duration:TimeInterval = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
97 + let animationCurveRawNSN = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber
98 + let animationCurveRaw = animationCurveRawNSN?.uintValue ?? UIView.AnimationOptions.curveEaseInOut.rawValue
99 + let animationCurve:UIView.AnimationOptions = UIView.AnimationOptions(rawValue: animationCurveRaw)
100 +
101 + if endFrameY >= UIScreen.main.bounds.size.height {
102 + self.mainViewBottom?.constant = 0.0
103 + } else {
104 + self.mainViewBottom?.constant = endFrame?.size.height ?? 0.0
105 + }
106 +
107 + UIView.animate(
108 + withDuration: duration,
109 + delay: TimeInterval(0),
110 + options: animationCurve,
111 + animations: { self.view.layoutIfNeeded() },
112 + completion: nil)
113 + }
114 +
115 + // MARK: - Functions
116 + func showSendDialog() -> Void {
117 +
118 + let alert = UIAlertController(title: "Στείλε δώρο", message: "Είσαι σίγουρος ότι θέλεις να κάνεις δώρο το κουπόνι σου;", preferredStyle: .alert)
119 + alert.addAction(UIAlertAction(title: "Αποστολή", style: .default, handler: { action in
120 + switch action.style{
121 + case .default:
122 + self.cosmoteCouponSharingRequest()
123 +
124 + case .cancel:
125 + print("cancel")
126 +
127 + case .destructive:
128 + print("destructive")
129 +
130 + }
131 + }))
132 + alert.addAction(UIAlertAction(title: "Άκυρο", style: .default, handler: { action in
133 + switch action.style{
134 + case .default:
135 + print("default")
136 +
137 + case .cancel:
138 + print("cancel")
139 +
140 + case .destructive:
141 + print("destructive")
142 +
143 + }
144 + }))
145 + self.present(alert, animated: true, completion: nil)
146 + }
147 +
148 + func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void {
149 +
150 + let alert = UIAlertController(title: alertTitle, message: alertSubTitle, preferredStyle: .alert)
151 + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
152 + switch action.style{
153 + case .default:
154 + print("default")
155 +
156 + case .cancel:
157 + print("cancel")
158 +
159 + case .destructive:
160 + print("destructive")
161 +
162 + }
163 + }))
164 + self.present(alert, animated: true, completion: nil)
165 + }
166 +
167 + // MARK: - API Calls
168 + func getProfileRequest() {
169 + swiftApi().getProfileAsync(getProfileCallback)
170 + }
171 +
172 + func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void {
173 + if (profileData != nil) {
174 + DispatchQueue.main.async {
175 + self.numbersList = profileData?.msisdnList ?? []
176 +
177 + print("========= getProfileRequest SUCCESSSS =========")
178 + }
179 + } else {
180 + print("========= getProfileRequest ERROR =========")
181 + }
182 + }
183 +
184 + func cosmoteCouponSharingRequest() {
185 + swiftApi().cosmoteCouponSharingAsync(coupon: coupon?.coupon ?? "", sender: selectedNumber, receiver: numberTextField.text ?? "", couponSharingCallback)
186 + }
187 +
188 + func couponSharingCallback (_ response: swiftApi.GenericResponseModel?) -> Void {
189 + if (response != nil) {
190 + DispatchQueue.main.async {
191 + if (response?.getStatus == 1) {
192 + self.showDialog("Συγχαρητήρια!","Μόλις έκανες δώρο ένα κουπόνι!")
193 +
194 +// swiftApi().getCouponsAsync(getCouponsCallback)
195 +//
196 +// func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
197 +// if (couponsData != nil) {
198 +//
199 +// DispatchQueue.main.async {
200 +// print("========= getCouponsRequest SUCCESSSS CouponViewController =========")
201 +// }
202 +// } else {
203 +// print("========= getCouponsRequest ERROR CouponViewController =========")
204 +// }
205 +// }
206 + } else {
207 + self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
208 + }
209 + }
210 + } else {
211 + self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
212 + }
213 + }
214 +
215 + // MARK: - Actions
216 + @IBAction func redeemButtomAction(_ sender: Any) {
217 + if (selectedNumber == "" || numberTextField.text == "") {
218 + self.showDialog("Αποτυχία","Τα πεδία δεν είναι σωστά")
219 + } else {
220 + self.showSendDialog()
221 + }
222 + }
223 +
224 +}
225 +
226 +// MARK: NumbersPopup
227 +extension ShareViewController: NumbersPopupDelegate {
228 + @objc func numbersPopupTapped(_ sender: Any) {
229 + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
230 + // self.storyboard?
231 + let pp = storyboard.instantiateViewController(withIdentifier: "NumberPopupViewController") as! SwiftWarplyFramework.NumberPopupViewController
232 + pp.InitWithController(controller: self,
233 + numbersList: self.numbersList,
234 + sender: sender,
235 + delegate: self)
236 + }
237 +
238 + func presentedPopup() {
239 +// Code for when popup is presented
240 + }
241 +
242 + func dismissedPopup() {
243 +// Code for when popup is dismissed
244 + }
245 +
246 + func optionSelected(_ option: String) {
247 +// Code for when option is selected
248 + selectedNumber = option
249 + senderLabel.text = option
250 + }
251 +}
252 +
...@@ -378,6 +378,8 @@ WL_VERSION_INTERFACE() ...@@ -378,6 +378,8 @@ WL_VERSION_INTERFACE()
378 378
379 - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 379 - (void) redeemCouponSetsWithSuccessBlock:(NSString*) uuid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
380 380
381 +- (void) cosmoteCouponSharingWithSuccessBlock:(NSString*) coupon :(NSString*)sender :(NSString*)receiver :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
382 +
381 - (void) cosmoteSharingWithSuccessBlock:(NSString*) sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 383 - (void) cosmoteSharingWithSuccessBlock:(NSString*) sharingId :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
382 384
383 - (void) cosmoteRetrieveSharingWithSuccessBlock:(NSString*) sharingId :(NSNumber*)accept :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 385 - (void) cosmoteRetrieveSharingWithSuccessBlock:(NSString*) sharingId :(NSNumber*)accept :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
......
...@@ -1949,7 +1949,48 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) ...@@ -1949,7 +1949,48 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
1949 NSLog(@"Error at token %@", error ); 1949 NSLog(@"Error at token %@", error );
1950 }]; 1950 }];
1951 } 1951 }
1952 - NSLog(@"Error at get coupon sets %@", error ); 1952 + NSLog(@"Error at redeem coupon sets %@", error );
1953 + }
1954 + }];
1955 +}
1956 +
1957 +- (void) cosmoteCouponSharingWithSuccessBlock:(NSString*) coupon :(NSString*)sender :(NSString*)receiver :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1958 +{
1959 + NSDictionary *postDictionary = @{@"coupon": @{@"action": @"share", @"coupon": coupon, @"sender_msisdn": sender, @"receiver_msisdn": receiver}};
1960 + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
1961 + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
1962 + if (success) {
1963 + success(contextResponse);
1964 + }
1965 + NSLog(@"**************** WARPLY Response *****************" );
1966 + NSLog(@"%@", contextResponse );
1967 + } failureBlock:^(NSError *error) {
1968 + if (failure) {
1969 + NSDictionary* dict = [NSDictionary alloc];
1970 + dict = [error userInfo];
1971 + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
1972 + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
1973 + [self refreshToken:^(NSDictionary *response) {
1974 + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
1975 + if (success) {
1976 + success(contextResponse);
1977 + }
1978 + NSLog(@"**************** WARPLY Response *****************" );
1979 + NSLog(@"%@", contextResponse );
1980 + } failureBlock:^(NSError *error) {
1981 + if (failure) {
1982 + failure(error);
1983 + }
1984 + }];
1985 + } failureBlock:^(NSError *error) {
1986 + if (failure) {
1987 + [_db executeUpdate:@"DROP TABLE requestVariables"];
1988 + failure(error);
1989 + }
1990 + NSLog(@"Error at token %@", error );
1991 + }];
1992 + }
1993 + NSLog(@"Error at cosmote Coupon Sharing %@", error );
1953 } 1994 }
1954 }]; 1995 }];
1955 } 1996 }
......
...@@ -1216,6 +1216,9 @@ public class swiftApi { ...@@ -1216,6 +1216,9 @@ public class swiftApi {
1216 1216
1217 let tempProfile = ProfileModel(dictionary: profileDataResult) 1217 let tempProfile = ProfileModel(dictionary: profileDataResult)
1218 1218
1219 + swiftApi().setConsumer(tempProfile ?? swiftApi.ProfileModel())
1220 + swiftApi().setUserTag(tempProfile.badge ?? "")
1221 +
1219 getProfileCallback(tempProfile); 1222 getProfileCallback(tempProfile);
1220 1223
1221 } else { 1224 } else {
...@@ -3034,4 +3037,32 @@ public class swiftApi { ...@@ -3034,4 +3037,32 @@ public class swiftApi {
3034 } 3037 }
3035 } 3038 }
3036 3039
3040 +
3041 + public func cosmoteCouponSharingAsync(coupon: String, sender: String, receiver: String, _ couponSharingCallback: @escaping (_ responseData: GenericResponseModel?) -> Void) -> Void {
3042 +
3043 + let instanceOfMyApi = MyApi()
3044 + instanceOfMyApi.cosmoteCouponSharingAsync(coupon, sender, receiver, requestCallback, failureBlock: requestFailureCallback)
3045 +
3046 + func requestCallback(_ responseData: [AnyHashable: Any]?) -> Void {
3047 +
3048 + if let responseDataDictionary = responseData as? [String: Any] {
3049 +
3050 + let tempResponse = GenericResponseModel(dictionary: responseDataDictionary)
3051 +
3052 + couponSharingCallback(tempResponse);
3053 +
3054 + } else {
3055 + couponSharingCallback(nil)
3056 + }
3057 +
3058 + }
3059 +
3060 + func requestFailureCallback(_ error: Error?) -> Void {
3061 + print("cosmoteCouponSharing error: ")
3062 + print(error)
3063 + print("====================")
3064 + couponSharingCallback(nil)
3065 + }
3066 + }
3067 +
3037 } 3068 }
......