From 7a0ff2c70cfe0903be8c97ffd596176d07e4bd6c Mon Sep 17 00:00:00 2001 From: GeorgCantor Date: Sat, 18 Nov 2023 15:49:45 +0300 Subject: [PATCH] Remove !! operators --- .../uamp/viewmodels/MediaItemFragmentViewModel.kt | 7 ++++--- .../uamp/viewmodels/NowPlayingFragmentViewModel.kt | 2 +- .../automotive/UsernameAndPasswordSignInFragment.kt | 2 +- .../android/uamp/media/CastMediaItemConverter.kt | 2 +- .../com/example/android/uamp/media/MusicService.kt | 10 +++++++--- .../example/android/uamp/media/library/BrowseTree.kt | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/example/android/uamp/viewmodels/MediaItemFragmentViewModel.kt b/app/src/main/java/com/example/android/uamp/viewmodels/MediaItemFragmentViewModel.kt index 508bc7535..246216cd2 100644 --- a/app/src/main/java/com/example/android/uamp/viewmodels/MediaItemFragmentViewModel.kt +++ b/app/src/main/java/com/example/android/uamp/viewmodels/MediaItemFragmentViewModel.kt @@ -16,6 +16,7 @@ package com.example.android.uamp.viewmodels +import android.net.Uri import android.support.v4.media.MediaBrowserCompat import android.support.v4.media.MediaBrowserCompat.MediaItem import android.support.v4.media.MediaBrowserCompat.SubscriptionCallback @@ -61,12 +62,12 @@ class MediaItemFragmentViewModel( val itemsList = children.map { child -> val subtitle = child.description.subtitle ?: "" MediaItemData( - child.mediaId!!, + child.mediaId.orEmpty(), child.description.title.toString(), subtitle.toString(), - child.description.iconUri!!, + child.description.iconUri ?: Uri.EMPTY, child.isBrowsable, - getResourceForMediaId(child.mediaId!!) + getResourceForMediaId(child.mediaId.orEmpty()) ) } _mediaItems.postValue(itemsList) diff --git a/app/src/main/java/com/example/android/uamp/viewmodels/NowPlayingFragmentViewModel.kt b/app/src/main/java/com/example/android/uamp/viewmodels/NowPlayingFragmentViewModel.kt index 7757c0e40..b0467d0c4 100644 --- a/app/src/main/java/com/example/android/uamp/viewmodels/NowPlayingFragmentViewModel.kt +++ b/app/src/main/java/com/example/android/uamp/viewmodels/NowPlayingFragmentViewModel.kt @@ -170,7 +170,7 @@ class NowPlayingFragmentViewModel( // Only update media item once we have duration available if (mediaMetadata.duration != 0L && mediaMetadata.id != null) { val nowPlayingMetadata = NowPlayingMetadata( - mediaMetadata.id!!, + mediaMetadata.id.orEmpty(), mediaMetadata.albumArtUri, mediaMetadata.title?.trim(), mediaMetadata.displaySubtitle?.trim(), diff --git a/automotive/src/main/java/com/example/android/uamp/automotive/UsernameAndPasswordSignInFragment.kt b/automotive/src/main/java/com/example/android/uamp/automotive/UsernameAndPasswordSignInFragment.kt index 1cd8ed94b..e40d1e5a2 100644 --- a/automotive/src/main/java/com/example/android/uamp/automotive/UsernameAndPasswordSignInFragment.kt +++ b/automotive/src/main/java/com/example/android/uamp/automotive/UsernameAndPasswordSignInFragment.kt @@ -88,7 +88,7 @@ class UsernameAndPasswordSignInFragment : Fragment() { submitButton.text = getString(R.string.sign_in_submit_button_label) submitButton.setOnClickListener { - onSignIn(userId!!, passwordInput.text.toString()) + onSignIn(userId.orEmpty(), passwordInput.text.toString()) } } diff --git a/common/src/main/java/com/example/android/uamp/media/CastMediaItemConverter.kt b/common/src/main/java/com/example/android/uamp/media/CastMediaItemConverter.kt index bce302a4a..5d6d30f43 100644 --- a/common/src/main/java/com/example/android/uamp/media/CastMediaItemConverter.kt +++ b/common/src/main/java/com/example/android/uamp/media/CastMediaItemConverter.kt @@ -53,7 +53,7 @@ internal class CastMediaItemConverter : MediaItemConverter { mediaItem.mediaMetadata.discNumber?.let { castMediaMetadata.putInt(MediaMetadata.KEY_DISC_NUMBER, it) } - val mediaInfo = MediaInfo.Builder(mediaItem.localConfiguration!!.uri.toString()) + val mediaInfo = MediaInfo.Builder(mediaItem.localConfiguration?.uri.toString()) .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType(MimeTypes.AUDIO_MPEG) mediaItem.localConfiguration?.let { diff --git a/common/src/main/java/com/example/android/uamp/media/MusicService.kt b/common/src/main/java/com/example/android/uamp/media/MusicService.kt index 8e3ea68d1..37840bf0f 100644 --- a/common/src/main/java/com/example/android/uamp/media/MusicService.kt +++ b/common/src/main/java/com/example/android/uamp/media/MusicService.kt @@ -217,7 +217,11 @@ open class MusicService : MediaBrowserServiceCompat() { switchToPlayer( previousPlayer = null, - newPlayer = if (castPlayer?.isCastSessionAvailable == true) castPlayer!! else exoPlayer + newPlayer = if (castPlayer?.isCastSessionAvailable == true) { + castPlayer ?: exoPlayer + } else { + exoPlayer + } ) notificationManager.showNotificationForPlayer(currentPlayer) @@ -445,7 +449,7 @@ open class MusicService : MediaBrowserServiceCompat() { * remote Cast receiver rather than play audio locally. */ override fun onCastSessionAvailable() { - switchToPlayer(currentPlayer, castPlayer!!) + castPlayer?.let { switchToPlayer(currentPlayer, it) } } /** @@ -484,7 +488,7 @@ open class MusicService : MediaBrowserServiceCompat() { override fun onPrepare(playWhenReady: Boolean) { val recentSong = storage.loadRecentSong() ?: return onPrepareFromMediaId( - recentSong.mediaId!!, + recentSong.mediaId.orEmpty(), playWhenReady, recentSong.description.extras ) diff --git a/common/src/main/java/com/example/android/uamp/media/library/BrowseTree.kt b/common/src/main/java/com/example/android/uamp/media/library/BrowseTree.kt index c82bc490f..69384f143 100644 --- a/common/src/main/java/com/example/android/uamp/media/library/BrowseTree.kt +++ b/common/src/main/java/com/example/android/uamp/media/library/BrowseTree.kt @@ -147,7 +147,7 @@ class BrowseTree( // Insert the album's root with an empty list for its children, and return the list. return mutableListOf().also { - mediaIdToChildren[albumMetadata.id!!] = it + mediaIdToChildren[albumMetadata.id.orEmpty()] = it } } }