From 44679855cd2746bba7addcbb7a9ded77726bc86a Mon Sep 17 00:00:00 2001 From: le-firehawk Date: Thu, 18 Sep 2025 18:51:06 +0930 Subject: [PATCH] fix: Replace poor syntax that created warnings during build --- .../tempo/subsonic/models/Share.kt | 22 +++++++++---------- .../tempo/service/MediaService.kt | 6 ++--- .../tempo/service/MediaService.kt | 14 +++++++++--- .../cappielloantonio/tempo/util/Flavors.java | 4 +++- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/tempo/subsonic/models/Share.kt b/app/src/main/java/com/cappielloantonio/tempo/subsonic/models/Share.kt index 193cefc8..83332068 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/subsonic/models/Share.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/subsonic/models/Share.kt @@ -8,15 +8,15 @@ import java.util.* @Keep @Parcelize -class Share : Parcelable { +data class Share( @SerializedName("entry") - var entries: List? = null - var id: String? = null - var url: String? = null - var description: String? = null - var username: String? = null - var created: Date? = null - var expires: Date? = null - var lastVisited: Date? = null - var visitCount = 0 -} \ No newline at end of file + var entries: List? = null, + var id: String? = null, + var url: String? = null, + var description: String? = null, + var username: String? = null, + var created: Date? = null, + var expires: Date? = null, + var lastVisited: Date? = null, + var visitCount: Int = 0 +) : Parcelable \ No newline at end of file diff --git a/app/src/notquitemy/java/com/cappielloantonio/tempo/service/MediaService.kt b/app/src/notquitemy/java/com/cappielloantonio/tempo/service/MediaService.kt index 870a1537..613650bc 100644 --- a/app/src/notquitemy/java/com/cappielloantonio/tempo/service/MediaService.kt +++ b/app/src/notquitemy/java/com/cappielloantonio/tempo/service/MediaService.kt @@ -123,9 +123,9 @@ class MediaService : MediaLibraryService() { val connectionResult = super.onConnect(session, controller) val availableSessionCommands = connectionResult.availableSessionCommands.buildUpon() - shuffleCommands.forEach { commandButton -> + shuffleCommands.forEach { // TODO: Aggiungere i comandi personalizzati - // commandButton.sessionCommand?.let { availableSessionCommands.add(it) } + // it.sessionCommand?.let { availableSessionCommands.add(it) } } return MediaSession.ConnectionResult.accept( @@ -430,7 +430,7 @@ class MediaService : MediaLibraryService() { .build() } - private fun ignoreFuture(customLayout: ListenableFuture) { + private fun ignoreFuture(@Suppress("UNUSED_PARAMETER") customLayout: ListenableFuture) { /* Do nothing. */ } diff --git a/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaService.kt b/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaService.kt index 7ae707bc..125ef0dd 100644 --- a/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaService.kt +++ b/app/src/tempo/java/com/cappielloantonio/tempo/service/MediaService.kt @@ -8,6 +8,7 @@ import android.os.Binder import android.os.IBinder import android.os.Handler import android.os.Looper +import androidx.core.content.ContextCompat import androidx.media3.cast.CastPlayer import androidx.media3.cast.SessionAvailabilityListener import androidx.media3.common.AudioAttributes @@ -73,10 +74,10 @@ class MediaService : MediaLibraryService(), SessionAvailabilityListener { initializeRepository() initializePlayer() - initializeCastPlayer() initializeMediaLibrarySession() restorePlayerFromQueue() initializePlayerListener() + initializeCastPlayer() initializeEqualizerManager() setPlayer( @@ -150,8 +151,15 @@ class MediaService : MediaLibraryService(), SessionAvailabilityListener { if (GoogleApiAvailability.getInstance() .isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS ) { - castPlayer = CastPlayer(CastContext.getSharedInstance(this)) - castPlayer.setSessionAvailabilityListener(this) + CastContext.getSharedInstance(this, ContextCompat.getMainExecutor(this)) + .addOnSuccessListener { castContext -> + castPlayer = CastPlayer(castContext) + castPlayer.setSessionAvailabilityListener(this@MediaService) + + if (castPlayer.isCastSessionAvailable && this::mediaLibrarySession.isInitialized) { + setPlayer(player, castPlayer) + } + } } } diff --git a/app/src/tempo/java/com/cappielloantonio/tempo/util/Flavors.java b/app/src/tempo/java/com/cappielloantonio/tempo/util/Flavors.java index 4bed2921..73c7e43b 100644 --- a/app/src/tempo/java/com/cappielloantonio/tempo/util/Flavors.java +++ b/app/src/tempo/java/com/cappielloantonio/tempo/util/Flavors.java @@ -2,6 +2,8 @@ package com.cappielloantonio.tempo.util; import android.content.Context; +import androidx.core.content.ContextCompat; + import com.google.android.gms.cast.framework.CastContext; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; @@ -9,6 +11,6 @@ import com.google.android.gms.common.GoogleApiAvailability; public class Flavors { public static void initializeCastContext(Context context) { if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) - CastContext.getSharedInstance(context); + CastContext.getSharedInstance(context, ContextCompat.getMainExecutor(context)); } }