Skip to content

Commit

Permalink
Add a secondary control panel to video detail fragment
Browse files Browse the repository at this point in the history
It is shown when the user expands the description
It contains share, open in browser and play in kodi
  • Loading branch information
Stypox committed Oct 16, 2020
1 parent 6c49209 commit 825a07e
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.database.ContentObserver;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -97,6 +98,7 @@
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.KoreUtil;
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
Expand Down Expand Up @@ -208,6 +210,10 @@ public class VideoDetailFragment
private TextView detailControlsPopup;
private TextView detailControlsAddToPlaylist;
private TextView detailControlsDownload;
private TextView detailControlsShare;
private TextView detailControlsOpenInBrowser;
private TextView detailControlsPlayWithKodi;
private View detailSecondaryControlPanel;
private TextView appendControlsDetail;
private TextView detailDurationView;
private TextView detailPositionView;
Expand Down Expand Up @@ -244,7 +250,9 @@ public class VideoDetailFragment
private FrameLayout relatedStreamsLayout;

private ContentObserver settingsContentObserver;
@Nullable
private MainPlayer playerService;
@Nullable
private VideoPlayerImpl player;


Expand Down Expand Up @@ -492,6 +500,30 @@ public void onClick(final View v) {
this.openDownloadDialog();
}
break;
case R.id.detail_controls_share:
if (currentInfo != null) {
ShareUtils.shareUrl(requireContext(),
currentInfo.getName(), currentInfo.getUrl());
}
break;
case R.id.detail_controls_open_in_browser:
if (currentInfo != null) {
ShareUtils.openUrlInBrowser(requireContext(), currentInfo.getUrl());
}
break;
case R.id.detail_controls_play_with_kodi:
if (currentInfo != null) {
try {
NavigationHelper.playWithKore(
requireContext(), Uri.parse(currentInfo.getUrl()));
} catch (final Exception e) {
if (DEBUG) {
Log.i(TAG, "Failed to start kore", e);
}
KoreUtil.showInstallKoreDialog(requireContext());
}
}
break;
case R.id.detail_uploader_root_layout:
if (TextUtils.isEmpty(currentInfo.getSubChannelUrl())) {
if (!TextUtils.isEmpty(currentInfo.getUploaderUrl())) {
Expand Down Expand Up @@ -589,13 +621,15 @@ private void toggleTitleAndDescription() {
videoDescriptionView.setFocusable(false);
videoTitleToggleArrow.setImageResource(
ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_expand_more));
detailSecondaryControlPanel.setVisibility(View.GONE);
} else {
videoTitleTextView.setMaxLines(10);
videoDescriptionRootLayout.setVisibility(View.VISIBLE);
videoDescriptionView.setFocusable(true);
videoDescriptionView.setMovementMethod(new LargeTextMovementMethod());
videoTitleToggleArrow.setImageResource(
ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_expand_less));
detailSecondaryControlPanel.setVisibility(View.VISIBLE);
}
}

Expand Down Expand Up @@ -623,6 +657,10 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
detailControlsPopup = rootView.findViewById(R.id.detail_controls_popup);
detailControlsAddToPlaylist = rootView.findViewById(R.id.detail_controls_playlist_append);
detailControlsDownload = rootView.findViewById(R.id.detail_controls_download);
detailControlsShare = rootView.findViewById(R.id.detail_controls_share);
detailControlsOpenInBrowser = rootView.findViewById(R.id.detail_controls_open_in_browser);
detailControlsPlayWithKodi = rootView.findViewById(R.id.detail_controls_play_with_kodi);
detailSecondaryControlPanel = rootView.findViewById(R.id.detail_secondary_control_panel);
appendControlsDetail = rootView.findViewById(R.id.touch_append_detail);
detailDurationView = rootView.findViewById(R.id.detail_duration_view);
detailPositionView = rootView.findViewById(R.id.detail_position_view);
Expand Down Expand Up @@ -670,6 +708,9 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
detailControlsBackground.setBackgroundColor(transparent);
detailControlsPopup.setBackgroundColor(transparent);
detailControlsDownload.setBackgroundColor(transparent);
detailControlsShare.setBackgroundColor(transparent);
detailControlsOpenInBrowser.setBackgroundColor(transparent);
detailControlsPlayWithKodi.setBackgroundColor(transparent);
}

}
Expand All @@ -683,16 +724,18 @@ protected void initListeners() {
uploaderRootLayout.setOnLongClickListener(this);
videoTitleRoot.setOnClickListener(this);
thumbnailBackgroundButton.setOnClickListener(this);

detailControlsBackground.setOnClickListener(this);
detailControlsBackground.setOnLongClickListener(this);
detailControlsPopup.setOnClickListener(this);
detailControlsPopup.setOnLongClickListener(this);
detailControlsAddToPlaylist.setOnClickListener(this);
detailControlsDownload.setOnClickListener(this);
detailControlsDownload.setOnLongClickListener(this);

detailControlsBackground.setLongClickable(true);
detailControlsPopup.setLongClickable(true);
detailControlsBackground.setOnLongClickListener(this);
detailControlsPopup.setOnLongClickListener(this);
detailControlsShare.setOnClickListener(this);
detailControlsOpenInBrowser.setOnClickListener(this);
detailControlsPlayWithKodi.setOnClickListener(this);
showHideKodiButton();

overlayThumbnailImageView.setOnClickListener(this);
overlayThumbnailImageView.setOnLongClickListener(this);
Expand Down Expand Up @@ -757,6 +800,14 @@ public void onLoadingFailed(final String imageUri, final View view,
}
}

private void showHideKodiButton() {
// show kodi button if it supports the current service and it is enabled in settings
final boolean showKodiButton = KoreUtil.isServiceSupportedByKore(serviceId)
&& PreferenceManager.getDefaultSharedPreferences(requireContext())
.getBoolean(getString(R.string.show_play_with_kodi_key), false);
detailControlsPlayWithKodi.setVisibility(showKodiButton ? View.VISIBLE : View.GONE);
}

/*//////////////////////////////////////////////////////////////////////////
// OwnStack
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -1400,6 +1451,7 @@ public void showLoading() {
videoDescriptionRootLayout.setVisibility(View.GONE);
videoTitleToggleArrow.setVisibility(View.GONE);
videoTitleRoot.setClickable(false);
detailSecondaryControlPanel.setVisibility(View.GONE);

if (relatedStreamsLayout != null) {
if (showRelatedStreams) {
Expand Down Expand Up @@ -1517,6 +1569,7 @@ public void handleResult(@NonNull final StreamInfo info) {
ThemeHelper.resolveResourceIdFromAttr(requireContext(), R.attr.ic_expand_more));
videoTitleToggleArrow.setVisibility(View.VISIBLE);
videoDescriptionRootLayout.setVisibility(View.GONE);
detailSecondaryControlPanel.setVisibility(View.GONE);

if (info.getUploadDate() != null) {
videoUploadDateView.setText(Localization
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -946,15 +946,13 @@ private void onOpenInBrowserClicked() {
}

private void showHideKodiButton() {
final boolean kodiEnabled = defaultPreferences.getBoolean(
service.getString(R.string.show_play_with_kodi_key), false);
// show kodi button if it supports the current service and it is enabled in settings
final boolean showKodiButton = playQueue != null && playQueue.getItem() != null
final boolean showKodiButton = videoPlayerSelected()
&& playQueue != null && playQueue.getItem() != null
&& KoreUtil.isServiceSupportedByKore(playQueue.getItem().getServiceId())
&& PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.show_play_with_kodi_key), false);
playWithKodi.setVisibility(videoPlayerSelected() && kodiEnabled && showKodiButton
? View.VISIBLE : View.GONE);
&& defaultPreferences.getBoolean(
context.getString(R.string.show_play_with_kodi_key), false);
playWithKodi.setVisibility(showKodiButton ? View.VISIBLE : View.GONE);
}

private void setupScreenRotationButton() {
Expand Down
102 changes: 80 additions & 22 deletions app/src/main/res/layout-large-land/fragment_video_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,86 +426,144 @@
</RelativeLayout>
</RelativeLayout>

<!-- CONTROLS -->
<LinearLayout
android:id="@+id/detail_control_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusable="true"
android:orientation="horizontal"
android:padding="6dp">
android:padding="@dimen/detail_control_padding">

<!-- CONTROLS -->
<TextView
android:id="@+id/detail_controls_playlist_append"
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_width="@dimen/detail_control_width"
android:layout_height="@dimen/detail_control_height"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/append_playlist"
android:focusable="true"
android:gravity="center"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingVertical="@dimen/detail_control_padding"
android:text="@string/controls_add_to_playlist_title"
android:textSize="12sp"
android:textSize="@dimen/detail_control_text_size"
app:drawableTopCompat="?attr/ic_playlist_add" />

<TextView
android:id="@+id/detail_controls_background"
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_width="@dimen/detail_control_width"
android:layout_height="@dimen/detail_control_height"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/play_audio"
android:focusable="true"
android:gravity="center"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingVertical="@dimen/detail_control_padding"
android:text="@string/controls_background_title"
android:textSize="12sp"
android:textSize="@dimen/detail_control_text_size"
app:drawableTopCompat="?attr/ic_headset" />

<TextView
android:id="@+id/detail_controls_popup"
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_width="@dimen/detail_control_width"
android:layout_height="@dimen/detail_control_height"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/open_in_popup_mode"
android:focusable="true"
android:gravity="center"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingVertical="@dimen/detail_control_padding"
android:text="@string/controls_popup_title"
android:textSize="12sp"
android:textSize="@dimen/detail_control_text_size"
app:drawableTopCompat="?attr/ic_popup" />

<TextView
android:id="@+id/detail_controls_download"
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_width="@dimen/detail_control_width"
android:layout_height="@dimen/detail_control_height"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/controls_download_desc"
android:focusable="true"
android:gravity="center"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingVertical="@dimen/detail_control_padding"
android:text="@string/download"
android:textSize="12sp"
android:textSize="@dimen/detail_control_text_size"
app:drawableTopCompat="?attr/ic_file_download" />

</LinearLayout>

<!-- SECONDARY CONTROLS -->
<LinearLayout
android:id="@+id/detail_secondary_control_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"
android:focusable="true"
android:orientation="horizontal"
android:padding="@dimen/detail_control_padding"
android:visibility="gone"
tools:visibility="visible">

<TextView
android:id="@+id/detail_controls_share"
android:layout_width="@dimen/detail_control_width"
android:layout_height="@dimen/detail_control_height"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/share"
android:focusable="true"
android:gravity="center"
android:paddingVertical="@dimen/detail_control_padding"
android:text="@string/share"
android:textSize="@dimen/detail_control_text_size"
app:drawableTopCompat="?attr/ic_share" />

<TextView
android:id="@+id/detail_controls_open_in_browser"
android:layout_width="@dimen/detail_control_width"
android:layout_height="@dimen/detail_control_height"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/open_in_browser"
android:focusable="true"
android:gravity="center"
android:paddingVertical="@dimen/detail_control_padding"
android:text="@string/open_in_browser"
android:textSize="@dimen/detail_control_text_size"
app:drawableTopCompat="?attr/ic_language" />

<TextView
android:id="@+id/detail_controls_play_with_kodi"
android:layout_width="@dimen/detail_control_width"
android:layout_height="@dimen/detail_control_height"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/play_with_kodi_title"
android:focusable="true"
android:gravity="center"
android:paddingVertical="@dimen/detail_control_padding"
android:text="@string/play_with_kodi_title"
android:textSize="@dimen/detail_control_text_size"
app:drawableTopCompat="?attr/ic_cast" />

</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="1px"
Expand Down
Loading

0 comments on commit 825a07e

Please sign in to comment.