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

Commit d596ba73 authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: fix visualizer tile initial state



If something was playing intially and the tile detected so via the cold
check, it would be eventually overridden by the checkIfPlaying() method
because it always assumed the initial state to be false, which is not
always so.

Change-Id: I32c0c358be1e9e64c7185ae5012f28bc1279cbf8
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 165174e0
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public class VisualizerTile extends QSTile<QSTile.State>
            if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGING.equals(intent.getAction())) {
                mPowerSaveModeEnabled = intent.getBooleanExtra(PowerManager.EXTRA_POWER_SAVE_MODE,
                        false);
                checkIfPlaying();
                checkIfPlaying(null);
            }
        }
    };
@@ -216,9 +216,11 @@ public class VisualizerTile extends QSTile<QSTile.State>
        mContext.unregisterReceiver(mReceiver);
    }

    private void checkIfPlaying() {
        boolean anythingPlaying = false;
        if (!mPowerSaveModeEnabled) {
    private void checkIfPlaying(PlaybackState newState) {
        boolean anythingPlaying = newState == null
                ? mIsAnythingPlaying
                : newState.getState() == PlaybackState.STATE_PLAYING;
        if (!mPowerSaveModeEnabled && !anythingPlaying) {
            for (Map.Entry<MediaSession.Token, CallbackInfo> entry : mCallbacks.entrySet()) {
                if (entry.getValue().isPlaying()) {
                    anythingPlaying = true;
@@ -226,6 +228,7 @@ public class VisualizerTile extends QSTile<QSTile.State>
                }
            }
        }

        if (anythingPlaying != mIsAnythingPlaying) {
            mIsAnythingPlaying = anythingPlaying;
            doLinkage();
@@ -317,13 +320,13 @@ public class VisualizerTile extends QSTile<QSTile.State>
                @Override
                public void onSessionDestroyed() {
                    destroy();
                    checkIfPlaying();
                    checkIfPlaying(null);
                }

                @Override
                public void onPlaybackStateChanged(@NonNull PlaybackState state) {
                    mIsPlaying = state.getState() == PlaybackState.STATE_PLAYING;
                    checkIfPlaying();
                    checkIfPlaying(state);
                }
            };
            controller.registerCallback(mCallback);