refactor(android): the track-list heart buttons share LikesRepository.toggleTrackLike (DRY A8)
Album detail, playlist detail and the player each flipped a track's like with the same lines (desired = id !in likedTrackIds; toggleLike(TRACK…)). They call toggleTrackLike(trackId, likedIds) now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+1
-4
@@ -133,9 +133,6 @@ class AlbumDetailViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun toggleLikeTrack(trackId: String) {
|
||||
val desired = trackId !in likedTrackIds.value
|
||||
viewModelScope.launch {
|
||||
likes.toggleLike(LikesRepository.ENTITY_TRACK, trackId, desired)
|
||||
}
|
||||
viewModelScope.launch { likes.toggleTrackLike(trackId, likedTrackIds.value) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +148,14 @@ class LikesRepository @Inject constructor(
|
||||
|
||||
// ── Writes (optimistic local → best-effort REST → enqueue on fail) ──
|
||||
|
||||
/**
|
||||
* Flips a track's like, reading whether it is liked now from [likedIds],
|
||||
* the set the screen is already showing. The heart buttons on track lists
|
||||
* (an album, a playlist, the player) call this.
|
||||
*/
|
||||
suspend fun toggleTrackLike(trackId: String, likedIds: Set<String>): Boolean =
|
||||
toggleLike(ENTITY_TRACK, trackId, desiredState = trackId !in likedIds)
|
||||
|
||||
/**
|
||||
* Toggle like state for [entityType]/[entityId]. UI doesn't need to
|
||||
* await this; the Flow re-emits immediately from the optimistic
|
||||
|
||||
@@ -61,10 +61,7 @@ class PlayerViewModel @Inject constructor(
|
||||
fun clearQueue() = controller.clearQueue()
|
||||
|
||||
fun toggleLikeTrack(trackId: String) {
|
||||
val desired = trackId !in likedTrackIds.value
|
||||
viewModelScope.launch {
|
||||
likes.toggleLike(LikesRepository.ENTITY_TRACK, trackId, desired)
|
||||
}
|
||||
viewModelScope.launch { likes.toggleTrackLike(trackId, likedTrackIds.value) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -228,10 +228,7 @@ class PlaylistDetailViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun toggleLikeTrack(trackId: String) {
|
||||
val desired = trackId !in likedTrackIds.value
|
||||
viewModelScope.launch {
|
||||
likes.toggleLike(LikesRepository.ENTITY_TRACK, trackId, desired)
|
||||
}
|
||||
viewModelScope.launch { likes.toggleTrackLike(trackId, likedTrackIds.value) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user