Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Closes #378 - Revert #295 "Rm youtube reload hack when opening menu."
Browse files Browse the repository at this point in the history
This reverts commit 9d5d45c.
  • Loading branch information
liuche authored and mcomella committed Jan 24, 2018
1 parent 7025792 commit cb78bce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/org/mozilla/focus/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
});

Expand Down

0 comments on commit cb78bce

Please sign in to comment.