Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9464ba53d0 |
No files matched your search
@@ -32,6 +32,10 @@ a server-driven radio session and songs are added from Deezer or YouTube Music.
|
||||
- Add to mood;
|
||||
- Not interested (permanent for the mood);
|
||||
- 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
|
||||
`collectionPercent`. The app keeps a small queue and asks for more from the
|
||||
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
|
||||
web seek natively; desktop restarts the decoder at the requested position.
|
||||
- **Mood settings** live on their own screen: name, description, discovery hint,
|
||||
genres, source, collection share, recommendations, refresh interval, a
|
||||
**Keep this mood offline** switch, and Delete at the bottom.
|
||||
genres, source, collection share, recommendation count and replacement
|
||||
threshold, refresh interval, a **Keep this mood offline** switch, and Delete
|
||||
at the bottom.
|
||||
- **Downloads** screen for device-side copies: play, delete, clear, storage
|
||||
usage.
|
||||
- **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 |
|
||||
| `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`
|
||||
(`ResolutionStrategy.AUTO`), so only the tag/version name needs to change.
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ val hasUploadKey = uploadKeyStore?.exists() == true &&
|
||||
val appVersionCode = (System.getenv("VERSION_CODE") ?: localProperties.getProperty("VERSION_CODE") ?: "1").toInt()
|
||||
val appVersionName = System.getenv("VERSION_NAME")
|
||||
?: localProperties.getProperty("VERSION_NAME")
|
||||
?: "0.4.3"
|
||||
?: "0.5.0"
|
||||
|
||||
kotlin {
|
||||
androidTarget {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package win.taptap.musicmanager.client
|
||||
|
||||
/** 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 =
|
||||
parse(
|
||||
http.post(url("/moods/$moodId/recommendations/$externalId/add")) {
|
||||
|
||||
@@ -98,6 +98,8 @@ data class Mood(
|
||||
val collectionPercent: Int = 50,
|
||||
val recommendationPercent: Int = 50,
|
||||
val recommendationCount: Int = 10,
|
||||
/** Plays before a pick is replaced; 0 = never rotate. */
|
||||
val recommendationRotationPlays: Int = 3,
|
||||
val refreshHours: Int = 24,
|
||||
val lastDiscoveryAt: String? = null,
|
||||
val createdAt: String,
|
||||
@@ -139,6 +141,7 @@ data class Recommendation(
|
||||
val error: String? = null,
|
||||
val firstSeen: String = "",
|
||||
val lastSeen: String = "",
|
||||
val playCount: Int = 0,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
@@ -174,6 +177,14 @@ data class RecommendationDecision(
|
||||
val recommendation: Recommendation,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class RecommendationRotation(
|
||||
val detail: MoodDetail,
|
||||
val rotated: Int = 0,
|
||||
val active: Int = 0,
|
||||
val error: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SearchResult(
|
||||
val source: String = "youtube",
|
||||
@@ -257,6 +268,7 @@ data class CreateMoodRequest(
|
||||
val source: String? = null,
|
||||
val collectionPercent: Int = 50,
|
||||
val recommendationCount: Int = 10,
|
||||
val recommendationRotationPlays: Int = 3,
|
||||
val refreshHours: Int = 24,
|
||||
)
|
||||
|
||||
@@ -271,6 +283,7 @@ data class UpdateMoodRequest(
|
||||
val source: String? = null,
|
||||
val collectionPercent: Int? = null,
|
||||
val recommendationCount: Int? = null,
|
||||
val recommendationRotationPlays: Int? = null,
|
||||
val refreshHours: Int? = null,
|
||||
)
|
||||
|
||||
|
||||
@@ -94,6 +94,8 @@ data class AppState(
|
||||
val loading: Boolean = false,
|
||||
val saving: Boolean = false,
|
||||
val discovering: Boolean = false,
|
||||
/** True while every recommendation is being replaced. */
|
||||
val rotatingPicks: Boolean = false,
|
||||
val message: String? = null,
|
||||
val messageIsError: Boolean = false,
|
||||
val messageId: Long = 0,
|
||||
@@ -847,6 +849,7 @@ class AppStore(
|
||||
source: String,
|
||||
collectionPercent: Int,
|
||||
recommendationCount: Int,
|
||||
recommendationRotationPlays: Int,
|
||||
refreshHours: Int,
|
||||
) {
|
||||
scope.launch {
|
||||
@@ -861,6 +864,7 @@ class AppStore(
|
||||
source = source,
|
||||
collectionPercent = collectionPercent,
|
||||
recommendationCount = recommendationCount,
|
||||
recommendationRotationPlays = recommendationRotationPlays,
|
||||
refreshHours = refreshHours,
|
||||
),
|
||||
)
|
||||
@@ -928,6 +932,7 @@ class AppStore(
|
||||
source: String,
|
||||
collectionPercent: Int,
|
||||
recommendationCount: Int,
|
||||
recommendationRotationPlays: Int,
|
||||
refreshHours: Int,
|
||||
) {
|
||||
scope.launch {
|
||||
@@ -945,6 +950,7 @@ class AppStore(
|
||||
source = source,
|
||||
collectionPercent = collectionPercent,
|
||||
recommendationCount = recommendationCount,
|
||||
recommendationRotationPlays = recommendationRotationPlays,
|
||||
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) {
|
||||
val moodId = _state.value.selectedMood?.mood?.id ?: return
|
||||
if (_state.value.discovering) return
|
||||
|
||||
+29
-7
@@ -25,6 +25,7 @@ import androidx.compose.material.icons.rounded.Refresh
|
||||
import androidx.compose.material.icons.rounded.RemoveCircleOutline
|
||||
import androidx.compose.material.icons.rounded.Search
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material.icons.rounded.Shuffle
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
@@ -39,7 +40,6 @@ import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -186,19 +186,41 @@ fun MoodDetailScreen(state: AppState, store: AppStore) {
|
||||
item {
|
||||
HorizontalDivider(Modifier.padding(vertical = 12.dp))
|
||||
SectionTitle("Recommendations") {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
if (state.discovering) {
|
||||
if (state.discovering || state.rotatingPicks) {
|
||||
CircularProgressIndicator(Modifier.size(16.dp), strokeWidth = 2.dp)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
}
|
||||
TextButton(
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
val busy = state.discovering || state.rotatingPicks
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
OutlinedButton(
|
||||
onClick = { store.refreshRecommendations() },
|
||||
enabled = !state.discovering && mood.recommendationCount > 0,
|
||||
enabled = !busy && mood.recommendationCount > 0,
|
||||
) {
|
||||
Icon(Icons.Rounded.Refresh, contentDescription = null, modifier = Modifier.size(16.dp))
|
||||
Spacer(Modifier.width(4.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)
|
||||
} else {
|
||||
Icon(
|
||||
Icons.Rounded.Shuffle,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(16.dp),
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(6.dp))
|
||||
Text("All new")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
@@ -69,6 +69,9 @@ fun MoodSettingsScreen(state: AppState, store: AppStore) {
|
||||
var sourceMenu by remember { mutableStateOf(false) }
|
||||
var collectionPercent by remember(mood.id) { mutableStateOf(mood.collectionPercent.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 confirmDelete by remember { mutableStateOf(false) }
|
||||
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 {
|
||||
OutlinedTextField(
|
||||
value = hours,
|
||||
@@ -287,6 +316,7 @@ fun MoodSettingsScreen(state: AppState, store: AppStore) {
|
||||
source = source,
|
||||
collectionPercent = collectionPercent.roundToInt(),
|
||||
recommendationCount = recommendations.roundToInt(),
|
||||
recommendationRotationPlays = rotationPlays.roundToInt(),
|
||||
refreshHours = hours.toIntOrNull() ?: mood.refreshHours,
|
||||
)
|
||||
},
|
||||
|
||||
@@ -129,7 +129,8 @@ fun MoodsScreen(state: AppState, store: AppStore) {
|
||||
source,
|
||||
collectionPercent,
|
||||
recommendations,
|
||||
hours,
|
||||
recommendationRotationPlays = 3,
|
||||
refreshHours = hours,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -583,6 +583,55 @@ class AppStoreTest {
|
||||
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
|
||||
fun `logout clears the session and the mood cache`() = runTest {
|
||||
val storage = MemoryStorage()
|
||||
|
||||
Reference in new issue
Block a user