From 90f35ed0094d4413c9bf1cb8842eeebd73146f80 Mon Sep 17 00:00:00 2001 From: mcc Date: Sun, 10 Dec 2023 13:56:02 -0500 Subject: [PATCH 1/2] Media3/exoplayer introduced a regression where the device can sleep while video/audio are playing. Patch restores v23 behavior --- .../main/java/com/keylesspalace/tusky/ViewMediaActivity.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt index 88b330c84c..a414ac994e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt @@ -35,6 +35,7 @@ import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.View +import android.view.WindowManager import android.webkit.MimeTypeMap import android.widget.Toast import androidx.core.app.ShareCompat @@ -155,6 +156,10 @@ class ViewMediaActivity : BaseActivity(), HasAndroidInjector, ViewImageFragment. window.sharedElementEnterTransition.removeListener(this) } }) + + // Prevent this activity from dimming or sleeping the screen if it is playing video or audio + if (attachments!![binding.viewPager.currentItem].attachment.type != Attachment.Type.IMAGE) + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } override fun onCreateOptionsMenu(menu: Menu): Boolean { From b9a593d6b0418501c908d5d7fa84c18e2aecdff9 Mon Sep 17 00:00:00 2001 From: mcc Date: Sun, 10 Dec 2023 18:13:46 -0500 Subject: [PATCH 2/2] ktLint fix --- app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt index a414ac994e..f0943264c9 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt @@ -158,8 +158,9 @@ class ViewMediaActivity : BaseActivity(), HasAndroidInjector, ViewImageFragment. }) // Prevent this activity from dimming or sleeping the screen if it is playing video or audio - if (attachments!![binding.viewPager.currentItem].attachment.type != Attachment.Type.IMAGE) + if (attachments!![binding.viewPager.currentItem].attachment.type != Attachment.Type.IMAGE) { window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } } override fun onCreateOptionsMenu(menu: Menu): Boolean {