MarketLoyaltyAnalysisViewController.swift
9.26 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
//
// MarketLoyaltyAnalysisViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 5/4/23.
//
import UIKit
import SwiftEventBus
@objc public class MarketLoyaltyAnalysisViewController: UIViewController {
@IBOutlet weak var leftButton: UIButton!
@IBOutlet weak var rightButton: UIButton!
@IBOutlet weak var leftLineView: UIView!
@IBOutlet weak var rightLineView: UIView!
@IBOutlet weak var contentView: UIView!
var pageController: UIPageViewController!
var tabSelected = 0
var timerHistory: DispatchSourceTimer?
var seconds: Int = 0
public override func viewDidLoad() {
super.viewDidLoad()
self.hidesBottomBarWhenPushed = true
// setup view
setBackButton()
setNavigationTitle("Ανάλυση")
// tab
leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
leftButton.setTitle("Εξαργυρωμένα", for:.normal)
leftButton.backgroundColor = . clear
leftButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
rightButton.setTitle("Μοιρασμένα δώρα", for:.normal)
rightButton.backgroundColor = . clear
rightButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
leftLineView.applyGradient(colours: [UIColor(rgb: 0x1DA6B9), UIColor(rgb: 0xB2CE69)], gradient: GradientOrientation.horizontal, cornerRadius: 0.0)
rightLineView.applyGradient(colours: [UIColor(rgb: 0x1DA6B9), UIColor(rgb: 0xB2CE69)], gradient: GradientOrientation.horizontal, cornerRadius: 0.0)
leftLineView.isHidden = false
rightLineView.isHidden = true
// pages
pageController = UIPageViewController(transitionStyle:.scroll, navigationOrientation:.horizontal)
pageController.dataSource = self;
pageController.delegate = self;
pageController.view.frame = contentView.bounds;
addChild(pageController)
contentView.addSubview(pageController.view)
pageController .didMove(toParent: self)
let analysisVC = self.viewControllerAt(0)
pageController.setViewControllers([analysisVC!], direction:.forward, animated:false)
}
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
swiftApi().logTrackersEvent("screen", "LoyaltyHistoryScreen")
self.startTimer()
}
public override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.stopTimer()
}
// MARK: - Functions
func startTimer() {
print("========= GiftsCalculator Timer Started! =========")
let queue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".history.timer")
timerHistory = DispatchSource.makeTimerSource(queue: queue)
timerHistory!.schedule(deadline: .now(), repeating: .seconds(1))
timerHistory!.setEventHandler { [weak self] in
// do whatever stuff you want on the background queue here here
print("========= GiftsCalculator interval! =========")
DispatchQueue.main.async {
// update your model objects and/or UI here
self?.seconds = (self?.seconds ?? 0) + 1
}
}
timerHistory!.resume()
}
func stopTimer() {
print("========= GiftsCalculator Timer Stopped! =========")
timerHistory?.cancel()
timerHistory = nil
let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
firebaseEvent._eventName = "time_spent_on_loyalty_sdk"
firebaseEvent.setParameter = ("name", "GiftsCalculator")
firebaseEvent.setParameter = ("seconds", String(seconds))
SwiftEventBus.post("firebase", sender: firebaseEvent)
seconds = 0
}
////////////////////////////////////////////////////////////////////////////////
private func viewControllerAt(_ index:Int) -> AnalysisChildViewController?
{
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
if (index == 1) {
swiftApi().logTrackersEvent("click", ("LoyaltyHistoryScreen:" + "TabShared"))
let analysisVC = storyboard.instantiateViewController(withIdentifier:"MarketSharingHistoryViewController") as! SwiftWarplyFramework.MarketSharingHistoryViewController
analysisVC.index = index;
return analysisVC;
}
swiftApi().logTrackersEvent("click", ("LoyaltyHistoryScreen:" + "TabExpired"))
let analysisVC = storyboard.instantiateViewController(withIdentifier:"MarketHistoryViewController") as! SwiftWarplyFramework.MarketHistoryViewController
analysisVC.index = index;
return analysisVC;
}
// MARK: - Handlers
@IBAction func handleLeft() {
if (tabSelected != 0) {
self.tabSelected = 0
UIView.animate(withDuration: 2.0, delay: 0.0) {
self.leftLineView.isHidden = false
self.rightLineView.isHidden = true
self.leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
self.rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
self.leftButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
self.rightButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
}
let analysisVC = self.viewControllerAt(0)
pageController.setViewControllers([analysisVC!], direction:.reverse, animated:true)
}
}
@IBAction func handleRight() {
if (tabSelected != 1) {
self.tabSelected = 1
UIView.animate(withDuration: 2.0, delay: 0.0) {
self.leftLineView.isHidden = true
self.rightLineView.isHidden = false
self.leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
self.rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
self.rightButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
self.leftButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
}
let analysisVC = self.viewControllerAt(1)
pageController.setViewControllers([analysisVC!], direction:.forward, animated:true)
}
}
}
// MARK: - PageViewController
extension MarketLoyaltyAnalysisViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate {
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
if let analysisVC = viewController as? AnalysisChildViewController {
var index = analysisVC.index
if (index == 0) {
return nil;
}
index -= 1;
return viewControllerAt(index);
}
return nil;
}
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
if let analysisVC = viewController as? AnalysisChildViewController {
var index = analysisVC.index
if (index == 1) {
return nil;
}
index += 1;
return viewControllerAt(index);
}
return nil;
}
public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if (!completed) {
return;
}
if let childVCs = pageViewController.viewControllers as? [AnalysisChildViewController] {
let currentIndex = childVCs[0].index
if (currentIndex == 0) {
self.leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
self.rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
self.leftButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
self.rightButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
self.tabSelected = 0
self.leftLineView.isHidden = false
self.rightLineView.isHidden = true
} else {
self.leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
self.rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
self.rightButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
self.leftButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
self.tabSelected = 1
self.leftLineView.isHidden = true
self.rightLineView.isHidden = false
}
}
}
}