Advertisement
parthibweavers

AppReviewSurvey Swift

Jul 24th, 2023
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.48 KB | None | 0 0
  1. import Foundation
  2.  
  3. struct AppSurveyAndReviewManager: AppSurveyAndReviewManagerDelegate {
  4.     //MARK: - Properties
  5.     private var _numWorkoutsRequiredInTimeframe: Int = 1000
  6.     private var _minimumCoolDownPeriodInDays: Int = 1000
  7.    
  8.     var surveyCurrentlyBeingDisplayed: Bool = false
  9.     var isUserCurrentlyWorkingOut: Bool = false
  10.    
  11.     var lastTimeDisplayedInDaysAgo: Int {
  12.         let lastDateWhenSurveyWasShown = UserDefaultsModule.getDate(for: .lastDateWhenSurveyWasShown) ?? Date()
  13.         let currentDate = Date()
  14.        
  15.         let differenceInDays = Calendar.current.dateComponents([.day], from: lastDateWhenSurveyWasShown, to: currentDate).day ?? 0
  16.         return abs(differenceInDays)
  17.         // return 31
  18.     }
  19.    
  20.     var numberOfWorkoutsDoneByTheUser: Int {
  21.         return UserDefaultsModule.getInteger(for: .workoutCountForSurveyAndReview) ?? 0
  22.     }
  23.    
  24.     var numWorkoutsRequiredInTimeframe: Int {
  25.         return self._numWorkoutsRequiredInTimeframe
  26.     }
  27.    
  28.     var minimumCoolDownPeriodInDays: Int {
  29.         return self._minimumCoolDownPeriodInDays
  30.     }
  31.    
  32.     var isAFrequentUser: Bool {
  33.         return self.numberOfWorkoutsDoneByTheUser >= self.numWorkoutsRequiredInTimeframe
  34.     }
  35.    
  36.     var shouldShowSurvey: Bool {
  37.         return self.isAFrequentUser &&
  38.                !self.isUserCurrentlyWorkingOut &&
  39.                (self.lastTimeDisplayedInDaysAgo > self.minimumCoolDownPeriodInDays) &&
  40.                !self.surveyCurrentlyBeingDisplayed
  41.     }
  42.    
  43.    
  44.    
  45.    
  46.    
  47.     //MARK: - Init
  48.     init(numWorkoutsRequiredInTimeframe: Int, minimumCoolDownPeriodInDays: Int) {
  49.         self._numWorkoutsRequiredInTimeframe = numWorkoutsRequiredInTimeframe
  50.         self._minimumCoolDownPeriodInDays = minimumCoolDownPeriodInDays
  51.     }
  52.    
  53.    
  54.    
  55.    
  56.    
  57.     //MARK: - Static Functions
  58.     static func updateWorkoutStatus(_ currentlyWorkingOut: Bool) {
  59.         NotificationCenter.default.post(name: .userCurrentlyWorkingOut, object: nil, userInfo: [NotificationKeys.userCurrentlyWorkingOut: currentlyWorkingOut])
  60.     }
  61.    
  62.     static func updateSurveyDisplayStatus(_ surveyCurrentlyDisplayed: Bool) {
  63.         NotificationCenter.default.post(name: .surveyCurrentlyBeingDisplayed, object: nil, userInfo: [NotificationKeys.surveyCurrentlyBeingDisplayed: surveyCurrentlyDisplayed])
  64.     }
  65.    
  66.     static func tryToShowSurveyIfPossible() {
  67.         NotificationCenter.default.post(name: .tryToShowSurveyIfPossible, object: nil)
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement