Skip to content

Commit 9c3fa3e

Browse files
Add Intent extension
1 parent de6dc54 commit 9c3fa3e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.schabi.newpipe.ktx
2+
3+
import android.content.Intent
4+
5+
// isEmpty unparcels the extras
6+
fun Intent.extrasString(): String = extras?.takeIf { !it.isEmpty }?.toString() ?: ""

app/src/main/java/org/schabi/newpipe/player/PlayerService.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
3939

40+
import org.schabi.newpipe.ktx.IntentKt;
4041
import org.schabi.newpipe.player.mediabrowser.MediaBrowserImpl;
4142
import org.schabi.newpipe.player.mediabrowser.MediaBrowserPlaybackPreparer;
4243
import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi;
@@ -125,11 +126,9 @@ public void onCreate() {
125126
@Override
126127
public int onStartCommand(final Intent intent, final int flags, final int startId) {
127128
if (DEBUG) {
128-
final var extras = intent.getExtras();
129-
// isEmpty unparcels the bundle
130-
final var extrasString = extras != null && !extras.isEmpty() ? extras.toString() : "";
131-
Log.d(TAG, "onStartCommand() called with: intent = [" + intent + "], extras = ["
132-
+ extrasString + "], flags = [" + flags + "], startId = [" + startId + "]");
129+
Log.d(TAG, "onStartCommand() called with: intent = [" + intent + "], "
130+
+ "extras = [" + IntentKt.extrasString(intent) + "], flags = [" + flags + "], "
131+
+ "startId = [" + startId + "]");
133132
}
134133

135134
// All internal NewPipe intents used to interact with the player, that are sent to the
@@ -270,11 +269,8 @@ protected void attachBaseContext(final Context base) {
270269
@Override
271270
public IBinder onBind(final Intent intent) {
272271
if (DEBUG) {
273-
final var extras = intent.getExtras();
274-
// isEmpty unparcels the bundle
275-
final var extrasString = extras != null && !extras.isEmpty() ? extras.toString() : "";
276-
Log.d(TAG, "onBind() called with: intent = [" + intent + "], extras = ["
277-
+ extrasString + "]");
272+
Log.d(TAG, "onBind() called with: intent = [" + intent + "], "
273+
+ "extras = [" + IntentKt.extrasString(intent) + "]");
278274
}
279275

280276
if (BIND_PLAYER_HOLDER_ACTION.equals(intent.getAction())) {

0 commit comments

Comments
 (0)