Merge remote-tracking branch 'origin/feat/analysis_vc' into swift_sdk_development
Showing
15 changed files
with
595 additions
and
12 deletions
This diff is collapsed. Click to expand it.
1 | { | 1 | { |
2 | "pins" : [ | 2 | "pins" : [ |
3 | { | 3 | { |
4 | + "identity" : "resegmentedcontrol", | ||
5 | + "kind" : "remoteSourceControl", | ||
6 | + "location" : "https://github.com/sh-khashimov/RESegmentedControl", | ||
7 | + "state" : { | ||
8 | + "revision" : "09d8cbd0da906c06d30fb057ab9902dc9d0e26b9", | ||
9 | + "version" : "0.5.1" | ||
10 | + } | ||
11 | + }, | ||
12 | + { | ||
4 | "identity" : "rsbarcodes_swift", | 13 | "identity" : "rsbarcodes_swift", |
5 | "kind" : "remoteSourceControl", | 14 | "kind" : "remoteSourceControl", |
6 | "location" : "https://github.com/yeahdongcn/RSBarcodes_Swift", | 15 | "location" : "https://github.com/yeahdongcn/RSBarcodes_Swift", | ... | ... |
1 | +// | ||
2 | +// AnalysisHeaderMessageViewCell.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class AnalysisHeaderMessageViewCell: UITableViewCell { | ||
11 | + | ||
12 | + // attributes | ||
13 | + @IBOutlet weak var itemImage: UIImageView! | ||
14 | + @IBOutlet weak var messageLabel: UILabel! | ||
15 | + @IBOutlet weak var titleLabel: UILabel! | ||
16 | + | ||
17 | + public var loyaltyBadge:swiftApi.LoyaltyBadgeModel = swiftApi().getLoyaltyBadge() | ||
18 | + | ||
19 | + // lifecycle | ||
20 | + override func awakeFromNib() { | ||
21 | + super.awakeFromNib() | ||
22 | + | ||
23 | + // image | ||
24 | + itemImage.image = UIImage(named: "ic_gift_circle", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil) | ||
25 | + | ||
26 | + // title | ||
27 | + titleLabel.textColor = UIColor(rgb: 0x435563) | ||
28 | + titleLabel.text = "Αναλυτικά:" | ||
29 | + | ||
30 | + // message | ||
31 | + messageLabel.textColor = UIColor(rgb: 0x435563) | ||
32 | + messageLabel.layer.borderWidth = 1.0 | ||
33 | + messageLabel.layer.borderColor = UIColor(rgb: 0xB2CE69).cgColor | ||
34 | + | ||
35 | + let totalCouponDiscount = Float(round(100 * loyaltyBadge._value) / 100) | ||
36 | + var totalCouponDiscountString = "0" | ||
37 | + totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil) | ||
38 | + | ||
39 | + messageLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(loyaltyBadge._couponCount) + " κουπόνια!" | ||
40 | + } | ||
41 | +} | ||
42 | + | ||
43 | +extension AnalysisHeaderMessageViewCell { | ||
44 | + func configureCell(item: AnalysisItem) { | ||
45 | + | ||
46 | + // TODO: TO BE IMPLEMENTED | ||
47 | + } | ||
48 | +} |
1 | +// | ||
2 | +// AnalysisHeaderViewCell.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class AnalysisHeaderViewCell: UITableViewCell { | ||
11 | + | ||
12 | + // attributes | ||
13 | + @IBOutlet weak var itemImage: UIImageView! | ||
14 | + @IBOutlet weak var titleLabel: UILabel! | ||
15 | + | ||
16 | + // lifecycle | ||
17 | + override func awakeFromNib() { | ||
18 | + super.awakeFromNib() | ||
19 | + | ||
20 | + // image | ||
21 | + itemImage.image = UIImage(named: "ic_gift_circle", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil) | ||
22 | + | ||
23 | + // title | ||
24 | + titleLabel.textColor = UIColor(rgb: 0x435563) | ||
25 | + titleLabel.text = "Αναλυτικά:" | ||
26 | + } | ||
27 | +} | ||
28 | + | ||
29 | +extension AnalysisHeaderViewCell { | ||
30 | + func configureCell(item: AnalysisItem) { | ||
31 | + | ||
32 | + // TODO: TO BE IMPLEMENTED | ||
33 | + } | ||
34 | +} |
1 | +// | ||
2 | +// AnalysisItem.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +public class AnalysisItem: Codable { | ||
11 | + | ||
12 | + // attributes | ||
13 | + public var date: Date | ||
14 | + public var image_url: String? | ||
15 | + public var title: String? | ||
16 | + public let subtitle: String? | ||
17 | + public var price: Float | ||
18 | + | ||
19 | + // initialization | ||
20 | + public init() { | ||
21 | + self.date = Date() | ||
22 | + self.image_url = "" | ||
23 | + self.title = "" | ||
24 | + self.subtitle = "" | ||
25 | + self.price = 4.0 | ||
26 | + } | ||
27 | +} |
1 | +// | ||
2 | +// AnalysisItemViewCell.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class AnalysisItemViewCell: UITableViewCell { | ||
11 | + | ||
12 | + @IBOutlet weak var dateLabel: UILabel! | ||
13 | + @IBOutlet weak var itemImage: UIImageView! | ||
14 | + @IBOutlet weak var titleLabel: UILabel! | ||
15 | + @IBOutlet weak var priceLabel: UILabel! | ||
16 | + @IBOutlet weak var subtitleLabel: UILabel! | ||
17 | + | ||
18 | + // lifecycle | ||
19 | + override func awakeFromNib() { | ||
20 | + super.awakeFromNib() | ||
21 | + | ||
22 | + // date | ||
23 | + dateLabel.textColor = UIColor(rgb: 0x435563) | ||
24 | + | ||
25 | + // title | ||
26 | + titleLabel.textColor = UIColor(rgb: 0x435563) | ||
27 | + | ||
28 | + // price | ||
29 | + priceLabel.textColor = UIColor(rgb: 0x435563) | ||
30 | + | ||
31 | + // subtitle | ||
32 | + subtitleLabel.textColor = UIColor(rgb: 0x8B97A3) | ||
33 | + } | ||
34 | +} | ||
35 | + | ||
36 | +extension AnalysisItemViewCell { | ||
37 | + func configureCell(item: swiftApi.SharingCouponModel) { | ||
38 | + | ||
39 | + dateLabel.text = item._date | ||
40 | + //itemImage.image = | ||
41 | + titleLabel.text = item._name | ||
42 | + | ||
43 | + let priceFloat = Float(round(100 * (Float(item._discount) ?? 0.0)) / 100) | ||
44 | + var priceString = "0" | ||
45 | + priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil) | ||
46 | + priceLabel.text = priceString + "€" | ||
47 | + | ||
48 | + if ("sent" == item._sharing_type) { | ||
49 | + subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς " + item._receiver_msisdn) | ||
50 | + } else if ("received" == item._sharing_type) { | ||
51 | + subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από " + item._sender_msisdn) | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
55 | + func configureCell(item: swiftApi.CouponItemModel) { | ||
56 | + | ||
57 | +// COUPONSET: desc, img_preview, name, terms | ||
58 | +// COUPON: coupon, expiration, discount, status | ||
59 | + | ||
60 | + let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data | ||
61 | + | ||
62 | + dateLabel.text = item.expiration ?? "" // TODO: change | ||
63 | + itemImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache()) | ||
64 | + titleLabel.text = couponSetData?.name ?? "" | ||
65 | + | ||
66 | + let priceFloat = Float(round(100 * (Float(item.discount ?? "") ?? 0.0)) / 100) | ||
67 | + var priceString = "0" | ||
68 | + priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil) | ||
69 | + priceLabel.text = priceString + "€" | ||
70 | + | ||
71 | + subtitleLabel.text = couponSetData?.short_description ?? "" | ||
72 | + | ||
73 | + } | ||
74 | +} |
1 | +// | ||
2 | +// HistoryViewController.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class HistoryViewController: AnalysisChildViewController { | ||
11 | + | ||
12 | + var loading: Bool = false | ||
13 | + var items: Array<swiftApi.CouponItemModel> = swiftApi().getCouponList() | ||
14 | + | ||
15 | + // TODO: remove this when configuring model | ||
16 | + let hasMessage = true | ||
17 | + | ||
18 | + // lifecycle | ||
19 | + override func viewDidLoad() { | ||
20 | + | ||
21 | + super.viewDidLoad() | ||
22 | + | ||
23 | + self.refreshControl = UIRefreshControl() | ||
24 | + self.refreshControl?.addTarget(self, action: #selector(handleRefresh(_:)), for: .valueChanged) | ||
25 | + | ||
26 | + handleRefresh(self.refreshControl!) | ||
27 | + } | ||
28 | + | ||
29 | + // mvp | ||
30 | + @objc func load() { | ||
31 | + | ||
32 | + if (loading) { | ||
33 | + return; | ||
34 | + } | ||
35 | + | ||
36 | + showLoading() | ||
37 | + | ||
38 | + items = swiftApi().getOldCouponList() | ||
39 | + showContent() | ||
40 | + self.tableView.reloadData() | ||
41 | + } | ||
42 | + | ||
43 | + private func showLoading() { | ||
44 | + | ||
45 | + loading = true | ||
46 | + if (self.refreshControl!.isRefreshing) { | ||
47 | + return; | ||
48 | + } | ||
49 | + | ||
50 | + self.refreshControl!.beginRefreshing() | ||
51 | + } | ||
52 | + | ||
53 | + private func showError() { | ||
54 | + } | ||
55 | + | ||
56 | + private func showContent() { | ||
57 | + | ||
58 | + loading = false | ||
59 | + self.refreshControl!.endRefreshing() | ||
60 | + } | ||
61 | + | ||
62 | + // private | ||
63 | + func responseCallback (_ data: Array<swiftApi.CouponItemModel>?) -> Void { | ||
64 | + | ||
65 | + self.items = data! | ||
66 | + showContent() | ||
67 | + DispatchQueue.main.async { | ||
68 | + self.tableView.reloadData() | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + @objc func handleRefresh(_ refreshControl: UIRefreshControl) { | ||
73 | + | ||
74 | + self.perform(_: #selector(load), with: nil, afterDelay: 0.5) | ||
75 | + } | ||
76 | + | ||
77 | + // MARK: - Table view data source | ||
78 | + override func numberOfSections(in tableView: UITableView) -> Int { | ||
79 | + return 2 | ||
80 | + } | ||
81 | + | ||
82 | + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
83 | + if (section == 0) { | ||
84 | + return 1; | ||
85 | + } | ||
86 | + | ||
87 | + return items.count | ||
88 | + } | ||
89 | + | ||
90 | + override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | ||
91 | + if (indexPath.section == 0) { | ||
92 | + return hasMessage ? 380.0 : 280 | ||
93 | + } | ||
94 | + | ||
95 | + return 140.0 | ||
96 | + } | ||
97 | + | ||
98 | + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
99 | + | ||
100 | + // header | ||
101 | + if (indexPath.section == 0) { | ||
102 | + if (hasMessage) { | ||
103 | + return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderMessageViewCell", for: indexPath) as! AnalysisHeaderMessageViewCell | ||
104 | + } | ||
105 | + | ||
106 | + return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderViewCell", for: indexPath) as! AnalysisHeaderViewCell | ||
107 | + } | ||
108 | + | ||
109 | + let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! AnalysisItemViewCell | ||
110 | + cell.configureCell(item: items[indexPath.row]) | ||
111 | + | ||
112 | + return cell | ||
113 | + } | ||
114 | +} |
... | @@ -2,30 +2,133 @@ | ... | @@ -2,30 +2,133 @@ |
2 | // LoyaltyAnalysisViewController.swift | 2 | // LoyaltyAnalysisViewController.swift |
3 | // SwiftWarplyFramework | 3 | // SwiftWarplyFramework |
4 | // | 4 | // |
5 | -// Created by Manos Chorianopoulos on 10/6/22. | 5 | +// Created by Manos Chorianopoulos on 18/7/22. |
6 | // | 6 | // |
7 | 7 | ||
8 | import UIKit | 8 | import UIKit |
9 | +import RESegmentedControl | ||
9 | 10 | ||
10 | @objc public class LoyaltyAnalysisViewController: UIViewController { | 11 | @objc public class LoyaltyAnalysisViewController: UIViewController { |
11 | - | 12 | + |
13 | + @IBOutlet weak var leftButton: UIButton! | ||
14 | + @IBOutlet weak var rightButton: UIButton! | ||
15 | + @IBOutlet weak var contentView: UIView! | ||
16 | + var pageController: UIPageViewController! | ||
17 | + | ||
12 | public override func viewDidLoad() { | 18 | public override func viewDidLoad() { |
13 | super.viewDidLoad() | 19 | super.viewDidLoad() |
14 | 20 | ||
15 | self.hidesBottomBarWhenPushed = true | 21 | self.hidesBottomBarWhenPushed = true |
16 | - | 22 | + |
17 | - // Do any additional setup after loading the view. | 23 | + // setup view |
24 | + setBackButton() | ||
25 | + setNavigationTitle("Ανάλυση") | ||
26 | + | ||
27 | + // tab | ||
28 | + leftButton.setTitle("Εξαργυρωμένα", for:.normal) | ||
29 | + leftButton.backgroundColor = . clear | ||
30 | + leftButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal) | ||
31 | + | ||
32 | + rightButton.setTitle("Μοιρασμένα δώρα", for:.normal) | ||
33 | + rightButton.backgroundColor = . clear | ||
34 | + rightButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal) | ||
35 | + | ||
36 | + // pages | ||
37 | + pageController = UIPageViewController(transitionStyle:.scroll, navigationOrientation:.horizontal) | ||
38 | + pageController.dataSource = self; | ||
39 | + pageController.delegate = self; | ||
40 | + | ||
41 | + pageController.view.frame = contentView.bounds; | ||
42 | + addChild(pageController) | ||
43 | + contentView.addSubview(pageController.view) | ||
44 | + pageController .didMove(toParent: self) | ||
45 | + | ||
46 | + let analysisVC = self.viewControllerAt(0) | ||
47 | + pageController.setViewControllers([analysisVC!], direction:.forward, animated:false) | ||
18 | } | 48 | } |
19 | 49 | ||
50 | + //////////////////////////////////////////////////////////////////////////////// | ||
51 | + private func viewControllerAt(_ index:Int) -> AnalysisChildViewController? | ||
52 | + { | ||
53 | + let storyboard = UIStoryboard(name: "Main", bundle: nil) | ||
54 | + | ||
55 | + if (index == 1) { | ||
56 | + let analysisVC = storyboard.instantiateViewController(withIdentifier:"SharingHistoryViewController") as! SharingHistoryViewController | ||
57 | + analysisVC.index = index; | ||
58 | + | ||
59 | + return analysisVC; | ||
60 | + } | ||
20 | 61 | ||
21 | - /* | 62 | + let analysisVC = storyboard.instantiateViewController(withIdentifier:"HistoryViewController") as! HistoryViewController |
22 | - // MARK: - Navigation | 63 | + analysisVC.index = index; |
23 | 64 | ||
24 | - // In a storyboard-based application, you will often want to do a little preparation before navigation | 65 | + return analysisVC; |
25 | - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | 66 | + } |
26 | - // Get the new view controller using segue.destination. | 67 | + |
27 | - // Pass the selected object to the new view controller. | 68 | + // MARK: - Handlers |
69 | + @IBAction func handleLeft() { | ||
70 | + | ||
71 | + let analysisVC = self.viewControllerAt(0) | ||
72 | + pageController.setViewControllers([analysisVC!], direction:.reverse, animated:true) | ||
73 | + } | ||
74 | + | ||
75 | + @IBAction func handleRight() { | ||
76 | + | ||
77 | + let analysisVC = self.viewControllerAt(1) | ||
78 | + pageController.setViewControllers([analysisVC!], direction:.forward, animated:true) | ||
28 | } | 79 | } |
29 | - */ | 80 | +} |
30 | 81 | ||
82 | +// MARK: - PageViewController | ||
83 | +extension LoyaltyAnalysisViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate { | ||
84 | + | ||
85 | + public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { | ||
86 | + | ||
87 | + if let analysisVC = viewController as? AnalysisChildViewController { | ||
88 | + var index = analysisVC.index | ||
89 | + if (index == 1) { | ||
90 | + return nil; | ||
91 | + } | ||
92 | + | ||
93 | + index += 1; | ||
94 | + return viewControllerAt(index); | ||
95 | + } | ||
96 | + | ||
97 | + return nil; | ||
98 | + } | ||
99 | + | ||
100 | + public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { | ||
101 | + | ||
102 | + if let analysisVC = viewController as? AnalysisChildViewController { | ||
103 | + var index = analysisVC.index | ||
104 | + if (index == 0) { | ||
105 | + return nil; | ||
106 | + } | ||
107 | + | ||
108 | + index -= 1; | ||
109 | + return viewControllerAt(index); | ||
110 | + } | ||
111 | + | ||
112 | + return nil; | ||
113 | + } | ||
114 | + | ||
115 | + | ||
116 | + public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { | ||
117 | + | ||
118 | + if (!completed) { | ||
119 | + return; | ||
120 | + } | ||
121 | + | ||
122 | + | ||
123 | + if let childVCs = pageViewController.viewControllers as? [AnalysisChildViewController] { | ||
124 | + let currentIndex = childVCs[0].index | ||
125 | + if (currentIndex == 0) { | ||
126 | + leftButton.isSelected = true | ||
127 | + rightButton.isSelected = false | ||
128 | + } else { | ||
129 | + leftButton.isSelected = false | ||
130 | + rightButton.isSelected = true | ||
131 | + } | ||
132 | + } | ||
133 | + } | ||
31 | } | 134 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -63,6 +63,7 @@ | ... | @@ -63,6 +63,7 @@ |
63 | - (NSDictionary*) getCoupons; | 63 | - (NSDictionary*) getCoupons; |
64 | - (NSDictionary*) getTransactionHistory; | 64 | - (NSDictionary*) getTransactionHistory; |
65 | - (NSDictionary*) getPointsHistory; | 65 | - (NSDictionary*) getPointsHistory; |
66 | +- (NSDictionary*) getSharingHistory; | ||
66 | - (NSDictionary*)addAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes; | 67 | - (NSDictionary*)addAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes; |
67 | - (NSDictionary*)getAddress; | 68 | - (NSDictionary*)getAddress; |
68 | - (NSDictionary*)editAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes andUuid:(NSString*)uuid; | 69 | - (NSDictionary*)editAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes andUuid:(NSString*)uuid; | ... | ... |
... | @@ -940,6 +940,35 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; | ... | @@ -940,6 +940,35 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; |
940 | return resp; | 940 | return resp; |
941 | } | 941 | } |
942 | 942 | ||
943 | +- (NSDictionary*) getSharingHistory | ||
944 | +{ | ||
945 | + __block NSDictionary *resp = [NSDictionary alloc]; | ||
946 | + __block BOOL isRunLoopNested = NO; | ||
947 | + __block BOOL isOperationCompleted = NO; | ||
948 | + [[Warply sharedService] getSharingHistoryWithSuccessBlock:^(NSDictionary *response) { | ||
949 | + resp = response; | ||
950 | + isOperationCompleted = YES; | ||
951 | + if (isRunLoopNested) { | ||
952 | + CFRunLoopStop(CFRunLoopGetCurrent()); // CFRunLoopRun() returns | ||
953 | + } | ||
954 | + } failureBlock:^(NSError *error) { | ||
955 | + NSLog(@"%@", error); | ||
956 | + resp = nil; | ||
957 | + isOperationCompleted = YES; | ||
958 | + if (isRunLoopNested) { | ||
959 | + CFRunLoopStop(CFRunLoopGetCurrent()); // CFRunLoopRun() returns | ||
960 | + } | ||
961 | + }]; | ||
962 | + if ( ! isOperationCompleted) { | ||
963 | + isRunLoopNested = YES; | ||
964 | + NSLog(@"Waiting..."); | ||
965 | + CFRunLoopRun(); // Magic! | ||
966 | + isRunLoopNested = NO; | ||
967 | + } | ||
968 | + return resp; | ||
969 | +} | ||
970 | + | ||
971 | + | ||
943 | - (NSDictionary*)addAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes { | 972 | - (NSDictionary*)addAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes { |
944 | __block NSDictionary *resp = [NSDictionary alloc]; | 973 | __block NSDictionary *resp = [NSDictionary alloc]; |
945 | __block BOOL isRunLoopNested = NO; | 974 | __block BOOL isRunLoopNested = NO; | ... | ... |
1 | +// | ||
2 | +// SharingHistoryViewController.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class SharingHistoryViewController: AnalysisChildViewController { | ||
11 | + | ||
12 | + var loading: Bool = false | ||
13 | + var items: Array<swiftApi.SharingCouponModel> = Array() | ||
14 | + | ||
15 | + // TODO: remove this when configuring model | ||
16 | + let hasMessage = false | ||
17 | + | ||
18 | + // lifecycle | ||
19 | + override func viewDidLoad() { | ||
20 | + | ||
21 | + super.viewDidLoad() | ||
22 | + | ||
23 | + self.refreshControl = UIRefreshControl() | ||
24 | + self.refreshControl?.addTarget(self, action: #selector(handleRefresh(_:)), for: .valueChanged) | ||
25 | + | ||
26 | + handleRefresh(self.refreshControl!) | ||
27 | + } | ||
28 | + | ||
29 | + // mvp | ||
30 | + @objc func load() { | ||
31 | + | ||
32 | + if (loading) { | ||
33 | + return; | ||
34 | + } | ||
35 | + | ||
36 | + showLoading() | ||
37 | + | ||
38 | + swiftApi().getSharingHistoryAsync(responseCallback) | ||
39 | + } | ||
40 | + | ||
41 | + private func showLoading() { | ||
42 | + | ||
43 | + loading = true | ||
44 | + if (self.refreshControl!.isRefreshing) { | ||
45 | + return; | ||
46 | + } | ||
47 | + | ||
48 | + self.refreshControl!.beginRefreshing() | ||
49 | + } | ||
50 | + | ||
51 | + private func showError() { | ||
52 | + } | ||
53 | + | ||
54 | + private func showContent() { | ||
55 | + | ||
56 | + loading = false | ||
57 | + self.refreshControl!.endRefreshing() | ||
58 | + } | ||
59 | + | ||
60 | + // private | ||
61 | + func responseCallback (_ data: Array<swiftApi.SharingCouponModel>?) -> Void { | ||
62 | + | ||
63 | + self.items = data! | ||
64 | + showContent() | ||
65 | + DispatchQueue.main.async { | ||
66 | + self.tableView.reloadData() | ||
67 | + } | ||
68 | + } | ||
69 | + | ||
70 | + @objc func handleRefresh(_ refreshControl: UIRefreshControl) { | ||
71 | + | ||
72 | + self.perform(_: #selector(load), with: nil, afterDelay: 0.5) | ||
73 | + } | ||
74 | + | ||
75 | + // MARK: - Table view data source | ||
76 | + override func numberOfSections(in tableView: UITableView) -> Int { | ||
77 | + return 2 | ||
78 | + } | ||
79 | + | ||
80 | + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
81 | + if (section == 0) { | ||
82 | + return 1; | ||
83 | + } | ||
84 | + | ||
85 | + return items.count | ||
86 | + } | ||
87 | + | ||
88 | + override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | ||
89 | + if (indexPath.section == 0) { | ||
90 | + return hasMessage ? 380.0 : 280 | ||
91 | + } | ||
92 | + | ||
93 | + return 140.0 | ||
94 | + } | ||
95 | + | ||
96 | + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
97 | + | ||
98 | + // header | ||
99 | + if (indexPath.section == 0) { | ||
100 | + if (hasMessage) { | ||
101 | + return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderMessageViewCell", for: indexPath) as! AnalysisHeaderMessageViewCell | ||
102 | + } | ||
103 | + | ||
104 | + return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderViewCell", for: indexPath) as! AnalysisHeaderViewCell | ||
105 | + } | ||
106 | + | ||
107 | + let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! AnalysisItemViewCell | ||
108 | + cell.configureCell(item: items[indexPath.row]) | ||
109 | + | ||
110 | + return cell | ||
111 | + } | ||
112 | +} |
1 | +// | ||
2 | +// UIColorExtensions.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import Foundation | ||
9 | +import UIKit | ||
10 | + | ||
11 | +extension UIColor { | ||
12 | + convenience init(rgb: UInt) { | ||
13 | + self.init( | ||
14 | + red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0, | ||
15 | + green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0, | ||
16 | + blue: CGFloat(rgb & 0x0000FF) / 255.0, | ||
17 | + alpha: CGFloat(1.0) | ||
18 | + ) | ||
19 | + } | ||
20 | +} |
... | @@ -155,7 +155,6 @@ public class swiftApi { | ... | @@ -155,7 +155,6 @@ public class swiftApi { |
155 | public func getActiveDFYCoupons() -> Array<ActiveDFYCouponModel> { | 155 | public func getActiveDFYCoupons() -> Array<ActiveDFYCouponModel> { |
156 | return GlobalVariables.dfyCoupons | 156 | return GlobalVariables.dfyCoupons |
157 | } | 157 | } |
158 | - | ||
159 | 158 | ||
160 | public class CouponSetItemModel: Codable { | 159 | public class CouponSetItemModel: Codable { |
161 | public let uuid: String? | 160 | public let uuid: String? | ... | ... |
-
Please register or login to post a comment