feat: rotate picks and add an all-new action
CI / build (push) Successful in 4m55s
CI / play (push) Successful in 3m50s

- mood settings gain a replacement threshold slider (default 3 plays, 0
  never), sent with create and update requests
- All new on the mood page calls POST /recommendations/rotate and refills the
  list with different tracks; Refresh keeps its top-up behaviour
- show the rotation threshold, playCount-aware models and busy state, and
  refresh the selected mood from the rotate response
- version 0.5.0
This commit is contained in:
TapTap committed 2026-11-22 17:31:36 +00:00
1 parent e6c1dae3c3
commit 9464ba53d0
10 files changed
+192 -18

No files matched your search

+8 -3
View File
@@ -32,6 +32,10 @@ a server-driven radio session and songs are added from Deezer or YouTube Music.
- Add to mood; - Add to mood;
- Not interested (permanent for the mood); - Not interested (permanent for the mood);
- Retry for failed downloads. - Retry for failed downloads.
A pick is replaced automatically after `recommendationRotationPlays` plays
(default 3, configurable per mood), and **All new** on the mood page swaps the
whole list at once. **Refresh** only discovers and tops up empty slots, which
is why it usually kept the same songs.
- **Radio** mixes the collection and ready recommendations using the mood's - **Radio** mixes the collection and ready recommendations using the mood's
`collectionPercent`. The app keeps a small queue and asks for more from the `collectionPercent`. The app keeps a small queue and asks for more from the
same mood session. same mood session.
@@ -58,8 +62,9 @@ a server-driven radio session and songs are added from Deezer or YouTube Music.
- **Scrubbing**: the progress slider can be dragged on every platform. Android and - **Scrubbing**: the progress slider can be dragged on every platform. Android and
web seek natively; desktop restarts the decoder at the requested position. web seek natively; desktop restarts the decoder at the requested position.
- **Mood settings** live on their own screen: name, description, discovery hint, - **Mood settings** live on their own screen: name, description, discovery hint,
genres, source, collection share, recommendations, refresh interval, a genres, source, collection share, recommendation count and replacement
**Keep this mood offline** switch, and Delete at the bottom. threshold, refresh interval, a **Keep this mood offline** switch, and Delete
at the bottom.
- **Downloads** screen for device-side copies: play, delete, clear, storage - **Downloads** screen for device-side copies: play, delete, clear, storage
usage. usage.
- **Diagnostics**: warnings, errors and crashes are kept in a 500-entry local - **Diagnostics**: warnings, errors and crashes are kept in a 500-entry local
@@ -212,7 +217,7 @@ Tagged builds (`v*`) publish to internal testing from CI. The Gitea secrets are:
| `ANDROID_KEY_PASSWORD` | key password | | `ANDROID_KEY_PASSWORD` | key password |
| `PLAY_SERVICE_ACCOUNT_JSON` | contents of the service account JSON | | `PLAY_SERVICE_ACCOUNT_JSON` | contents of the service account JSON |
Then `git tag v0.4.3 && git push --tags` builds, signs and uploads the bundle. Then `git tag v0.5.0 && git push --tags` builds, signs and uploads the bundle.
Gradle Play Publisher asks Play for the next free `versionCode` Gradle Play Publisher asks Play for the next free `versionCode`
(`ResolutionStrategy.AUTO`), so only the tag/version name needs to change. (`ResolutionStrategy.AUTO`), so only the tag/version name needs to change.
+1 -1
View File
@@ -41,7 +41,7 @@ val hasUploadKey = uploadKeyStore?.exists() == true &&
val appVersionCode = (System.getenv("VERSION_CODE") ?: localProperties.getProperty("VERSION_CODE") ?: "1").toInt() val appVersionCode = (System.getenv("VERSION_CODE") ?: localProperties.getProperty("VERSION_CODE") ?: "1").toInt()
val appVersionName = System.getenv("VERSION_NAME") val appVersionName = System.getenv("VERSION_NAME")
?: localProperties.getProperty("VERSION_NAME") ?: localProperties.getProperty("VERSION_NAME")
?: "0.4.3" ?: "0.5.0"
kotlin { kotlin {
androidTarget { androidTarget {
@@ -1,4 +1,4 @@
package win.taptap.musicmanager.client package win.taptap.musicmanager.client
/** One place for the version shown in Settings and sent with diagnostics. */ /** One place for the version shown in Settings and sent with diagnostics. */
const val APP_VERSION = "0.4.3" const val APP_VERSION = "0.5.0"
@@ -164,6 +164,19 @@ class ApiClient(private val http: HttpClient) {
}, },
) )
/** Retires every active pick and asks the server for different ones. */
suspend fun rotateRecommendations(moodId: String): RecommendationRotation =
parse(
http.post(url("/moods/$moodId/recommendations/rotate")) {
auth()
// The server searches and queues downloads for the new picks.
timeout {
requestTimeoutMillis = 120_000
socketTimeoutMillis = 120_000
}
},
)
suspend fun addRecommendation(moodId: String, externalId: String): RecommendationDecision = suspend fun addRecommendation(moodId: String, externalId: String): RecommendationDecision =
parse( parse(
http.post(url("/moods/$moodId/recommendations/$externalId/add")) { http.post(url("/moods/$moodId/recommendations/$externalId/add")) {
@@ -98,6 +98,8 @@ data class Mood(
val collectionPercent: Int = 50, val collectionPercent: Int = 50,
val recommendationPercent: Int = 50, val recommendationPercent: Int = 50,
val recommendationCount: Int = 10, val recommendationCount: Int = 10,
/** Plays before a pick is replaced; 0 = never rotate. */
val recommendationRotationPlays: Int = 3,
val refreshHours: Int = 24, val refreshHours: Int = 24,
val lastDiscoveryAt: String? = null, val lastDiscoveryAt: String? = null,
val createdAt: String, val createdAt: String,
@@ -139,6 +141,7 @@ data class Recommendation(
val error: String? = null, val error: String? = null,
val firstSeen: String = "", val firstSeen: String = "",
val lastSeen: String = "", val lastSeen: String = "",
val playCount: Int = 0,
) )
@Serializable @Serializable
@@ -174,6 +177,14 @@ data class RecommendationDecision(
val recommendation: Recommendation, val recommendation: Recommendation,
) )
@Serializable
data class RecommendationRotation(
val detail: MoodDetail,
val rotated: Int = 0,
val active: Int = 0,
val error: String? = null,
)
@Serializable @Serializable
data class SearchResult( data class SearchResult(
val source: String = "youtube", val source: String = "youtube",
@@ -257,6 +268,7 @@ data class CreateMoodRequest(
val source: String? = null, val source: String? = null,
val collectionPercent: Int = 50, val collectionPercent: Int = 50,
val recommendationCount: Int = 10, val recommendationCount: Int = 10,
val recommendationRotationPlays: Int = 3,
val refreshHours: Int = 24, val refreshHours: Int = 24,
) )
@@ -271,6 +283,7 @@ data class UpdateMoodRequest(
val source: String? = null, val source: String? = null,
val collectionPercent: Int? = null, val collectionPercent: Int? = null,
val recommendationCount: Int? = null, val recommendationCount: Int? = null,
val recommendationRotationPlays: Int? = null,
val refreshHours: Int? = null, val refreshHours: Int? = null,
) )
@@ -94,6 +94,8 @@ data class AppState(
val loading: Boolean = false, val loading: Boolean = false,
val saving: Boolean = false, val saving: Boolean = false,
val discovering: Boolean = false, val discovering: Boolean = false,
/** True while every recommendation is being replaced. */
val rotatingPicks: Boolean = false,
val message: String? = null, val message: String? = null,
val messageIsError: Boolean = false, val messageIsError: Boolean = false,
val messageId: Long = 0, val messageId: Long = 0,
@@ -847,6 +849,7 @@ class AppStore(
source: String, source: String,
collectionPercent: Int, collectionPercent: Int,
recommendationCount: Int, recommendationCount: Int,
recommendationRotationPlays: Int,
refreshHours: Int, refreshHours: Int,
) { ) {
scope.launch { scope.launch {
@@ -861,6 +864,7 @@ class AppStore(
source = source, source = source,
collectionPercent = collectionPercent, collectionPercent = collectionPercent,
recommendationCount = recommendationCount, recommendationCount = recommendationCount,
recommendationRotationPlays = recommendationRotationPlays,
refreshHours = refreshHours, refreshHours = refreshHours,
), ),
) )
@@ -928,6 +932,7 @@ class AppStore(
source: String, source: String,
collectionPercent: Int, collectionPercent: Int,
recommendationCount: Int, recommendationCount: Int,
recommendationRotationPlays: Int,
refreshHours: Int, refreshHours: Int,
) { ) {
scope.launch { scope.launch {
@@ -945,6 +950,7 @@ class AppStore(
source = source, source = source,
collectionPercent = collectionPercent, collectionPercent = collectionPercent,
recommendationCount = recommendationCount, recommendationCount = recommendationCount,
recommendationRotationPlays = recommendationRotationPlays,
refreshHours = refreshHours, refreshHours = refreshHours,
), ),
) )
@@ -1043,6 +1049,41 @@ class AppStore(
} }
} }
/**
* Asks the server to retire every active pick and fill the slots with other
* tracks. Plain refresh only tops up empty slots, which is why it usually
* returned the same list.
*/
fun rotateRecommendations() {
val moodId = _state.value.selectedMood?.mood?.id ?: return
if (_state.value.rotatingPicks || _state.value.discovering) return
scope.launch {
_state.update { it.copy(rotatingPicks = true) }
try {
val result = api.rotateRecommendations(moodId)
if (_state.value.selectedMood?.mood?.id == moodId) {
applyMoodDetail(result.detail)
}
_state.update {
it.copy(
rotatingPicks = false,
message = when {
result.error != null ->
"Swapped ${result.rotated} picks, but new ones failed: ${result.error}"
result.active > 0 -> "${result.active} new recommendations"
else -> "No different picks were available"
},
messageIsError = result.error != null,
messageId = it.messageId + 1,
)
}
} catch (t: Throwable) {
_state.update { it.copy(rotatingPicks = false) }
message(t)
}
}
}
fun addRecommendation(externalId: String) { fun addRecommendation(externalId: String) {
val moodId = _state.value.selectedMood?.mood?.id ?: return val moodId = _state.value.selectedMood?.mood?.id ?: return
if (_state.value.discovering) return if (_state.value.discovering) return
@@ -25,6 +25,7 @@ import androidx.compose.material.icons.rounded.Refresh
import androidx.compose.material.icons.rounded.RemoveCircleOutline import androidx.compose.material.icons.rounded.RemoveCircleOutline
import androidx.compose.material.icons.rounded.Search import androidx.compose.material.icons.rounded.Search
import androidx.compose.material.icons.rounded.Settings import androidx.compose.material.icons.rounded.Settings
import androidx.compose.material.icons.rounded.Shuffle
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenu
@@ -39,7 +40,6 @@ import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Slider import androidx.compose.material3.Slider
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@@ -186,19 +186,41 @@ fun MoodDetailScreen(state: AppState, store: AppStore) {
item { item {
HorizontalDivider(Modifier.padding(vertical = 12.dp)) HorizontalDivider(Modifier.padding(vertical = 12.dp))
SectionTitle("Recommendations") { SectionTitle("Recommendations") {
Row(verticalAlignment = Alignment.CenterVertically) { if (state.discovering || state.rotatingPicks) {
if (state.discovering) { CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp)
}
}
}
item {
val busy = state.discovering || state.rotatingPicks
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(10.dp),
) {
OutlinedButton(
onClick = { store.refreshRecommendations() },
enabled = !busy && mood.recommendationCount > 0,
) {
Icon(Icons.Rounded.Refresh, contentDescription = null, modifier = Modifier.size(16.dp))
Spacer(Modifier.width(6.dp))
Text("Refresh")
}
FilledTonalButton(
onClick = { store.rotateRecommendations() },
enabled = !busy && mood.recommendationCount > 0,
) {
if (state.rotatingPicks) {
CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp) CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp)
Spacer(Modifier.width(8.dp)) } else {
} Icon(
TextButton( Icons.Rounded.Shuffle,
onClick = { store.refreshRecommendations() }, contentDescription = null,
enabled = !state.discovering && mood.recommendationCount > 0, modifier = Modifier.size(16.dp),
) { )
Icon(Icons.Rounded.Refresh, contentDescription = null, modifier = Modifier.size(16.dp))
Spacer(Modifier.width(4.dp))
Text("Refresh")
} }
Spacer(Modifier.width(6.dp))
Text("All new")
} }
} }
} }
@@ -69,6 +69,9 @@ fun MoodSettingsScreen(state: AppState, store: AppStore) {
var sourceMenu by remember { mutableStateOf(false) } var sourceMenu by remember { mutableStateOf(false) }
var collectionPercent by remember(mood.id) { mutableStateOf(mood.collectionPercent.toFloat()) } var collectionPercent by remember(mood.id) { mutableStateOf(mood.collectionPercent.toFloat()) }
var recommendations by remember(mood.id) { mutableStateOf(mood.recommendationCount.toFloat()) } var recommendations by remember(mood.id) { mutableStateOf(mood.recommendationCount.toFloat()) }
var rotationPlays by remember(mood.id) {
mutableStateOf(mood.recommendationRotationPlays.toFloat())
}
var hours by remember(mood.id) { mutableStateOf(mood.refreshHours.toString()) } var hours by remember(mood.id) { mutableStateOf(mood.refreshHours.toString()) }
var confirmDelete by remember { mutableStateOf(false) } var confirmDelete by remember { mutableStateOf(false) }
val offline = mood.id in state.offlineMoods val offline = mood.id in state.offlineMoods
@@ -264,6 +267,32 @@ fun MoodSettingsScreen(state: AppState, store: AppStore) {
} }
} }
item {
val plays = rotationPlays.roundToInt()
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(
if (plays == 0) {
"Replace picks: never"
} else {
"Replace each pick after $plays ${if (plays == 1) "play" else "plays"}"
},
style = MaterialTheme.typography.bodySmall,
)
Slider(
value = rotationPlays,
onValueChange = { rotationPlays = it },
valueRange = 0f..10f,
steps = 9,
)
Text(
"A recommendation makes way for a different song once it has been played " +
"this often. Use All new on the mood page to swap them immediately.",
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}
item { item {
OutlinedTextField( OutlinedTextField(
value = hours, value = hours,
@@ -287,6 +316,7 @@ fun MoodSettingsScreen(state: AppState, store: AppStore) {
source = source, source = source,
collectionPercent = collectionPercent.roundToInt(), collectionPercent = collectionPercent.roundToInt(),
recommendationCount = recommendations.roundToInt(), recommendationCount = recommendations.roundToInt(),
recommendationRotationPlays = rotationPlays.roundToInt(),
refreshHours = hours.toIntOrNull() ?: mood.refreshHours, refreshHours = hours.toIntOrNull() ?: mood.refreshHours,
) )
}, },
@@ -129,7 +129,8 @@ fun MoodsScreen(state: AppState, store: AppStore) {
source, source,
collectionPercent, collectionPercent,
recommendations, recommendations,
hours, recommendationRotationPlays = 3,
refreshHours = hours,
) )
}, },
) )
@@ -583,6 +583,55 @@ class AppStoreTest {
AppLog.clear() AppLog.clear()
} }
@Test
fun `all new replaces recommendations through the rotate endpoint`() = runTest {
val storage = MemoryStorage()
val cache = AppCache(storage)
cache.saveSession(SessionState("http://music", "token", User("alice", admin = false)))
val fresh = """{"source":"youtube","externalId":"v2","title":"Fresh Pick",
"artist":"Artist","duration":180,"state":"downloading","playCount":0,
"firstSeen":"2026-01-01T00:00:00Z","lastSeen":"2026-01-01T00:00:00Z"}"""
var rotateCalls = 0
val engine = MockEngine { request ->
when (request.url.encodedPath) {
"/api/v1/me" -> respond(
"""{"name":"alice","admin":false}""",
HttpStatusCode.OK,
jsonHeaders,
)
"/api/v1/moods" -> respond("""{"moods":[${moodJson(1)}]}""", HttpStatusCode.OK, jsonHeaders)
"/api/v1/moods/mo-1" -> respond(
detailJson(listOf("sg-1"), recommendationJson("ready", "sg-1")),
HttpStatusCode.OK,
jsonHeaders,
)
"/api/v1/moods/mo-1/recommendations/rotate" -> {
rotateCalls += 1
respond(
"""{"detail":${detailJson(listOf("sg-1"), fresh)},
"rotated":1,"active":1}""",
HttpStatusCode.OK,
jsonHeaders,
)
}
else -> respondError(HttpStatusCode.NotFound)
}
}
val store = store(storage, cache, FakePlayer(), engine)
store.openMood("mo-1")
awaitState { store.state.value.selectedMood != null }
store.rotateRecommendations()
awaitState("rotate finished") {
rotateCalls == 1 && store.state.value.message?.contains("new recommendations") == true
}
val detail = assertNotNull(store.state.value.selectedMood)
assertEquals(listOf("v2"), detail.recommendations.map { it.externalId })
assertFalse(store.state.value.rotatingPicks)
store.release()
}
@Test @Test
fun `logout clears the session and the mood cache`() = runTest { fun `logout clears the session and the mood cache`() = runTest {
val storage = MemoryStorage() val storage = MemoryStorage()