@@ -29,19 +29,32 @@ public class Session: NSObject {
29
29
@objc public private( set) var screenView : Int = 0
30
30
31
31
/// Number of screen viewed in all session
32
- @objc public private( set) var totalScreenView : Int = Store . totalScreenView {
33
- didSet { Store . totalScreenView = self . totalScreenView }
32
+ @objc public private( set) var totalScreenView : Int {
33
+ get {
34
+ localStore. totalScreenView
35
+ }
36
+ set {
37
+ localStore. totalScreenView = newValue
38
+ }
34
39
}
35
-
40
+
36
41
/// Number of seconds spent in the application for all time
37
- @objc public private( set) var totalSecondsInApp : TimeInterval = Store . totalSecondsInApp {
38
- didSet { Store . totalSecondsInApp = self . totalSecondsInApp }
42
+ @objc public private( set) var totalSecondsInApp : TimeInterval {
43
+ get {
44
+ localStore. totalSecondsInApp
45
+ }
46
+ set {
47
+ localStore. totalSecondsInApp = newValue
48
+ }
39
49
}
40
50
41
51
/// Date when the survey will be appear again
42
- @objc public var localQuarantineDate : Date {
52
+ @objc public internal ( set ) var localQuarantineDate : Date {
43
53
get {
44
- return Store . localQuarantineDate
54
+ localStore. localQuarantineDate
55
+ }
56
+ set {
57
+ localStore. localQuarantineDate = newValue
45
58
}
46
59
}
47
60
@@ -57,23 +70,28 @@ public class Session: NSObject {
57
70
/// The timer with which the parameters `sessionSeconds` and `totalSecondsInApp` will be updated
58
71
private var sessionUpdateTimer : Timer ?
59
72
73
+ /// Store used for the store current session
74
+ private var localStore : Store !
75
+
60
76
// MARK: Init
61
77
62
78
/**
63
79
* Creates an instance with the specified object `settings` (options) and closure `rulesPassed`.
64
80
*
65
81
* - parameter settings: Settings used for the current session
82
+ * - parameter store: Store used for the store current session
66
83
* - parameter rulesPassed: A closure executed when all rules pass
67
84
*
68
85
* - returns: The new `Session` instance.
69
86
*/
70
- internal convenience init ( settings: UserReportSettings ? = nil , rulesPassed: @escaping SessionRulesPassedHandler ) {
87
+ internal convenience init ( settings: UserReportSettings ? = nil , store : Store , rulesPassed: @escaping SessionRulesPassedHandler ) {
71
88
self . init ( )
72
89
73
90
// DI
74
91
self . settings = settings
75
92
self . rulesPassed = rulesPassed
76
-
93
+ self . localStore = store
94
+
77
95
self . startTimer ( )
78
96
79
97
// Observe UIApplication enter background/foreground
@@ -100,13 +118,6 @@ public class Session: NSObject {
100
118
self . lastViewScreenDate = Date ( )
101
119
}
102
120
103
- /**
104
- * Update local quarantine date to current date
105
- */
106
- internal func updateLocalQuarantineDate( _ localQuarantine: Date ) {
107
- Store . localQuarantineDate = localQuarantine
108
- }
109
-
110
121
/**
111
122
* Set new settings.
112
123
*/
@@ -163,7 +174,7 @@ public class Session: NSObject {
163
174
guard self . totalScreenView >= settings. inviteAfterTotalScreensViewed else { return }
164
175
guard self . sessionSeconds >= settings. sessionNSecondsLength else { return }
165
176
guard self . totalSecondsInApp >= settings. inviteAfterNSecondsInApp else { return }
166
- guard Date ( ) >= Store . localQuarantineDate else { return }
177
+ guard Date ( ) >= localStore . localQuarantineDate else { return }
167
178
168
179
self . rulesPassed ? ( )
169
180
}
0 commit comments