From 9bd227e8077c824045f7b3c84f45285efff0c1e3 Mon Sep 17 00:00:00 2001 From: vfsfitvnm Date: Wed, 19 Oct 2022 18:17:49 +0200 Subject: [PATCH] Set targetSdk to 33 (#267) --- app/build.gradle.kts | 2 +- app/src/main/AndroidManifest.xml | 1 + .../vimusic/service/PlayerService.kt | 42 +++++++++++-------- .../ui/screens/settings/AppearanceSettings.kt | 26 +++++++----- .../it/vfsfitvnm/vimusic/utils/Utils.kt | 4 ++ 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b2551c2..17b8b8f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,7 +10,7 @@ android { defaultConfig { applicationId = "it.vfsfitvnm.vimusic" minSdk = 21 - targetSdk = 32 + targetSdk = 33 versionCode = 18 versionName = "0.5.2" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ba23fad..7bb4de4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt index ce219db..aa6be00 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt @@ -86,6 +86,7 @@ import it.vfsfitvnm.vimusic.utils.forceSeekToNext import it.vfsfitvnm.vimusic.utils.forceSeekToPrevious import it.vfsfitvnm.vimusic.utils.getEnum import it.vfsfitvnm.vimusic.utils.intent +import it.vfsfitvnm.vimusic.utils.isAtLeastAndroid13 import it.vfsfitvnm.vimusic.utils.isInvincibilityEnabledKey import it.vfsfitvnm.vimusic.utils.isShowingThumbnailInLockscreenKey import it.vfsfitvnm.vimusic.utils.mediaItems @@ -310,7 +311,8 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene playTime = totalPlayTimeMs ) ) - } catch (_: SQLException) { } + } catch (_: SQLException) { + } } } } @@ -426,8 +428,18 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene } private fun maybeShowSongCoverInLockScreen() { - val bitmap = if (isShowingThumbnailInLockscreen) bitmapProvider.bitmap else null - metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap) + val bitmap = + if (isAtLeastAndroid13 || isShowingThumbnailInLockscreen) bitmapProvider.bitmap else null + + metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap) + + if (isAtLeastAndroid13 && player.currentMediaItemIndex == 0) { + metadataBuilder.putText( + MediaMetadata.METADATA_KEY_TITLE, + "${player.mediaMetadata.title} " + ) + } + mediaSession.setMetadata(metadataBuilder.build()) } @@ -460,21 +472,14 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene override fun onEvents(player: Player, events: Player.Events) { if (player.duration != C.TIME_UNSET) { - metadataBuilder - .putText( - MediaMetadata.METADATA_KEY_TITLE, - player.currentMediaItem?.mediaMetadata?.title - ) - .putText( - MediaMetadata.METADATA_KEY_ARTIST, - player.currentMediaItem?.mediaMetadata?.artist - ) - .putText( - MediaMetadata.METADATA_KEY_ALBUM, - player.currentMediaItem?.mediaMetadata?.albumTitle - ) - .putLong(MediaMetadata.METADATA_KEY_DURATION, player.duration) - .build().let(mediaSession::setMetadata) + mediaSession.setMetadata( + metadataBuilder + .putText(MediaMetadata.METADATA_KEY_TITLE, player.mediaMetadata.title) + .putText(MediaMetadata.METADATA_KEY_ARTIST, player.mediaMetadata.artist) + .putText(MediaMetadata.METADATA_KEY_ALBUM, player.mediaMetadata.albumTitle) + .putLong(MediaMetadata.METADATA_KEY_DURATION, player.duration) + .build() + ) } stateBuilder @@ -538,6 +543,7 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene isShowingThumbnailInLockscreen = sharedPreferences.getBoolean(key, true) maybeShowSongCoverInLockScreen() } + trackLoopEnabledKey, queueLoopEnabledKey -> { player.repeatMode = when { preferences.getBoolean(trackLoopEnabledKey, false) -> Player.REPEAT_MODE_ONE diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/settings/AppearanceSettings.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/settings/AppearanceSettings.kt index 8c3ffad..827c2f7 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/settings/AppearanceSettings.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/settings/AppearanceSettings.kt @@ -1,11 +1,15 @@ package it.vfsfitvnm.vimusic.ui.screens.settings +import android.os.Build import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.WindowInsetsSides +import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.rememberScrollState @@ -16,9 +20,6 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import it.vfsfitvnm.vimusic.LocalPlayerAwareWindowInsets -import androidx.compose.foundation.layout.WindowInsetsSides -import androidx.compose.foundation.layout.asPaddingValues -import androidx.compose.foundation.layout.only import it.vfsfitvnm.vimusic.enums.ColorPaletteMode import it.vfsfitvnm.vimusic.enums.ColorPaletteName import it.vfsfitvnm.vimusic.enums.ThumbnailRoundness @@ -27,6 +28,7 @@ import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance import it.vfsfitvnm.vimusic.utils.applyFontPaddingKey import it.vfsfitvnm.vimusic.utils.colorPaletteModeKey import it.vfsfitvnm.vimusic.utils.colorPaletteNameKey +import it.vfsfitvnm.vimusic.utils.isAtLeastAndroid13 import it.vfsfitvnm.vimusic.utils.isShowingThumbnailInLockscreenKey import it.vfsfitvnm.vimusic.utils.rememberPreference import it.vfsfitvnm.vimusic.utils.thumbnailRoundnessKey @@ -114,15 +116,17 @@ fun AppearanceSettings() { onCheckedChange = { applyFontPadding = it } ) - SettingsGroupSpacer() + if (!isAtLeastAndroid13) { + SettingsGroupSpacer() - SettingsEntryGroupText(title = "LOCKSCREEN") + SettingsEntryGroupText(title = "LOCKSCREEN") - SwitchSettingEntry( - title = "Show song cover", - text = "Use the playing song cover as the lockscreen wallpaper", - isChecked = isShowingThumbnailInLockscreen, - onCheckedChange = { isShowingThumbnailInLockscreen = it } - ) + SwitchSettingEntry( + title = "Show song cover", + text = "Use the playing song cover as the lockscreen wallpaper", + isChecked = isShowingThumbnailInLockscreen, + onCheckedChange = { isShowingThumbnailInLockscreen = it } + ) + } } } diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/Utils.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/Utils.kt index 348cfd7..0b4b169 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/Utils.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/Utils.kt @@ -1,6 +1,7 @@ package it.vfsfitvnm.vimusic.utils import android.net.Uri +import android.os.Build import android.text.format.DateUtils import androidx.core.net.toUri import androidx.core.os.bundleOf @@ -111,3 +112,6 @@ suspend fun Result.completed(): Result= Build.VERSION_CODES.TIRAMISU