diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-10-14 08:50:59 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-10-14 08:50:59 +0000 |
| commit | 3e605a33b21ff6f69937b949f3139217004b1f36 (patch) | |
| tree | 5c5551611242083d2099adcccf06765af0c7dbce /app/src | |
| parent | b7c22e660c929bbd5640c57d87201c19c13c8e19 (diff) | |
Add the setting for skipping a show's own audio
On by default, because skipping every detected break is what the app
already does.
Diffstat (limited to 'app/src')
| -rw-r--r-- | app/src/androidTest/java/org/terst/listen/data/PreferencesTest.kt | 41 | ||||
| -rw-r--r-- | app/src/main/java/org/terst/listen/data/Preferences.kt | 14 |
2 files changed, 55 insertions, 0 deletions
diff --git a/app/src/androidTest/java/org/terst/listen/data/PreferencesTest.kt b/app/src/androidTest/java/org/terst/listen/data/PreferencesTest.kt new file mode 100644 index 0000000..42c8f4a --- /dev/null +++ b/app/src/androidTest/java/org/terst/listen/data/PreferencesTest.kt @@ -0,0 +1,41 @@ +package org.terst.listen.data + +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.test.runTest +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented, not a JVM unit test: [Preferences] takes a [android.content.Context] and reads + * it through `preferencesDataStore`, which a plain JVM test cannot construct without Robolectric + * -- not a dependency here. There was no test for [Preferences] before this; this is the first. + */ +@RunWith(AndroidJUnit4::class) +class PreferencesTest { + + private val context = ApplicationProvider.getApplicationContext<android.content.Context>() + + /** + * On by default, because it is what the app already does: every detected break has always + * been skipped. Defaulting it off would quietly stop skipping intros for someone who never + * asked for that. + */ + @Test + fun furnitureIsSkippedUntilItIsTurnedOff() = runTest { + val prefs = Preferences(context) + + assertTrue(prefs.skipShowFurniture.first()) + + prefs.setSkipShowFurniture(false) + assertFalse(prefs.skipShowFurniture.first()) + + // Leave the real, on-device DataStore as this test found it -- it persists across runs + // in the same process, and a stray `false` here would make this test order-dependent + // with itself on a second run. + prefs.setSkipShowFurniture(true) + } +} diff --git a/app/src/main/java/org/terst/listen/data/Preferences.kt b/app/src/main/java/org/terst/listen/data/Preferences.kt index 0c170a1..e63b898 100644 --- a/app/src/main/java/org/terst/listen/data/Preferences.kt +++ b/app/src/main/java/org/terst/listen/data/Preferences.kt @@ -33,6 +33,19 @@ class Preferences(private val context: Context) { } /** + * Whether a show's own intro, break cue and credits are skipped as well as the advertising. + * + * On by default: every detected break has always been skipped, so this preserves that. + * Advertising is not covered by this and is always skipped -- it is the thing the detection + * exists for, and there is no case for keeping it. + */ + val skipShowFurniture: Flow<Boolean> = context.store.data.map { it[SKIP_SHOW_FURNITURE] ?: true } + + suspend fun setSkipShowFurniture(value: Boolean) { + context.store.edit { it[SKIP_SHOW_FURNITURE] = value } + } + + /** * Where the skip server is, and the token for it. Blank means not configured, which is a * working state: the app downloads from publishers and plays without detected skips, * exactly as it did before the server existed. @@ -51,5 +64,6 @@ class Preferences(private val context: Context) { val SHOW_PLAYED = booleanPreferencesKey("show_played") val SERVER_URL = stringPreferencesKey("server_url") val SERVER_TOKEN = stringPreferencesKey("server_token") + val SKIP_SHOW_FURNITURE = booleanPreferencesKey("skip_show_furniture") } } |
