1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-09-30 07:50:50 +00:00

-Replace main player dropdown menu with expand/collapse custom UI.

This commit is contained in:
John Zhen Mo 2018-02-06 15:07:49 -08:00
parent 5773152ed3
commit 6485327b97
2 changed files with 114 additions and 57 deletions

View File

@ -61,7 +61,6 @@ import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.ListHelper; import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper; import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.PopupMenuIconHacker;
import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.util.ThemeHelper;
import java.util.List; import java.util.List;
@ -194,7 +193,6 @@ public final class MainVideoPlayer extends Activity {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
if (playerImpl.isSomePopupMenuVisible()) { if (playerImpl.isSomePopupMenuVisible()) {
playerImpl.moreOptionsPopupMenu.dismiss();
playerImpl.getQualityPopupMenu().dismiss(); playerImpl.getQualityPopupMenu().dismiss();
playerImpl.getPlaybackSpeedPopupMenu().dismiss(); playerImpl.getPlaybackSpeedPopupMenu().dismiss();
} }
@ -301,8 +299,11 @@ public final class MainVideoPlayer extends Activity {
private boolean queueVisible; private boolean queueVisible;
private ImageButton moreOptionsButton; private ImageButton moreOptionsButton;
public int moreOptionsPopupMenuGroupId = 89; private ImageButton toggleOrientationButton;
public PopupMenu moreOptionsPopupMenu; private ImageButton switchPopupButton;
private ImageButton switchBackgroundButton;
private View secondaryControls;
VideoPlayerImpl(final Context context) { VideoPlayerImpl(final Context context) {
super("VideoPlayerImpl" + MainVideoPlayer.TAG, context); super("VideoPlayerImpl" + MainVideoPlayer.TAG, context);
@ -322,9 +323,12 @@ public final class MainVideoPlayer extends Activity {
this.playPauseButton = rootView.findViewById(R.id.playPauseButton); this.playPauseButton = rootView.findViewById(R.id.playPauseButton);
this.playPreviousButton = rootView.findViewById(R.id.playPreviousButton); this.playPreviousButton = rootView.findViewById(R.id.playPreviousButton);
this.playNextButton = rootView.findViewById(R.id.playNextButton); this.playNextButton = rootView.findViewById(R.id.playNextButton);
this.moreOptionsButton = rootView.findViewById(R.id.moreOptionsButton); this.moreOptionsButton = rootView.findViewById(R.id.moreOptionsButton);
this.moreOptionsPopupMenu = new PopupMenu(context, moreOptionsButton); this.secondaryControls = rootView.findViewById(R.id.secondaryControls);
buildMoreOptionsMenu(); this.toggleOrientationButton = rootView.findViewById(R.id.toggleOrientation);
this.switchBackgroundButton = rootView.findViewById(R.id.switchBackground);
this.switchPopupButton = rootView.findViewById(R.id.switchPopup);
titleTextView.setSelected(true); titleTextView.setSelected(true);
channelTextView.setSelected(true); channelTextView.setSelected(true);
@ -348,7 +352,11 @@ public final class MainVideoPlayer extends Activity {
playPauseButton.setOnClickListener(this); playPauseButton.setOnClickListener(this);
playPreviousButton.setOnClickListener(this); playPreviousButton.setOnClickListener(this);
playNextButton.setOnClickListener(this); playNextButton.setOnClickListener(this);
moreOptionsButton.setOnClickListener(this); moreOptionsButton.setOnClickListener(this);
toggleOrientationButton.setOnClickListener(this);
switchBackgroundButton.setOnClickListener(this);
switchPopupButton.setOnClickListener(this);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -464,6 +472,16 @@ public final class MainVideoPlayer extends Activity {
return; return;
} else if (v.getId() == moreOptionsButton.getId()) { } else if (v.getId() == moreOptionsButton.getId()) {
onMoreOptionsClicked(); onMoreOptionsClicked();
} else if (v.getId() == toggleOrientationButton.getId()) {
onScreenRotationClicked();
} else if (v.getId() == switchPopupButton.getId()) {
onFullScreenButtonClicked();
} else if (v.getId() == switchBackgroundButton.getId()) {
onPlayBackgroundButtonClicked();
} }
if (getCurrentState() != STATE_COMPLETED) { if (getCurrentState() != STATE_COMPLETED) {
@ -497,8 +515,15 @@ public final class MainVideoPlayer extends Activity {
private void onMoreOptionsClicked() { private void onMoreOptionsClicked() {
if (DEBUG) Log.d(TAG, "onMoreOptionsClicked() called"); if (DEBUG) Log.d(TAG, "onMoreOptionsClicked() called");
moreOptionsPopupMenu.show(); if (secondaryControls.getVisibility() == View.VISIBLE) {
isSomePopupMenuVisible = true; moreOptionsButton.setImageDrawable(getResources().getDrawable(
R.drawable.ic_expand_more_white_24dp));
animateView(secondaryControls, false, 200);
} else {
moreOptionsButton.setImageDrawable(getResources().getDrawable(
R.drawable.ic_expand_less_white_24dp));
animateView(secondaryControls, true, 200);
}
showControls(300); showControls(300);
} }
@ -637,42 +662,6 @@ public final class MainVideoPlayer extends Activity {
setShuffleButton(shuffleButton, playQueue.isShuffled()); setShuffleButton(shuffleButton, playQueue.isShuffled());
} }
private void buildMoreOptionsMenu() {
this.moreOptionsPopupMenu.getMenuInflater().inflate(R.menu.menu_videooptions,
moreOptionsPopupMenu.getMenu());
moreOptionsPopupMenu.setOnMenuItemClickListener(menuItem -> {
switch (menuItem.getItemId()) {
case R.id.toggleOrientation:
onScreenRotationClicked();
break;
case R.id.switchPopup:
onFullScreenButtonClicked();
break;
case R.id.switchBackground:
onPlayBackgroundButtonClicked();
break;
}
return false;
});
try {
PopupMenuIconHacker.setShowPopupIcon(moreOptionsPopupMenu);
} catch (Exception e) {
e.printStackTrace();
}
// fix icon theme
if(ThemeHelper.isLightThemeSelected(MainVideoPlayer.this)) {
moreOptionsPopupMenu.getMenu()
.findItem(R.id.toggleOrientation)
.setIcon(R.drawable.ic_screen_rotation_black_24dp);
moreOptionsPopupMenu.getMenu()
.findItem(R.id.switchPopup)
.setIcon(R.drawable.ic_fullscreen_exit_black_24dp);
}
}
private void buildQueue() { private void buildQueue() {
queueLayout = findViewById(R.id.playQueuePanel); queueLayout = findViewById(R.id.playQueuePanel);

View File

@ -145,10 +145,10 @@
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:background="@drawable/player_top_controls_bg" android:background="@drawable/player_top_controls_bg"
android:gravity="top" android:gravity="top"
android:paddingBottom="70dp"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<LinearLayout <LinearLayout
@ -209,6 +209,7 @@
android:text="720p" android:text="720p"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textStyle="bold" android:textStyle="bold"
android:background="?attr/selectableItemBackground"
tools:ignore="HardcodedText,RtlHardcoded"/> tools:ignore="HardcodedText,RtlHardcoded"/>
<TextView <TextView
@ -222,6 +223,7 @@
android:minWidth="40dp" android:minWidth="40dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textStyle="bold" android:textStyle="bold"
android:background="?attr/selectableItemBackground"
tools:ignore="RtlHardcoded,RtlSymmetry" tools:ignore="RtlHardcoded,RtlSymmetry"
tools:text="1x" /> tools:text="1x" />
@ -232,12 +234,12 @@
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:layout_toLeftOf="@+id/moreOptionsButton" android:layout_toLeftOf="@+id/moreOptionsButton"
android:background="#00ffffff"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:padding="5dp" android:padding="5dp"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/list" android:src="@drawable/list"
android:background="?attr/selectableItemBackground"
tools:ignore="ContentDescription,RtlHardcoded"/> tools:ignore="ContentDescription,RtlHardcoded"/>
<ImageButton <ImageButton
@ -247,12 +249,25 @@
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:padding="5dp" android:padding="5dp"
android:background="#00ffffff"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/ic_more_vert_white_24dp" android:src="@drawable/ic_expand_more_white_24dp"
android:background="?attr/selectableItemBackground"
tools:ignore="ContentDescription,RtlHardcoded"/> tools:ignore="ContentDescription,RtlHardcoded"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/secondaryControls"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/topControls"
android:gravity="top"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:visibility="gone"
tools:ignore="RtlHardcoded"
tools:visibility="visible">
<TextView <TextView
android:id="@+id/resizeTextView" android:id="@+id/resizeTextView"
@ -260,22 +275,21 @@
android:layout_height="35dp" android:layout_height="35dp"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:layout_below="@id/metadataView"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:gravity="center" android:gravity="center"
android:minWidth="50dp" android:minWidth="50dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textStyle="bold" android:textStyle="bold"
android:background="?attr/selectableItemBackground"
tools:ignore="HardcodedText,RtlHardcoded" tools:ignore="HardcodedText,RtlHardcoded"
tools:text="FIT"/> tools:text="FIT"/>
<TextView <TextView
android:id="@+id/captionTextView" android:id="@+id/captionTextView"
android:layout_width="wrap_content" android:layout_width="80dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="8dp" android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:layout_below="@id/metadataView"
android:layout_toRightOf="@id/resizeTextView" android:layout_toRightOf="@id/resizeTextView"
android:gravity="center" android:gravity="center"
android:minHeight="35dp" android:minHeight="35dp"
@ -284,8 +298,59 @@
android:paddingRight="2dp" android:paddingRight="2dp"
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textStyle="bold" android:textStyle="bold"
tools:ignore="RtlHardcoded,RtlSymmetry" android:background="?attr/selectableItemBackground"
tools:ignore="RtlHardcoded"
tools:text="English" /> tools:text="English" />
<ImageButton
android:id="@+id/toggleOrientation"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="true"
android:focusable="true"
android:padding="5dp"
android:scaleType="fitXY"
android:src="@drawable/ic_screen_rotation_white"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/toggle_orientation"
tools:ignore="RtlHardcoded"/>
<ImageButton
android:id="@+id/switchPopup"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="@id/toggleOrientation"
android:layout_centerVertical="true"
android:clickable="true"
android:focusable="true"
android:scaleType="fitXY"
android:src="@drawable/ic_fullscreen_exit_white"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/switch_to_popup"
tools:ignore="RtlHardcoded"/>
<ImageButton
android:id="@+id/switchBackground"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_toLeftOf="@id/switchPopup"
android:layout_centerVertical="true"
android:clickable="true"
android:focusable="true"
android:padding="5dp"
android:scaleType="fitXY"
android:src="@drawable/ic_headset_white_24dp"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/switch_to_background"
tools:ignore="RtlHardcoded"/>
</RelativeLayout> </RelativeLayout>
<LinearLayout <LinearLayout
@ -417,7 +482,10 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_toEndOf="@+id/loading_panel"
android:layout_toRightOf="@+id/loading_panel"
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<TextView <TextView
@ -437,7 +505,7 @@
android:visibility="gone" android:visibility="gone"
tools:ignore="RtlHardcoded" tools:ignore="RtlHardcoded"
tools:text="Volume 0" tools:text="Volume 0"
tools:visibility="visible"/> tools:visibility="visible" />
<TextView <TextView
android:id="@+id/brightnessTextView" android:id="@+id/brightnessTextView"
@ -456,7 +524,7 @@
android:visibility="gone" android:visibility="gone"
tools:ignore="RtlHardcoded" tools:ignore="RtlHardcoded"
tools:text="Brightness 0" tools:text="Brightness 0"
tools:visibility="visible"/> tools:visibility="visible" />
<TextView <TextView
android:id="@+id/currentDisplaySeek" android:id="@+id/currentDisplaySeek"
@ -475,7 +543,7 @@
android:visibility="gone" android:visibility="gone"
tools:ignore="RtlHardcoded" tools:ignore="RtlHardcoded"
tools:text="1:06:29" tools:text="1:06:29"
tools:visibility="visible"/> tools:visibility="visible" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>