package de.christinecoenen.code.zapp.utils.video;

import android.view.View;

import com.google.android.exoplayer2.Player;

import java.lang.ref.WeakReference;

/**
 * Allows the screen to turn off as soon as video playback finishes
 * or pauses.
 */
class ScreenDimmingVideoEventListener implements Player.EventListener {

	private final WeakReference<View> viewToKeepScreenOn;

	ScreenDimmingVideoEventListener(View viewToKeepScreenOn) {
		this.viewToKeepScreenOn = new WeakReference<>(viewToKeepScreenOn);
	}

	@Override
	public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
		View view = viewToKeepScreenOn.get();

		if (view == null) {
			return;
		}

		if (playbackState == Player.STATE_IDLE || playbackState == Player.STATE_ENDED || !playWhenReady) {
			view.setKeepScreenOn(false);
		} else {
			// This prevents the screen from getting dim/lock
			view.setKeepScreenOn(true);
		}
	}
}

@@ -536,18 +536,20 @@
 d onPlay
-er
+back
 StateCha
@@ -557,31 +557,8 @@
 ged(
-boolean playWhenReady, 
 int 
@@ -736,26 +736,8 @@
 NDED
- %7C%7C !playWhenReady
 ) %7B%0A

Fix use of deprecated api