Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56d3de5a authored by Albert Tang's avatar Albert Tang Committed by Georg Veichtlbauer
Browse files

Eleven: Add shuffle button for Android Auto

Change-Id: Ic363d2241ab9db5f3774537dc95583cd12f9f8fc
parent 6b4329c5
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -834,6 +834,13 @@ public class MusicPlaybackService extends MediaBrowserService
                open(mSongs.stream().mapToLong(i -> i).toArray(), position, -1, IdType.NA);
                onPlay();
            }

            @Override
            public void onCustomAction(@NonNull String action, @Nullable Bundle extras) {
                if (action.equals(SHUFFLE_ACTION)) {
                    cycleShuffle();
                }
            }
        });

        PendingIntent pi = PendingIntent.getBroadcast(this, 0,
@@ -1631,11 +1638,19 @@ public class MusicPlaybackService extends MediaBrowserService
                PlaybackState.ACTION_SKIP_TO_PREVIOUS |
                PlaybackState.ACTION_STOP;

        if (what.equals(PLAYSTATE_CHANGED) || what.equals(POSITION_CHANGED)) {
            mSession.setPlaybackState(new PlaybackState.Builder()
        PlaybackState.Builder stateBuilder = new PlaybackState.Builder()
                .setActions(playBackStateActions)
                .setActiveQueueItemId(getAudioId())
                    .setState(playState, position(), 1.0f).build());
                .setState(playState, position(), 1.0f);

        // create custom action
        stateBuilder.addCustomAction(new PlaybackState.CustomAction.Builder(
                SHUFFLE_ACTION,
                getString(R.string.menu_shuffle_item),
                R.drawable.btn_playback_shuffle_all).build());

        if (what.equals(PLAYSTATE_CHANGED) || what.equals(POSITION_CHANGED)) {
            mSession.setPlaybackState(stateBuilder.build());
        } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)
                || QUEUE_MOVED.equals(what)) {
            Bitmap albumArt = getAlbumArt(false).getBitmap();
@@ -1665,10 +1680,7 @@ public class MusicPlaybackService extends MediaBrowserService
                updateMediaSessionQueue();
            }

            mSession.setPlaybackState(new PlaybackState.Builder()
                    .setActions(playBackStateActions)
                    .setActiveQueueItemId(getAudioId())
                    .setState(playState, position(), 1.0f).build());
            mSession.setPlaybackState(stateBuilder.build());
        }
    }