fix: address code review issues — pinned on fresh install, reorder selection, stale rename, detached scopes, duplicate click
Made-with: Cursor
This commit is contained in:
@@ -69,7 +69,7 @@ object SomaFmSeedData : RoomDatabase.Callback() {
|
||||
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
seedStations(db)
|
||||
seedStations(db, includePinned = true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -472,20 +472,22 @@ class RadioPlaybackService : LifecycleService() {
|
||||
}
|
||||
|
||||
private fun endConnectionSpan() {
|
||||
if (connectionSpanId != 0L) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
connectionSpanDao.updateEndedAt(connectionSpanId, System.currentTimeMillis())
|
||||
}
|
||||
val spanId = connectionSpanId
|
||||
if (spanId != 0L) {
|
||||
connectionSpanId = 0L
|
||||
serviceScope.launch(Dispatchers.IO) {
|
||||
connectionSpanDao.updateEndedAt(spanId, System.currentTimeMillis())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun endListeningSession() {
|
||||
if (listeningSessionId != 0L) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
listeningSessionDao.updateEndedAt(listeningSessionId, System.currentTimeMillis())
|
||||
}
|
||||
val sessionId = listeningSessionId
|
||||
if (sessionId != 0L) {
|
||||
listeningSessionId = 0L
|
||||
serviceScope.launch(Dispatchers.IO) {
|
||||
listeningSessionDao.updateEndedAt(sessionId, System.currentTimeMillis())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ fun RenamePlaylistDialog(
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: (String) -> Unit
|
||||
) {
|
||||
var name by remember { mutableStateOf(currentName) }
|
||||
var name by remember(currentName) { mutableStateOf(currentName) }
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
|
||||
@@ -471,7 +471,7 @@ private fun DragReorderTabRow(
|
||||
Box {
|
||||
Tab(
|
||||
selected = selectedTabIndex == index,
|
||||
onClick = { onSelectTab(index) },
|
||||
onClick = {},
|
||||
text = {
|
||||
Text(
|
||||
text = tab.label,
|
||||
|
||||
@@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
@@ -355,10 +356,18 @@ class StationListViewModel(application: Application) : AndroidViewModel(applicat
|
||||
}
|
||||
|
||||
fun reorderTabs(reorderedPlaylists: List<Playlist>) {
|
||||
val currentTab = viewState.value.tabs.getOrNull(viewState.value.selectedTabIndex)
|
||||
val selectedPlaylistId = currentTab?.playlist?.id
|
||||
viewModelScope.launch {
|
||||
for ((index, playlist) in reorderedPlaylists.withIndex()) {
|
||||
playlistDao.updateSortOrder(playlist.id, index)
|
||||
}
|
||||
if (selectedPlaylistId != null) {
|
||||
val playlists = playlistDao.getAllPlaylists().first()
|
||||
val tabs = buildTabs(playlists)
|
||||
val newIndex = tabs.indexOfFirst { it.playlist?.id == selectedPlaylistId }
|
||||
if (newIndex >= 0) _selectedTabIndex.value = newIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user