Skip to content

Commit

Permalink
fix(app): reduce in-app review flow display frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshgngwr committed Dec 1, 2020
1 parent 873561d commit 2fe643b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object InAppReviewFlowManager {
return
}

if (Random.nextInt(20) != 0) {
if (Random.nextInt(30) != 0) {
Log.d(TAG, "abandoning request due to bad luck!")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ object InAppReviewFlowManager {
}

private fun isShownWithinLastWeek(context: Context): Boolean {
val timestamp = PreferenceManager.getDefaultSharedPreferences(context)
.getLong(PREF_LAST_SHOWN_ON, 0)
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
var timestamp = prefs.getLong(PREF_LAST_SHOWN_ON, 0L)

// refrain from showing review flow to the users newer than a day.
if (timestamp == 0L) {
timestamp = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(6L)
prefs.edit { putLong(PREF_LAST_SHOWN_ON, timestamp) }
}

return TimeUnit.DAYS.toMillis(7L) + timestamp > System.currentTimeMillis()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.shadows.ShadowLooper
import java.util.concurrent.TimeUnit

@RunWith(RobolectricTestRunner::class)
class InAppReviewFlowManagerTest {
Expand Down Expand Up @@ -47,6 +48,10 @@ class InAppReviewFlowManagerTest {
every { putLong(any(), any()) } returns this
}

every {
mockPrefs.getLong(InAppReviewFlowManager.PREF_LAST_SHOWN_ON, any())
} returns System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7L)

// try to show review flow for the first time, should work
InAppReviewFlowManager.maybeAskForReview(fragmentActivity)
ShadowLooper.idleMainLooper()
Expand Down

0 comments on commit 2fe643b

Please sign in to comment.