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) {
|
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||||
super.onCreate(db)
|
super.onCreate(db)
|
||||||
seedStations(db)
|
seedStations(db, includePinned = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -472,20 +472,22 @@ class RadioPlaybackService : LifecycleService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun endConnectionSpan() {
|
private fun endConnectionSpan() {
|
||||||
if (connectionSpanId != 0L) {
|
val spanId = connectionSpanId
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
if (spanId != 0L) {
|
||||||
connectionSpanDao.updateEndedAt(connectionSpanId, System.currentTimeMillis())
|
|
||||||
}
|
|
||||||
connectionSpanId = 0L
|
connectionSpanId = 0L
|
||||||
|
serviceScope.launch(Dispatchers.IO) {
|
||||||
|
connectionSpanDao.updateEndedAt(spanId, System.currentTimeMillis())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun endListeningSession() {
|
private fun endListeningSession() {
|
||||||
if (listeningSessionId != 0L) {
|
val sessionId = listeningSessionId
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
if (sessionId != 0L) {
|
||||||
listeningSessionDao.updateEndedAt(listeningSessionId, System.currentTimeMillis())
|
|
||||||
}
|
|
||||||
listeningSessionId = 0L
|
listeningSessionId = 0L
|
||||||
|
serviceScope.launch(Dispatchers.IO) {
|
||||||
|
listeningSessionDao.updateEndedAt(sessionId, System.currentTimeMillis())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ fun RenamePlaylistDialog(
|
|||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onConfirm: (String) -> Unit
|
onConfirm: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
var name by remember { mutableStateOf(currentName) }
|
var name by remember(currentName) { mutableStateOf(currentName) }
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
|
|||||||
@@ -471,7 +471,7 @@ private fun DragReorderTabRow(
|
|||||||
Box {
|
Box {
|
||||||
Tab(
|
Tab(
|
||||||
selected = selectedTabIndex == index,
|
selected = selectedTabIndex == index,
|
||||||
onClick = { onSelectTab(index) },
|
onClick = {},
|
||||||
text = {
|
text = {
|
||||||
Text(
|
Text(
|
||||||
text = tab.label,
|
text = tab.label,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
@@ -355,10 +356,18 @@ class StationListViewModel(application: Application) : AndroidViewModel(applicat
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun reorderTabs(reorderedPlaylists: List<Playlist>) {
|
fun reorderTabs(reorderedPlaylists: List<Playlist>) {
|
||||||
|
val currentTab = viewState.value.tabs.getOrNull(viewState.value.selectedTabIndex)
|
||||||
|
val selectedPlaylistId = currentTab?.playlist?.id
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
for ((index, playlist) in reorderedPlaylists.withIndex()) {
|
for ((index, playlist) in reorderedPlaylists.withIndex()) {
|
||||||
playlistDao.updateSortOrder(playlist.id, index)
|
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