From 9870465424921e65f8e10e3dd36a00c460ffee72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Tue, 5 Mar 2024 09:25:53 +0100 Subject: [PATCH 1/5] fix: Change opening number before review --- Sources/InfomaniakCore/Account/ReviewManager.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/InfomaniakCore/Account/ReviewManager.swift b/Sources/InfomaniakCore/Account/ReviewManager.swift index 0cf6c70..9b6e446 100644 --- a/Sources/InfomaniakCore/Account/ReviewManager.swift +++ b/Sources/InfomaniakCore/Account/ReviewManager.swift @@ -58,11 +58,15 @@ public protocol ReviewManageable { public class ReviewManager: ReviewManageable { let userDefaults: UserDefaults - let openingBeforeReview: Int + var openingBeforeReview: Int + // var openingBeforeSecondReview: Int - public init(userDefaults: UserDefaults, openingBeforeReview: Int = 50) { + // si openingBeforeReview = 50 ou += 500 alors on affiche la modal + + public init(userDefaults: UserDefaults, openingBeforeReview: Int = 3 /*, openingBeforeSecondReview: Int = 5*/) { self.userDefaults = userDefaults self.openingBeforeReview = openingBeforeReview + // self.openingBeforeSecondReview = openingBeforeSecondReview if userDefaults.object(forKey: userDefaults.key(.openingUntilReview)) == nil { userDefaults.set(openingBeforeReview, forKey: userDefaults.key(.openingUntilReview)) } @@ -74,6 +78,9 @@ public class ReviewManager: ReviewManageable { let request = userDefaults.openingUntilReview <= 0 if request { userDefaults.openingUntilReview = openingBeforeReview +// if openingBeforeReview == 2 { +// openingBeforeReview = openingBeforeSecondReview +// } return true } return false From 341ff01c1d01367d6ca0d45e5eb1a37eb48299cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Tue, 5 Mar 2024 13:36:45 +0100 Subject: [PATCH 2/5] feat: Add decreaseOpeningUntilReview --- Sources/InfomaniakCore/Account/ReviewManager.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/InfomaniakCore/Account/ReviewManager.swift b/Sources/InfomaniakCore/Account/ReviewManager.swift index 9b6e446..b8ffef8 100644 --- a/Sources/InfomaniakCore/Account/ReviewManager.swift +++ b/Sources/InfomaniakCore/Account/ReviewManager.swift @@ -52,6 +52,7 @@ public enum ReviewType: String { } public protocol ReviewManageable { + func decreaseOpeningUntilReview() func shouldRequestReview() -> Bool func requestReview() } @@ -72,6 +73,10 @@ public class ReviewManager: ReviewManageable { } } + public func decreaseOpeningUntilReview() { + userDefaults.openingUntilReview -= 1 + } + public func shouldRequestReview() -> Bool { switch userDefaults.appReview { case .none, .feedback: From 124c15c0d5ed62f14fcd5930311fbc84262babf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Tue, 5 Mar 2024 14:32:11 +0100 Subject: [PATCH 3/5] feat: Add openingBeforeNextReviews --- .../Account/ReviewManager.swift | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Sources/InfomaniakCore/Account/ReviewManager.swift b/Sources/InfomaniakCore/Account/ReviewManager.swift index b8ffef8..db6b6a8 100644 --- a/Sources/InfomaniakCore/Account/ReviewManager.swift +++ b/Sources/InfomaniakCore/Account/ReviewManager.swift @@ -59,17 +59,13 @@ public protocol ReviewManageable { public class ReviewManager: ReviewManageable { let userDefaults: UserDefaults - var openingBeforeReview: Int - // var openingBeforeSecondReview: Int + let openingBeforeNextReviews: Int - // si openingBeforeReview = 50 ou += 500 alors on affiche la modal - - public init(userDefaults: UserDefaults, openingBeforeReview: Int = 3 /*, openingBeforeSecondReview: Int = 5*/) { + public init(userDefaults: UserDefaults, openingBeforeFirstReview: Int = 3, openingBeforeNextReviews: Int = 5) { self.userDefaults = userDefaults - self.openingBeforeReview = openingBeforeReview - // self.openingBeforeSecondReview = openingBeforeSecondReview + self.openingBeforeNextReviews = openingBeforeNextReviews if userDefaults.object(forKey: userDefaults.key(.openingUntilReview)) == nil { - userDefaults.set(openingBeforeReview, forKey: userDefaults.key(.openingUntilReview)) + userDefaults.set(openingBeforeFirstReview, forKey: userDefaults.key(.openingUntilReview)) } } @@ -82,16 +78,13 @@ public class ReviewManager: ReviewManageable { case .none, .feedback: let request = userDefaults.openingUntilReview <= 0 if request { - userDefaults.openingUntilReview = openingBeforeReview -// if openingBeforeReview == 2 { -// openingBeforeReview = openingBeforeSecondReview -// } + userDefaults.openingUntilReview = openingBeforeNextReviews return true } return false case .readyForReview: if userDefaults.openingUntilReview <= 0 { - userDefaults.openingUntilReview = openingBeforeReview + userDefaults.openingUntilReview = openingBeforeNextReviews requestReview() } return false From 3666ce65e19af030c4a04a466819692940f73eac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Wed, 6 Mar 2024 14:33:38 +0100 Subject: [PATCH 4/5] refactor: Rewrite shouldRequestReview function --- .../Account/ReviewManager.swift | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Sources/InfomaniakCore/Account/ReviewManager.swift b/Sources/InfomaniakCore/Account/ReviewManager.swift index db6b6a8..f64ce69 100644 --- a/Sources/InfomaniakCore/Account/ReviewManager.swift +++ b/Sources/InfomaniakCore/Account/ReviewManager.swift @@ -61,6 +61,10 @@ public class ReviewManager: ReviewManageable { let userDefaults: UserDefaults let openingBeforeNextReviews: Int + private var userHasAlreadyAnsweredYes: Bool { + return userDefaults.appReview == .readyForReview + } + public init(userDefaults: UserDefaults, openingBeforeFirstReview: Int = 3, openingBeforeNextReviews: Int = 5) { self.userDefaults = userDefaults self.openingBeforeNextReviews = openingBeforeNextReviews @@ -74,22 +78,20 @@ public class ReviewManager: ReviewManageable { } public func shouldRequestReview() -> Bool { - switch userDefaults.appReview { - case .none, .feedback: - let request = userDefaults.openingUntilReview <= 0 - if request { - userDefaults.openingUntilReview = openingBeforeNextReviews - return true + guard userDefaults.openingUntilReview <= 0 else { + return false } - return false - case .readyForReview: - if userDefaults.openingUntilReview <= 0 { - userDefaults.openingUntilReview = openingBeforeNextReviews + + userDefaults.openingUntilReview = openingBeforeNextReviews + + if userHasAlreadyAnsweredYes { + // If the user has already answered yes, we will directly present the SKStoreReviewController requestReview() + return false + } else { + return true } - return false } - } public func requestReview() { DispatchQueue.main.async { From 117552d67cae42b3c28789826c6a48b1ff77dd82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Wed, 6 Mar 2024 15:12:30 +0100 Subject: [PATCH 5/5] chore: Change opening number before review --- Sources/InfomaniakCore/Account/ReviewManager.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/InfomaniakCore/Account/ReviewManager.swift b/Sources/InfomaniakCore/Account/ReviewManager.swift index f64ce69..5b989de 100644 --- a/Sources/InfomaniakCore/Account/ReviewManager.swift +++ b/Sources/InfomaniakCore/Account/ReviewManager.swift @@ -65,7 +65,7 @@ public class ReviewManager: ReviewManageable { return userDefaults.appReview == .readyForReview } - public init(userDefaults: UserDefaults, openingBeforeFirstReview: Int = 3, openingBeforeNextReviews: Int = 5) { + public init(userDefaults: UserDefaults, openingBeforeFirstReview: Int = 50, openingBeforeNextReviews: Int = 500) { self.userDefaults = userDefaults self.openingBeforeNextReviews = openingBeforeNextReviews if userDefaults.object(forKey: userDefaults.key(.openingUntilReview)) == nil {