Skip to content

Commit

Permalink
Apply PR recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Feb 15, 2024
1 parent c6d0c0b commit 8252f5e
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal class CurrentMediaItemTracker internal constructor(
* Set media item if has not tracking data, set to null
*/
private fun setMediaItem(mediaItem: MediaItem?) {
if (enabled && mediaItem.canHaveTrackingSession()) {
if (enabled && mediaItem != null && mediaItem.canHaveTrackingSession()) {
if (!areEqual(currentMediaItem, mediaItem)) {
currentItemChange(currentMediaItem, mediaItem)
currentMediaItem = mediaItem
Expand All @@ -69,12 +69,7 @@ internal class CurrentMediaItemTracker internal constructor(
}
}

private fun currentItemChange(lastMediaItem: MediaItem?, newMediaItem: MediaItem?) {
require(newMediaItem.canHaveTrackingSession())
if (newMediaItem == null) {
stopSession(MediaItemTracker.StopReason.Stop)
return
}
private fun currentItemChange(lastMediaItem: MediaItem?, newMediaItem: MediaItem) {
if (lastMediaItem == null) {
startNewSession(newMediaItem)
return
Expand Down Expand Up @@ -183,8 +178,8 @@ internal class CurrentMediaItemTracker internal constructor(
}
}

private fun MediaItem?.canHaveTrackingSession(): Boolean {
return this?.getMediaItemTrackerDataOrNull() != null
private fun MediaItem.canHaveTrackingSession(): Boolean {
return this.getMediaItemTrackerDataOrNull() != null
}

private fun MediaItem.getIdentifier(): String? {
Expand Down

0 comments on commit 8252f5e

Please sign in to comment.