Suggestions: swipable strip with a random tail

The carousel under the player now scrolls sideways; the four visible slots keep
their meaning.

- Series.suggestionsFor takes a size: the first four slots stay
  [outsider, previous, next, outsider], everything after them is a shuffled tail
  of up to 24 entries, so swiping left and right keeps revealing random videos
- the tail is only appended when both end slots really carry a video from outside
  the running series. Without that guard a series entry slid into position four as
  soon as the tail existed, which is exactly what must not happen
- tests: long tail with the visible four intact, tail that mixes the series back
  in, exhausted library, and the two edge cases that must stay short

19 Series tests + 5 store tests, 0 failures; assembleDebug and lintDebug green.
Built only — the tablet still runs the deployed build.
This commit is contained in:
lotherk committed 2026-10-28 18:55:55 +00:00
1 parent a43816a3ae
commit d75eccdc17
4 files changed
+52 -15

No files matched your search

+5 -4
View File
@@ -69,10 +69,11 @@ Mandatory: from API 29 scoped storage forbids directory listing (the app uid get
- `data/Library` — SAF tree else MediaStore; `MediaItem`; sorted by folder then
`Series.naturalOrder` (leading `001`, `002` … numeric, not lexical).
- `data/Series` — ordering plus the player's suggestion rule, pure and unit
tested: slots are `[outsider, previous of the series, next of the series,
outsider]`. Slots 1 and 4 are guaranteed to come from a different folder than
the running video; if there is no such video the slot stays empty instead of
falling back to the same series.
tested: the visible four are `[outsider, previous of the series, next of the
series, outsider]`, followed by a shuffled tail so the strip can be swiped
sideways. Slots 1 and 4 always come from another folder; the tail is only
appended when both of them are really filled, otherwise the promise would break
as a series entry slides into position four.
- `media/ThumbCache` — decode via `MediaMetadataRetriever`, take the brightest of
three offsets (openings often fade from black), write JPEGs to
`filesDir/thumbs`, `LruCache` in memory, 3 threads, tag-guarded callback.
@@ -71,26 +71,31 @@ object Series {
val used = hashSetOf(current.key)
val out = ArrayList<T>(size)
fun takeOutsider() {
while (outsiders.hasNext() && out.size < size) {
fun takeOutsider(): Boolean {
while (outsiders.hasNext()) {
val candidate = outsiders.next()
if (used.add(candidate.key)) {
out.add(candidate)
return
return true
}
}
return false
}
takeOutsider()
val firstFilled = takeOutsider()
previous?.let { if (used.add(it.key) && out.size < size) out.add(it) }
next?.let { if (used.add(it.key) && out.size < size) out.add(it) }
takeOutsider()
val fourthFilled = takeOutsider()
// Fill the middle only from outside the series; a series entry never lands
// in a slot that is not one of the two explicit neighbour slots.
while (out.size < size && outsiders.hasNext()) {
val candidate = outsiders.next()
if (used.add(candidate.key)) out.add(candidate)
// The swiping tail is only appended when both end slots really carry a
// video from outside the series. Otherwise the promise would break the
// moment a series entry slides into position four.
if (firstFilled && fourthFilled && out.size < size) {
val rest = all.filter { it.key !in used }.shuffled()
for (candidate in rest) {
if (out.size >= size) break
if (used.add(candidate.key)) out.add(candidate)
}
}
return out
}
@@ -165,7 +165,7 @@ class PlayerActivity : AppCompatActivity() {
private fun loadSuggestions(current: MediaItem) {
executor.execute {
val scan = Library.scan(this)
val others = Series.suggestionsFor(scan, current, 4)
val others = Series.suggestionsFor(scan, current, 24)
library = scan
pool = others
runOnUiThread {
@@ -162,6 +162,37 @@ class SeriesTest {
assertNull(Series.nextToPlay(all, all[0]))
}
@Test
fun suggestions_tailKeepsGoingForSwiping() {
val all = series("Sandmann", 10) + outsiders(6)
val out = Series.suggestionsFor(all, all[4], size = 12)
assertEquals(12, out.size)
assertEquals(12, out.map { it.key }.distinct().size)
// the visible four keep their rule even with a long tail
assertNotEquals("Sandmann", out[0].folder)
assertNotEquals("Sandmann", out[3].folder)
assertEquals("004 - Folge 4", out[1].title)
assertEquals("006 - Folge 6", out[2].title)
}
@Test
fun suggestions_tailMayContainTheSeries() {
val all = series("Sandmann", 10) + outsiders(2)
val out = Series.suggestionsFor(all, all[4], size = 10)
assertEquals(10, out.size)
// only two outsiders exist, so slots after the fourth must come from the
// series — the tail is not restricted
assertTrue(out.drop(5).any { it.folder == "Sandmann" })
}
@Test
fun suggestions_stopsWhenTheLibraryIsExhausted() {
val all = series("Sandmann", 3) + outsiders(1)
val out = Series.suggestionsFor(all, all[1], size = 24)
assertEquals(3, out.size) // current + all four others, nothing repeats
assertEquals(3, out.map { it.key }.distinct().size)
}
@Test
fun suggestions_handlesShortLibrary() {
val all = series("Sandmann", 2)