Skip to content

Instantly share code, notes, and snippets.

@IvanShafran
Last active August 22, 2019 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IvanShafran/9a2d5d4f3e4cf5787e7b99a048bf4dc8 to your computer and use it in GitHub Desktop.
Save IvanShafran/9a2d5d4f3e4cf5787e7b99a048bf4dc8 to your computer and use it in GitHub Desktop.
class ShowRateUsLogic(
private val rateUsPreferences: RateUsPreferences,
private val buyPreferences: BuyPreferences,
private val time: Time
) {
fun shouldShowRateUs(): Boolean {
val timeFromLastShown = time.getCurrentTimeMillis() - rateUsPreferences.getLastShownTimeMillis()
return when {
// User doesn't want to see "rate us" again
rateUsPreferences.isNeverShownAgainClicked() -> false
// User already rated the app
rateUsPreferences.isRateNowClicked() -> false
// "Rate us" should be shown after 2 "buy" clicked
buyPreferences.getBuyCount() < 2 -> false
// Show "rate us" only first time or if passed two months since last shown time
timeFromLastShown < TimeUnit.DAYS.toMillis(60) -> false
else -> true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment