Skip to content

Commit c8cb17a

Browse files
refactor: fix deprecation warnings and remove redundant code
1 parent dd7e55b commit c8cb17a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+134
-166
lines changed

app/src/main/kotlin/com/metrolist/music/db/DatabaseDao.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ interface DatabaseDao {
423423
toTimeStamp: Long? = LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli(),
424424
): Flow<List<Album>>
425425

426+
@Transaction
427+
@RewriteQueriesToDropUnusedColumns
426428
@Query("""
427429
SELECT album.*, count(song.dateDownload) downloadCount
428430
FROM album_artist_map

app/src/main/kotlin/com/metrolist/music/db/entities/Album.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.metrolist.music.db.entities
22

33
import androidx.compose.runtime.Immutable
4+
import androidx.room.ColumnInfo
5+
import androidx.room.Ignore
46
import androidx.room.Embedded
57
import androidx.room.Junction
68
import androidx.room.Relation
@@ -20,10 +22,10 @@ data class Album(
2022
entityColumn = "artistId",
2123
),
2224
)
23-
val artists: List<ArtistEntity>,
24-
val songCountListened: Int? = 0,
25-
val timeListened: Int? = 0,
25+
val artists: List<ArtistEntity> = emptyList(),
2626
) : LocalItem() {
27+
@Ignore var songCountListened: Int = 0
28+
@Ignore var timeListened: Long = 0
2729
override val id: String
2830
get() = album.id
2931
override val title: String

app/src/main/kotlin/com/metrolist/music/playback/MusicService.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,14 +1114,11 @@ class MusicService :
11141114
}
11151115
}
11161116

1117-
if (playbackData == null) {
1118-
throw PlaybackException(
1119-
getString(R.string.error_unknown),
1120-
null,
1121-
PlaybackException.ERROR_CODE_REMOTE_ERROR
1122-
)
1123-
} else {
1124-
val format = playbackData.format
1117+
val nonNullPlayback = requireNotNull(playbackData) {
1118+
getString(R.string.error_unknown)
1119+
}
1120+
run {
1121+
val format = nonNullPlayback.format
11251122

11261123
database.query {
11271124
upsert(
@@ -1133,17 +1130,17 @@ class MusicService :
11331130
bitrate = format.bitrate,
11341131
sampleRate = format.audioSampleRate,
11351132
contentLength = format.contentLength!!,
1136-
loudnessDb = playbackData.audioConfig?.loudnessDb,
1137-
playbackUrl = playbackData.playbackTracking?.videostatsPlaybackUrl?.baseUrl
1133+
loudnessDb = nonNullPlayback.audioConfig?.loudnessDb,
1134+
playbackUrl = nonNullPlayback.playbackTracking?.videostatsPlaybackUrl?.baseUrl
11381135
)
11391136
)
11401137
}
1141-
scope.launch(Dispatchers.IO) { recoverSong(mediaId, playbackData) }
1138+
scope.launch(Dispatchers.IO) { recoverSong(mediaId, nonNullPlayback) }
11421139

1143-
val streamUrl = playbackData.streamUrl
1140+
val streamUrl = nonNullPlayback.streamUrl
11441141

11451142
songUrlCache[mediaId] =
1146-
streamUrl to System.currentTimeMillis() + (playbackData.streamExpiresInSeconds * 1000L)
1143+
streamUrl to System.currentTimeMillis() + (nonNullPlayback.streamExpiresInSeconds * 1000L)
11471144
return@Factory dataSpec.withUri(streamUrl.toUri()).subrange(dataSpec.uriPositionOffset, CHUNK_LENGTH)
11481145
}
11491146
}

app/src/main/kotlin/com/metrolist/music/ui/menu/LyricsMenu.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import androidx.compose.ui.text.input.TextFieldValue
4747
import androidx.compose.ui.text.style.TextAlign
4848
import androidx.compose.ui.text.style.TextOverflow
4949
import androidx.compose.ui.unit.dp
50-
import androidx.hilt.navigation.compose.hiltViewModel
50+
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
5151
import com.metrolist.music.LocalDatabase
5252
import com.metrolist.music.R
5353
import com.metrolist.music.db.entities.LyricsEntity

app/src/main/kotlin/com/metrolist/music/ui/player/LyricsScreen.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,12 @@ fun LyricsScreen(
199199
PlayerBackgroundStyle.DEFAULT -> MaterialTheme.colorScheme.onBackground
200200
PlayerBackgroundStyle.BLUR -> Color.White
201201
PlayerBackgroundStyle.GRADIENT -> Color.White
202-
else -> MaterialTheme.colorScheme.onBackground
203202
}
204203

205204
val icBackgroundColor = when (playerBackground) {
206205
PlayerBackgroundStyle.DEFAULT -> MaterialTheme.colorScheme.surface
207206
PlayerBackgroundStyle.BLUR -> Color.Black
208207
PlayerBackgroundStyle.GRADIENT -> Color.Black
209-
else -> MaterialTheme.colorScheme.surface
210208
}
211209

212210
LaunchedEffect(playbackState) {

app/src/main/kotlin/com/metrolist/music/ui/player/Player.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,13 @@ fun BottomSheetPlayer(
337337
PlayerBackgroundStyle.DEFAULT -> MaterialTheme.colorScheme.onBackground
338338
PlayerBackgroundStyle.BLUR -> Color.White
339339
PlayerBackgroundStyle.GRADIENT -> Color.White
340-
else -> MaterialTheme.colorScheme.onBackground
341340
}
342341

343342
val icBackgroundColor =
344343
when (playerBackground) {
345344
PlayerBackgroundStyle.DEFAULT -> MaterialTheme.colorScheme.surface
346345
PlayerBackgroundStyle.BLUR -> Color.Black
347346
PlayerBackgroundStyle.GRADIENT -> Color.Black
348-
else -> MaterialTheme.colorScheme.surface
349347
}
350348

351349
val (textButtonColor, iconButtonColor) = when (playerButtonsStyle) {

app/src/main/kotlin/com/metrolist/music/ui/player/Queue.kt

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import androidx.compose.ui.draw.clip
8181
import androidx.compose.ui.graphics.Color
8282
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
8383
import androidx.compose.ui.input.nestedscroll.nestedScroll
84-
import androidx.compose.ui.platform.LocalClipboardManager
84+
import androidx.compose.ui.platform.LocalClipboard
8585
import androidx.compose.ui.platform.LocalContext
8686
import androidx.compose.ui.platform.LocalHapticFeedback
8787
import androidx.compose.ui.res.painterResource
@@ -147,7 +147,7 @@ fun Queue(
147147
) {
148148
val context = LocalContext.current
149149
val haptic = LocalHapticFeedback.current
150-
val clipboardManager = LocalClipboardManager.current
150+
val clipboardManager = LocalClipboard.current
151151
val menuState = LocalMenuState.current
152152
val bottomSheetPageState = LocalBottomSheetPageState.current
153153

@@ -686,40 +686,43 @@ fun Queue(
686686
val currentItem by rememberUpdatedState(window)
687687
val dismissBoxState =
688688
rememberSwipeToDismissBoxState(
689-
positionalThreshold = { totalDistance ->
690-
totalDistance
691-
},
692-
confirmValueChange = { dismissValue ->
693-
if (dismissValue == SwipeToDismissBoxValue.StartToEnd ||
694-
dismissValue == SwipeToDismissBoxValue.EndToStart
695-
) {
696-
playerConnection.player.removeMediaItem(currentItem.firstPeriodIndex)
697-
dismissJob?.cancel()
698-
dismissJob =
699-
coroutineScope.launch {
700-
val snackbarResult =
701-
snackbarHostState.showSnackbar(
702-
message =
703-
context.getString(
704-
R.string.removed_song_from_playlist,
705-
currentItem.mediaItem.metadata?.title,
706-
),
707-
actionLabel = context.getString(R.string.undo),
708-
duration = SnackbarDuration.Short,
709-
)
710-
if (snackbarResult == SnackbarResult.ActionPerformed) {
711-
playerConnection.player.addMediaItem(currentItem.mediaItem)
712-
playerConnection.player.moveMediaItem(
713-
mutableQueueWindows.size,
714-
currentItem.firstPeriodIndex,
715-
)
716-
}
717-
}
718-
}
719-
true
720-
},
689+
positionalThreshold = { totalDistance -> totalDistance }
721690
)
722691

692+
var processedDismiss by remember { mutableStateOf(false) }
693+
LaunchedEffect(dismissBoxState.currentValue) {
694+
val dv = dismissBoxState.currentValue
695+
if (!processedDismiss && (
696+
dv == SwipeToDismissBoxValue.StartToEnd ||
697+
dv == SwipeToDismissBoxValue.EndToStart
698+
)
699+
) {
700+
processedDismiss = true
701+
playerConnection.player.removeMediaItem(currentItem.firstPeriodIndex)
702+
dismissJob?.cancel()
703+
dismissJob = coroutineScope.launch {
704+
val snackbarResult = snackbarHostState.showSnackbar(
705+
message = context.getString(
706+
R.string.removed_song_from_playlist,
707+
currentItem.mediaItem.metadata?.title,
708+
),
709+
actionLabel = context.getString(R.string.undo),
710+
duration = SnackbarDuration.Short,
711+
)
712+
if (snackbarResult == SnackbarResult.ActionPerformed) {
713+
playerConnection.player.addMediaItem(currentItem.mediaItem)
714+
playerConnection.player.moveMediaItem(
715+
mutableQueueWindows.size,
716+
currentItem.firstPeriodIndex,
717+
)
718+
}
719+
}
720+
}
721+
if (dv == SwipeToDismissBoxValue.Settled) {
722+
processedDismiss = false
723+
}
724+
}
725+
723726
val content: @Composable () -> Unit = {
724727
Row(
725728
horizontalArrangement = Arrangement.Center,

app/src/main/kotlin/com/metrolist/music/ui/player/Thumbnail.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ fun Thumbnail(
108108
PlayerBackgroundStyle.DEFAULT -> MaterialTheme.colorScheme.onBackground
109109
PlayerBackgroundStyle.BLUR -> Color.White
110110
PlayerBackgroundStyle.GRADIENT -> Color.White
111-
else -> MaterialTheme.colorScheme.onBackground
112111
}
113112

114113
// Grid state

app/src/main/kotlin/com/metrolist/music/ui/screens/AccountScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import androidx.compose.ui.platform.LocalHapticFeedback
2121
import androidx.compose.ui.res.painterResource
2222
import androidx.compose.ui.res.stringResource
2323
import androidx.compose.ui.unit.dp
24-
import androidx.hilt.navigation.compose.hiltViewModel
24+
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
2525
import androidx.navigation.NavController
2626
import com.metrolist.music.LocalPlayerAwareWindowInsets
2727
import com.metrolist.music.R

app/src/main/kotlin/com/metrolist/music/ui/screens/AlbumScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import androidx.compose.ui.unit.dp
6161
import androidx.compose.ui.unit.sp
6262
import androidx.compose.ui.util.fastForEachIndexed
6363
import androidx.core.net.toUri
64-
import androidx.hilt.navigation.compose.hiltViewModel
64+
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
6565
import androidx.media3.exoplayer.offline.Download
6666
import androidx.media3.exoplayer.offline.DownloadRequest
6767
import androidx.media3.exoplayer.offline.DownloadService
@@ -397,7 +397,7 @@ fun AlbumScreen(
397397
}
398398
}
399399

400-
if (wrappedSongs != null) {
400+
if (!wrappedSongs.isNullOrEmpty()) {
401401
itemsIndexed(
402402
items = wrappedSongs,
403403
key = { _, song -> song.item.id },

0 commit comments

Comments
 (0)