From 1429774487f32b5cba578d89a89d3ecf14f09162 Mon Sep 17 00:00:00 2001 From: Roy Yosef Date: Mon, 13 Apr 2020 23:40:44 +0300 Subject: [PATCH] Add sub-channel details to video detail fragment --- app/build.gradle | 1 + .../fragments/detail/VideoDetailFragment.java | 95 +++++++++++++++---- .../fragment_video_detail.xml | 78 +++++++++++---- .../main/res/layout/fragment_video_detail.xml | 80 ++++++++++++---- app/src/main/res/values-land/dimens.xml | 4 +- app/src/main/res/values-sw600dp/dimens.xml | 4 +- app/src/main/res/values/dimens.xml | 8 +- app/src/main/res/values/strings.xml | 1 + settings.gradle | 6 ++ 9 files changed, 211 insertions(+), 66 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d91a4bba7..ecbdc150b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -66,6 +66,7 @@ android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 + encoding 'utf-8' } // Required and used only by groupie diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 35352c013..b6e53e74d 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -172,9 +172,10 @@ public class VideoDetailFragment extends BaseStateFragment private TextView videoUploadDateView; private TextView videoDescriptionView; - private View uploaderRootLayout; private TextView uploaderTextView; private ImageView uploaderThumb; + private TextView parentChannelTextView; + private ImageView parentChannelThumb; private TextView thumbsUpTextView; private ImageView thumbsUpImageView; @@ -418,19 +419,25 @@ public class VideoDetailFragment extends BaseStateFragment this.openDownloadDialog(); } break; - case R.id.detail_uploader_root_layout: + case R.id.detail_parent_channel_text_view: + case R.id.detail_parent_channel_thumbnail_view: + if (TextUtils.isEmpty(currentInfo.getParentChannelUrl())) { + Log.w(TAG, "Can't open parent's channel because we got no channel URL"); + + if (!TextUtils.isEmpty(currentInfo.getUploaderUrl())) { + openChannel(currentInfo.getUploaderUrl(), currentInfo.getUploaderName()); + } + } else { + openChannel(currentInfo.getParentChannelUrl(), + currentInfo.getParentChannelName()); + } + break; + case R.id.detail_uploader_text_view: + case R.id.detail_uploader_thumbnail_view: if (TextUtils.isEmpty(currentInfo.getUploaderUrl())) { Log.w(TAG, "Can't open channel because we got no channel URL"); } else { - try { - NavigationHelper.openChannelFragment( - getFragmentManager(), - currentInfo.getServiceId(), - currentInfo.getUploaderUrl(), - currentInfo.getUploaderName()); - } catch (Exception e) { - ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); - } + openChannel(currentInfo.getUploaderUrl(), currentInfo.getUploaderName()); } break; case R.id.detail_thumbnail_root_layout: @@ -447,6 +454,18 @@ public class VideoDetailFragment extends BaseStateFragment } } + private void openChannel(final String parentChannelUrl, final String parentChannelName) { + try { + NavigationHelper.openChannelFragment( + getFragmentManager(), + currentInfo.getServiceId(), + parentChannelUrl, + parentChannelName); + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } + } + @Override public boolean onLongClick(final View v) { if (isLoading.get() || currentInfo == null) { @@ -522,9 +541,10 @@ public class VideoDetailFragment extends BaseStateFragment thumbsDownImageView = rootView.findViewById(R.id.detail_thumbs_down_img_view); thumbsDisabledTextView = rootView.findViewById(R.id.detail_thumbs_disabled_view); - uploaderRootLayout = rootView.findViewById(R.id.detail_uploader_root_layout); uploaderTextView = rootView.findViewById(R.id.detail_uploader_text_view); uploaderThumb = rootView.findViewById(R.id.detail_uploader_thumbnail_view); + parentChannelTextView = rootView.findViewById(R.id.detail_parent_channel_text_view); + parentChannelThumb = rootView.findViewById(R.id.detail_parent_channel_thumbnail_view); appBarLayout = rootView.findViewById(R.id.appbarlayout); viewPager = rootView.findViewById(R.id.viewpager); @@ -554,8 +574,12 @@ public class VideoDetailFragment extends BaseStateFragment protected void initListeners() { super.initListeners(); + uploaderTextView.setOnClickListener(this); + uploaderThumb.setOnClickListener(this); + parentChannelTextView.setOnClickListener(this); + parentChannelThumb.setOnClickListener(this); + videoTitleRoot.setOnClickListener(this); - uploaderRootLayout.setOnClickListener(this); thumbnailBackgroundButton.setOnClickListener(this); detailControlsBackground.setOnClickListener(this); detailControlsPopup.setOnClickListener(this); @@ -603,6 +627,11 @@ public class VideoDetailFragment extends BaseStateFragment ImageDisplayConstants.DISPLAY_THUMBNAIL_OPTIONS, onFailListener); } + if (!TextUtils.isEmpty(info.getParentChannelAvatarUrl())) { + IMAGE_LOADER.displayImage(info.getParentChannelAvatarUrl(), parentChannelThumb, + ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); + } + if (!TextUtils.isEmpty(info.getUploaderAvatarUrl())) { IMAGE_LOADER.displayImage(info.getUploaderAvatarUrl(), uploaderThumb, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); @@ -964,7 +993,7 @@ public class VideoDetailFragment extends BaseStateFragment @NonNull final StreamInfo info, @NonNull final Stream selectedStream) { NavigationHelper.playOnExternalPlayer(context, currentInfo.getName(), - currentInfo.getUploaderName(), selectedStream); + currentInfo.getParentChannelName(), selectedStream); final HistoryRecordManager recordManager = new HistoryRecordManager(requireContext()); disposables.add(recordManager.onViewed(info).onErrorComplete() @@ -1097,9 +1126,9 @@ public class VideoDetailFragment extends BaseStateFragment } IMAGE_LOADER.cancelDisplayTask(thumbnailImageView); - IMAGE_LOADER.cancelDisplayTask(uploaderThumb); + IMAGE_LOADER.cancelDisplayTask(parentChannelThumb); thumbnailImageView.setImageBitmap(null); - uploaderThumb.setImageBitmap(null); + parentChannelThumb.setImageBitmap(null); } @Override @@ -1127,13 +1156,17 @@ public class VideoDetailFragment extends BaseStateFragment animateView(thumbnailPlayButton, true, 200); videoTitleTextView.setText(name); - if (!TextUtils.isEmpty(info.getUploaderName())) { - uploaderTextView.setText(info.getUploaderName()); - uploaderTextView.setVisibility(View.VISIBLE); - uploaderTextView.setSelected(true); + if (!TextUtils.isEmpty(info.getParentChannelName())) { + displayBothUploaderAndParentChannel(info); + } else if (!TextUtils.isEmpty(info.getUploaderName())) { + displayUploaderAsParentChannel(info); } else { + parentChannelThumb.setVisibility(View.GONE); uploaderTextView.setVisibility(View.GONE); + uploaderThumb.setVisibility(View.GONE); } + + parentChannelThumb.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.buddy)); uploaderThumb.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.buddy)); if (info.getViewCount() >= 0) { @@ -1264,6 +1297,28 @@ public class VideoDetailFragment extends BaseStateFragment viewPager.setVisibility(View.GONE); tabLayout.setVisibility(View.GONE); } + private void displayUploaderAsParentChannel(final StreamInfo info) { + parentChannelTextView.setText(info.getUploaderName()); + parentChannelTextView.setVisibility(View.VISIBLE); + parentChannelTextView.setSelected(true); + parentChannelThumb.setVisibility(View.GONE); + uploaderTextView.setVisibility(View.GONE); + } + + private void displayBothUploaderAndParentChannel(final StreamInfo info) { + parentChannelTextView.setText(info.getParentChannelName()); + parentChannelTextView.setVisibility(View.VISIBLE); + parentChannelTextView.setSelected(true); + + if (!TextUtils.isEmpty(info.getUploaderName())) { + uploaderTextView.setText("By " + info.getUploaderName()); + uploaderTextView.setVisibility(View.VISIBLE); + uploaderTextView.setSelected(true); + } else { + uploaderTextView.setVisibility(View.GONE); + } + } + public void openDownloadDialog() { try { diff --git a/app/src/main/res/layout-large-land/fragment_video_detail.xml b/app/src/main/res/layout-large-land/fragment_video_detail.xml index 10a622d55..8927a42fc 100644 --- a/app/src/main/res/layout-large-land/fragment_video_detail.xml +++ b/app/src/main/res/layout-large-land/fragment_video_detail.xml @@ -251,28 +251,66 @@ android:focusable="true" android:padding="6dp"> - + - + + + + + + + android:layout_height="match_parent" + android:gravity="center_vertical" + android:orientation="vertical"> + + + + + 42dp + 22dp 20sp 20sp 90dp diff --git a/app/src/main/res/values-sw600dp/dimens.xml b/app/src/main/res/values-sw600dp/dimens.xml index d745cdfb0..e3b7e6df7 100644 --- a/app/src/main/res/values-sw600dp/dimens.xml +++ b/app/src/main/res/values-sw600dp/dimens.xml @@ -8,12 +8,14 @@ 16sp 16sp 14sp - 16sp + 16sp + 12sp 16sp 16sp 18sp 45dp + 25dp 18sp 18sp diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index d97444f5b..575ac4e25 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -54,14 +54,16 @@ 15sp 13sp 12sp - 14sp + 12sp + 14sp 13sp 13sp 15sp - 12sp + 12sp 12sp - 28dp + 32dp + 16dp 18sp 18sp 70dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3b7bc8a4a..003088162 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -651,4 +651,5 @@ Disable fast mode Do you think feed loading is too slow? If so, try enabling fast loading (you can change it in settings or by pressing the button below).\n\nNewPipe offers two feed loading strategies:\n• Fetching the whole subscription channel, which is slow but complete.\n• Using a dedicated service endpoint, which is fast but usually not complete.\n\nThe difference between the two is that the fast one usually lacks some information, like the item\'s duration or type (can\'t distinguish between live videos and normal ones) and it may return less items.\n\nYouTube is an example of a service that offers this fast method with its RSS feed.\n\nSo the choice boils down to what you prefer: speed or precise information. This content is not yet supported by NewPipe.\n\nIt will hopefully be supported in a future version. + Channel\'s avatar thumbnail diff --git a/settings.gradle b/settings.gradle index e7b4def49..4928db65f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,7 @@ include ':app' + +includeBuild('../NewPipeExtractor') { + dependencySubstitution { + substitute module('com.github.TeamNewPipe:NewPipeExtractor') with project(':extractor') + } +} \ No newline at end of file