From b2c2998c5706937cf759b8cff3fb3608a36352c5 Mon Sep 17 00:00:00 2001 From: Chenxia Liu Date: Tue, 12 Mar 2019 16:53:58 -0700 Subject: [PATCH] Issue #1865 - Move workaround to separate file. --- .../tv/firefox/webrender/WebRenderFragment.kt | 11 +------ .../webrender/YoutubeGreyScreenWorkaround.kt | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/org/mozilla/tv/firefox/webrender/YoutubeGreyScreenWorkaround.kt diff --git a/app/src/main/java/org/mozilla/tv/firefox/webrender/WebRenderFragment.kt b/app/src/main/java/org/mozilla/tv/firefox/webrender/WebRenderFragment.kt index 5d64a761a1..9e85f302bc 100644 --- a/app/src/main/java/org/mozilla/tv/firefox/webrender/WebRenderFragment.kt +++ b/app/src/main/java/org/mozilla/tv/firefox/webrender/WebRenderFragment.kt @@ -16,10 +16,6 @@ import android.view.View import android.view.ViewGroup import android.view.WindowManager import kotlinx.android.synthetic.main.fragment_browser.view.* -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import mozilla.components.browser.session.Session import mozilla.components.concept.engine.EngineView import mozilla.components.concept.engine.permission.Permission @@ -84,12 +80,7 @@ class WebRenderFragment : EngineViewLifecycleFragment(), Session.Observer { override fun onResume() { super.onResume() if (session.isYoutubeTV) { - // Send key events on the UI thread to clear webview grey screen, see #1865 - GlobalScope.launch(Dispatchers.Main) { - delay(50) - activity?.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT)) - activity?.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT)) - } + YoutubeGreyScreenWorkaround.invoke(activity) } } diff --git a/app/src/main/java/org/mozilla/tv/firefox/webrender/YoutubeGreyScreenWorkaround.kt b/app/src/main/java/org/mozilla/tv/firefox/webrender/YoutubeGreyScreenWorkaround.kt new file mode 100644 index 0000000000..de2eb601ea --- /dev/null +++ b/app/src/main/java/org/mozilla/tv/firefox/webrender/YoutubeGreyScreenWorkaround.kt @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.tv.firefox.webrender + +import android.app.Activity +import android.view.KeyEvent +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch + +/** + * Workaround fix for intermittent grey screen that shows instead of WebView when returning to + * YouTube from the home screen, see #1865. Follow-up investigation in #1940. + * + * This fix sends navigation key events on the UI thread to dispel the grey screen. + * + * Other failed attempted workarounds: + * - Calling engineView.resume to trigger the webview to "load" from grey screen + * - Scrolling webview + * - Sending non-view-changing key events + */ +object YoutubeGreyScreenWorkaround { + fun invoke(activity: Activity?) { + GlobalScope.launch(Dispatchers.Main) { + delay(50) + activity?.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT)) + activity?.dispatchKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT)) + } + } +}