Skip to content

Native Android client for Spotify, built with Jetpack Compose

Support reminders come every 8 to 12 days instead of every two weeks, the wait drawn per person and per reminder so they do not all come on the same day, never more than once a week [skip ci]

kota-zo67ff880c1b45
diff --git a/base/app/src/main/java/com/music/spotui/data/api/SupportReminder.kt b/base/app/src/main/java/com/music/spotui/data/api/SupportReminder.kt
index 1fd57365..d3f9cec5 100644
--- a/base/app/src/main/java/com/music/spotui/data/api/SupportReminder.kt
+++ b/base/app/src/main/java/com/music/spotui/data/api/SupportReminder.kt
@@ -13,7 +13,8 @@ import com.music.spotui.data.preferences.Look
import com.music.spotui.data.preferences.LookPref
/**
- * Donations and their thank-yous. Reminders: a day after first use, then every 2 weeks;
+ * Donations and their thank-yous. Reminders: a day after first use, then every 8 to 12 days
+ * (drawn per person and per reminder, never weekly);
* for someone who said they gave once, every 3 months with a thank-you; never for a
* monthly supporter. "I've supported" is taken on trust (nothing is checked, nothing is
* sold): it unlocks cosmetic thank-yous only (accent colour, app icon, badge).
@@ -28,7 +29,9 @@ object SupportReminder {
* be checked: everyone is treated as a non-supporter and their entry points are hidden.
*/
const val PERKS_ENABLED = false
- const val EVERY_MS = 14L * 24 * 3_600_000
+ const val EVERY_MS = 8L * 24 * 3_600_000
+ /** Up to this much more after [EVERY_MS], so reminders do not come on the same day for everyone. */
+ const val SPREAD_MS = 4L * 24 * 3_600_000
const val SUPPORTER_EVERY_MS = 90L * 24 * 3_600_000
private const val PREFS = "support_reminder"
/** The single accent of earlier versions, copied to both looks once ([init]). */
@@ -73,9 +76,17 @@ object SupportReminder {
fun nextAt(firstSeen: Long, lastShown: Long, level: Level, supportedAt: Long): Long = when (level) {
Level.MONTHLY -> Long.MAX_VALUE
Level.ONCE -> maxOf(lastShown, supportedAt) + SUPPORTER_EVERY_MS
- Level.NONE -> if (lastShown == 0L) firstSeen + FIRST_AFTER_MS else lastShown + EVERY_MS
+ Level.NONE -> if (lastShown == 0L) firstSeen + FIRST_AFTER_MS else lastShown + EVERY_MS + spread(firstSeen, lastShown)
}
+ /**
+ * The extra wait after [EVERY_MS], in [0, [SPREAD_MS]): drawn from the first use and the last
+ * reminder, so it differs between people and between reminders but stays the same each time
+ * the app asks (nothing more to keep).
+ */
+ internal fun spread(firstSeen: Long, lastShown: Long): Long =
+ java.util.Random(firstSeen * 31 + lastShown).nextLong().mod(SPREAD_MS)
+
private fun prefs(context: Context) = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
fun init(context: Context) {
diff --git a/base/app/src/test/java/com/music/spotui/data/api/SupportReminderTest.kt b/base/app/src/test/java/com/music/spotui/data/api/SupportReminderTest.kt
index e1e84f6b..9eb09b16 100644
--- a/base/app/src/test/java/com/music/spotui/data/api/SupportReminderTest.kt
+++ b/base/app/src/test/java/com/music/spotui/data/api/SupportReminderTest.kt
@@ -17,8 +17,17 @@ class SupportReminderTest {
assertEquals(Level.NONE, SupportReminder.level)
}
- @Test fun thenEveryTwoWeeksAfterTheLastAnswer() {
- assertEquals(64 * day, SupportReminder.nextAt(1_000L, lastShown = 50 * day, level = Level.NONE, supportedAt = 0L))
+ @Test fun thenEveryEightToTwelveDaysAfterTheLastAnswer() {
+ val next = SupportReminder.nextAt(1_000L, lastShown = 50 * day, level = Level.NONE, supportedAt = 0L)
+ org.junit.Assert.assertTrue(next in 58 * day until 62 * day)
+ // The same answer each time the app asks.
+ assertEquals(next, SupportReminder.nextAt(1_000L, lastShown = 50 * day, level = Level.NONE, supportedAt = 0L))
+ }
+
+ @Test fun theWaitDiffersBetweenPeople() {
+ val waits = (1L..50L).map { SupportReminder.nextAt(it * 7_919_000L, lastShown = 50 * day, level = Level.NONE, supportedAt = 0L) }.toSet()
+ org.junit.Assert.assertTrue(waits.size > 40)
+ org.junit.Assert.assertTrue(waits.all { it in 58 * day until 62 * day })
}
@Test fun aOneTimeSupporterHearsAgainAfterThreeMonths() {