Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit f889ece

Browse files
MortimerGorobluemarvin
authored andcommitted
Correctly update media control selected projection when entering a immersive video (#2345)
1 parent 4254845 commit f889ece

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/menus/VideoProjectionMenuWidget.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.ArrayList;
1414
import java.util.concurrent.atomic.AtomicBoolean;
15+
import java.util.stream.IntStream;
1516

1617
public class VideoProjectionMenuWidget extends MenuWidget {
1718

@@ -31,6 +32,14 @@ public interface Delegate {
3132
void onVideoProjectionClick(@VideoProjectionFlags int aProjection);
3233
}
3334

35+
class ProjectionMenuItem extends MenuItem {
36+
@VideoProjectionFlags int projection;
37+
public ProjectionMenuItem(@VideoProjectionFlags int aProjection, String aString, int aImage) {
38+
super(aString, aImage, () -> handleClick(aProjection));
39+
projection = aProjection;
40+
}
41+
}
42+
3443
ArrayList<MenuItem> mItems;
3544
Delegate mDelegate;
3645
@VideoProjectionFlags int mSelectedProjection = VIDEO_PROJECTION_3D_SIDE_BY_SIDE;
@@ -63,23 +72,23 @@ public void setDelegate(@Nullable Delegate aDelegate) {
6372
private void createMenuItems() {
6473
mItems = new ArrayList<>();
6574

66-
mItems.add(new MenuItem(getContext().getString(R.string.video_mode_3d_side),
67-
R.drawable.ic_icon_videoplayback_3dsidebyside, () -> handleClick(VIDEO_PROJECTION_3D_SIDE_BY_SIDE)));
75+
mItems.add(new ProjectionMenuItem(VIDEO_PROJECTION_3D_SIDE_BY_SIDE, getContext().getString(R.string.video_mode_3d_side),
76+
R.drawable.ic_icon_videoplayback_3dsidebyside));
6877

69-
mItems.add(new MenuItem(getContext().getString(R.string.video_mode_360),
70-
R.drawable.ic_icon_videoplayback_360, () -> handleClick(VIDEO_PROJECTION_360)));
78+
mItems.add(new ProjectionMenuItem(VIDEO_PROJECTION_360, getContext().getString(R.string.video_mode_360),
79+
R.drawable.ic_icon_videoplayback_360));
7180

72-
mItems.add(new MenuItem(getContext().getString(R.string.video_mode_360_stereo),
73-
R.drawable.ic_icon_videoplayback_360_stereo, () -> handleClick(VIDEO_PROJECTION_360_STEREO)));
81+
mItems.add(new ProjectionMenuItem(VIDEO_PROJECTION_360_STEREO, getContext().getString(R.string.video_mode_360_stereo),
82+
R.drawable.ic_icon_videoplayback_360_stereo));
7483

75-
mItems.add(new MenuItem(getContext().getString(R.string.video_mode_180),
76-
R.drawable.ic_icon_videoplayback_180, () -> handleClick(VIDEO_PROJECTION_180)));
84+
mItems.add(new ProjectionMenuItem(VIDEO_PROJECTION_180, getContext().getString(R.string.video_mode_180),
85+
R.drawable.ic_icon_videoplayback_180));
7786

78-
mItems.add(new MenuItem(getContext().getString(R.string.video_mode_180_left_right),
79-
R.drawable.ic_icon_videoplayback_180_stereo_leftright, () -> handleClick(VIDEO_PROJECTION_180_STEREO_LEFT_RIGHT)));
87+
mItems.add(new ProjectionMenuItem(VIDEO_PROJECTION_180_STEREO_LEFT_RIGHT, getContext().getString(R.string.video_mode_180_left_right),
88+
R.drawable.ic_icon_videoplayback_180_stereo_leftright));
8089

81-
mItems.add(new MenuItem(getContext().getString(R.string.video_mode_180_top_bottom),
82-
R.drawable.ic_icon_videoplayback_180_stereo_topbottom, () -> handleClick(VIDEO_PROJECTION_180_STEREO_TOP_BOTTOM)));
90+
mItems.add(new ProjectionMenuItem(VIDEO_PROJECTION_180_STEREO_TOP_BOTTOM, getContext().getString(R.string.video_mode_180_top_bottom),
91+
R.drawable.ic_icon_videoplayback_180_stereo_topbottom));
8392

8493

8594
super.updateMenuItems(mItems);
@@ -101,6 +110,10 @@ private void handleClick(@VideoProjectionFlags int aVideoProjection) {
101110

102111
public void setSelectedProjection(@VideoProjectionFlags int aProjection) {
103112
mSelectedProjection = aProjection;
113+
IntStream.range(0, mItems.size())
114+
.filter(i -> ((ProjectionMenuItem)mItems.get(i)).projection == aProjection)
115+
.findFirst()
116+
.ifPresent(this::setSelectedItem);
104117
}
105118

106119
public static @VideoProjectionFlags Integer getAutomaticProjection(String aURL, AtomicBoolean autoEnter) {

0 commit comments

Comments
 (0)