Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- struct AppSurveyAndReviewManager: AppSurveyAndReviewManagerDelegate {
- //MARK: - Properties
- private var _numWorkoutsRequiredInTimeframe: Int = 1000
- private var _minimumCoolDownPeriodInDays: Int = 1000
- var surveyCurrentlyBeingDisplayed: Bool = false
- var isUserCurrentlyWorkingOut: Bool = false
- var lastTimeDisplayedInDaysAgo: Int {
- let lastDateWhenSurveyWasShown = UserDefaultsModule.getDate(for: .lastDateWhenSurveyWasShown) ?? Date()
- let currentDate = Date()
- let differenceInDays = Calendar.current.dateComponents([.day], from: lastDateWhenSurveyWasShown, to: currentDate).day ?? 0
- return abs(differenceInDays)
- // return 31
- }
- var numberOfWorkoutsDoneByTheUser: Int {
- return UserDefaultsModule.getInteger(for: .workoutCountForSurveyAndReview) ?? 0
- }
- var numWorkoutsRequiredInTimeframe: Int {
- return self._numWorkoutsRequiredInTimeframe
- }
- var minimumCoolDownPeriodInDays: Int {
- return self._minimumCoolDownPeriodInDays
- }
- var isAFrequentUser: Bool {
- return self.numberOfWorkoutsDoneByTheUser >= self.numWorkoutsRequiredInTimeframe
- }
- var shouldShowSurvey: Bool {
- return self.isAFrequentUser &&
- !self.isUserCurrentlyWorkingOut &&
- (self.lastTimeDisplayedInDaysAgo > self.minimumCoolDownPeriodInDays) &&
- !self.surveyCurrentlyBeingDisplayed
- }
- //MARK: - Init
- init(numWorkoutsRequiredInTimeframe: Int, minimumCoolDownPeriodInDays: Int) {
- self._numWorkoutsRequiredInTimeframe = numWorkoutsRequiredInTimeframe
- self._minimumCoolDownPeriodInDays = minimumCoolDownPeriodInDays
- }
- //MARK: - Static Functions
- static func updateWorkoutStatus(_ currentlyWorkingOut: Bool) {
- NotificationCenter.default.post(name: .userCurrentlyWorkingOut, object: nil, userInfo: [NotificationKeys.userCurrentlyWorkingOut: currentlyWorkingOut])
- }
- static func updateSurveyDisplayStatus(_ surveyCurrentlyDisplayed: Bool) {
- NotificationCenter.default.post(name: .surveyCurrentlyBeingDisplayed, object: nil, userInfo: [NotificationKeys.surveyCurrentlyBeingDisplayed: surveyCurrentlyDisplayed])
- }
- static func tryToShowSurveyIfPossible() {
- NotificationCenter.default.post(name: .tryToShowSurveyIfPossible, object: nil)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement