From cb78bce5c7abe10a8e749d10fe6b1880e261cbb3 Mon Sep 17 00:00:00 2001 From: Chenxia Liu Date: Tue, 23 Jan 2018 12:05:31 -0800 Subject: [PATCH] Closes #378 - Revert #295 "Rm youtube reload hack when opening menu." This reverts commit 9d5d45cf112e3a43079e8347cc67864e9571d362. --- .../java/org/mozilla/focus/activity/MainActivity.java | 11 +++++++++++ .../org/mozilla/focus/fragment/BrowserFragment.java | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/src/main/java/org/mozilla/focus/activity/MainActivity.java b/app/src/main/java/org/mozilla/focus/activity/MainActivity.java index d40bb8ca0a..fb459b66ab 100644 --- a/app/src/main/java/org/mozilla/focus/activity/MainActivity.java +++ b/app/src/main/java/org/mozilla/focus/activity/MainActivity.java @@ -109,6 +109,9 @@ public MainActivity() { sessionManager = SessionManager.getInstance(); } + // We need to respond to the onPageFinished event so we set a flag here. + public boolean isReloadingForYoutubeDrawerClosed = false; + private static boolean isAmazonFactoryInit = false; public static AmazonWebKitFactory factory = null; @@ -214,6 +217,14 @@ public void onDrawerOpened(final View drawerView) { public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); isDrawerOpen = false; + + // If you open and close the menu on youtube, dpad navigation stops working for an unknown reason. + // One workaround is to reload the page, which we do here. + final BrowserFragment browserFragment = (BrowserFragment) getSupportFragmentManager().findFragmentByTag(BrowserFragment.FRAGMENT_TAG); + if (browserFragment != null && browserFragment.isVisible() && browserFragment.getUrl().contains("youtube.com/tv")) { + browserFragment.reload(); + isReloadingForYoutubeDrawerClosed = true; + } } @Override diff --git a/app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.java b/app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.java index 7edf0f4ac4..43106d1a38 100644 --- a/app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.java +++ b/app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.java @@ -15,6 +15,7 @@ import android.support.annotation.Nullable; import android.support.v4.app.FragmentManager; import android.text.TextUtils; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -206,6 +207,15 @@ public void onValueChanged(@NonNull Boolean loading) { final MainActivity activity = (MainActivity)getActivity(); updateCursorState(); + if (!loading && activity.isReloadingForYoutubeDrawerClosed) { + activity.isReloadingForYoutubeDrawerClosed = false; + + // We send a play event which: + // - If we're on the video selection page, does nothing. + // - If we're in a fullscreen video, will show the play/pause controls on the screen so + // we don't just see a black screen. + activity.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); + } } });