@@ -30,7 +30,6 @@ import org.schabi.newpipe.player.notification.NotificationPlayerUi
3030import org.schabi.newpipe.util.Localization
3131import org.schabi.newpipe.util.ThemeHelper
3232import java.lang.ref.WeakReference
33- import java.util.function.Consumer
3433
3534/* *
3635 * One background service for our player. Even though the player has multiple UIs
@@ -60,8 +59,8 @@ class PlayerService : Service() {
6059 loading stream metadata) takes a lot of time, the app would crash on Android 8+ as the
6160 service would never be put in the foreground while we said to the system we would do so
6261 */
63- player.UIs ().getOpt< NotificationPlayerUi > (NotificationPlayerUi ::class .java)
64- .ifPresent( Consumer { obj : NotificationPlayerUi ? -> obj !! .createNotificationAndStartForeground() } )
62+ player.UIs ().get (NotificationPlayerUi ::class .java)
63+ ? .createNotificationAndStartForeground()
6564 }
6665
6766 override fun onStartCommand (intent : Intent , flags : Int , startId : Int ): Int {
@@ -85,11 +84,11 @@ class PlayerService : Service() {
8584 If the service is already started in foreground, requesting it to be started shouldn't
8685 do anything
8786 */
88- player.UIs ().getOpt <NotificationPlayerUi >(NotificationPlayerUi ::class .java)
89- .ifPresent( Consumer { obj : NotificationPlayerUi ? -> obj !! .createNotificationAndStartForeground() } )
87+ player.UIs ().get <NotificationPlayerUi >(NotificationPlayerUi ::class .java)
88+ ? .createNotificationAndStartForeground()
9089
91- if (Intent .ACTION_MEDIA_BUTTON == intent.getAction() &&
92- (player.getPlayQueue() == null )
90+ if (Intent .ACTION_MEDIA_BUTTON == intent.action &&
91+ (player.playQueue == null )
9392 ) {
9493 /*
9594 No need to process media button's actions if the player is not working, otherwise
@@ -102,14 +101,8 @@ class PlayerService : Service() {
102101 }
103102
104103 player.handleIntent(intent)
105- player.UIs ().getOpt<MediaSessionPlayerUi >(MediaSessionPlayerUi ::class .java)
106- .ifPresent(
107- Consumer { ui: MediaSessionPlayerUi ? ->
108- ui!! .handleMediaButtonIntent(
109- intent
110- )
111- }
112- )
104+ player.UIs ().get<MediaSessionPlayerUi >(MediaSessionPlayerUi ::class .java)
105+ ?.handleMediaButtonIntent(intent)
113106
114107 return START_NOT_STICKY
115108 }
@@ -162,11 +155,8 @@ class PlayerService : Service() {
162155 * back to our [org.schabi.newpipe.player.helper.PlayerHolder].
163156 */
164157 class LocalBinder internal constructor(playerService : PlayerService ? ) : Binder() {
165- private val playerService: WeakReference <PlayerService ?>
166-
167- init {
168- this .playerService = WeakReference <PlayerService ?>(playerService)
169- }
158+ private val playerService: WeakReference <PlayerService ?> =
159+ WeakReference <PlayerService ?>(playerService)
170160
171161 /* *
172162 * Get the PlayerService object itself.
0 commit comments