From 2d0bc0548849da36e9ad0c4a5d70025aca89a737 Mon Sep 17 00:00:00 2001 From: Roy Yosef Date: Mon, 13 Apr 2020 23:40:58 +0300 Subject: [PATCH] Add sub-channel details to channel fragment --- .../list/channel/ChannelFragment.java | 60 +++++++++++++++- .../newpipe/streams/Mp4FromDashWriter.java | 3 +- app/src/main/res/layout/channel_header.xml | 68 +++++++++++++------ 3 files changed, 109 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index ad8d25d3a..faa13c792 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -21,6 +21,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import com.jakewharton.rxbinding2.view.RxView; @@ -38,6 +39,7 @@ import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.local.subscription.SubscriptionManager; import org.schabi.newpipe.player.playqueue.ChannelPlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueue; +import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.ExtractorHelper; @@ -65,7 +67,8 @@ import static org.schabi.newpipe.util.AnimationUtils.animateBackgroundColor; import static org.schabi.newpipe.util.AnimationUtils.animateTextColor; import static org.schabi.newpipe.util.AnimationUtils.animateView; -public class ChannelFragment extends BaseListInfoFragment { +public class ChannelFragment extends BaseListInfoFragment + implements View.OnClickListener { private static final int BUTTON_DEBOUNCE_INTERVAL = 100; private final CompositeDisposable disposables = new CompositeDisposable(); private Disposable subscribeButtonMonitor; @@ -79,6 +82,8 @@ public class ChannelFragment extends BaseListInfoFragment { private ImageView headerChannelBanner; private ImageView headerAvatarView; private TextView headerTitleView; + private ImageView headerParentChannelAvatarView; + private TextView headerParentChannelTitleView; private TextView headerSubscribersTextView; private Button headerSubscribeButton; private View playlistCtrl; @@ -156,7 +161,10 @@ public class ChannelFragment extends BaseListInfoFragment { headerSubscribersTextView = headerRootLayout.findViewById(R.id.channel_subscriber_view); headerSubscribeButton = headerRootLayout.findViewById(R.id.channel_subscribe_button); playlistCtrl = headerRootLayout.findViewById(R.id.playlist_control); - + headerParentChannelAvatarView = + headerRootLayout.findViewById(R.id.parent_channel_avatar_view); + headerParentChannelTitleView = + headerRootLayout.findViewById(R.id.parent_channel_title_view); headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_all_button); headerPopupButton = headerRootLayout.findViewById(R.id.playlist_ctrl_play_popup_button); @@ -165,6 +173,12 @@ public class ChannelFragment extends BaseListInfoFragment { return headerRootLayout; } + @Override + protected void initListeners() { + headerParentChannelTitleView.setOnClickListener(this); + headerParentChannelAvatarView.setOnClickListener(this); + } + /*////////////////////////////////////////////////////////////////////////// // Menu //////////////////////////////////////////////////////////////////////////*/ @@ -394,6 +408,36 @@ public class ChannelFragment extends BaseListInfoFragment { return ExtractorHelper.getChannelInfo(serviceId, url, forceLoad); } + /*////////////////////////////////////////////////////////////////////////// + // OnClick + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public void onClick(final View v) { + if (isLoading.get() || currentInfo == null) { + return; + } + + switch (v.getId()) { + case R.id.parent_channel_avatar_view: + case R.id.parent_channel_title_view: + if (TextUtils.isEmpty(currentInfo.getParentChannelUrl())) { + Log.w(TAG, "Can't open parent's channel because we got no channel URL"); + } else { + try { + NavigationHelper.openChannelFragment( + getFragmentManager(), + currentInfo.getServiceId(), + currentInfo.getParentChannelUrl(), + currentInfo.getParentChannelName()); + } catch (Exception e) { + ErrorActivity.reportUiError((AppCompatActivity) getActivity(), e); + } + } + break; + } + } + /*////////////////////////////////////////////////////////////////////////// // Contract //////////////////////////////////////////////////////////////////////////*/ @@ -404,6 +448,7 @@ public class ChannelFragment extends BaseListInfoFragment { IMAGE_LOADER.cancelDisplayTask(headerChannelBanner); IMAGE_LOADER.cancelDisplayTask(headerAvatarView); + IMAGE_LOADER.cancelDisplayTask(headerParentChannelAvatarView); animateView(headerSubscribeButton, false, 100); } @@ -416,6 +461,8 @@ public class ChannelFragment extends BaseListInfoFragment { ImageDisplayConstants.DISPLAY_BANNER_OPTIONS); IMAGE_LOADER.displayImage(result.getAvatarUrl(), headerAvatarView, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); + IMAGE_LOADER.displayImage(result.getParentChannelAvatarUrl(), headerParentChannelAvatarView, + ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS); headerSubscribersTextView.setVisibility(View.VISIBLE); if (result.getSubscriberCount() >= 0) { @@ -425,6 +472,15 @@ public class ChannelFragment extends BaseListInfoFragment { headerSubscribersTextView.setText(R.string.subscribers_count_not_available); } + if (!TextUtils.isEmpty(currentInfo.getParentChannelName())) { + headerParentChannelTitleView.setText( + "Created by " + currentInfo.getParentChannelName()); + headerParentChannelTitleView.setVisibility(View.VISIBLE); + } else { + headerParentChannelTitleView.setVisibility(View.GONE); + headerParentChannelAvatarView.setVisibility(View.GONE); + } + if (menuRssButton != null) { menuRssButton.setVisible(!TextUtils.isEmpty(result.getFeedUrl())); } diff --git a/app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java b/app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java index 6f7d27c2c..eb208280e 100644 --- a/app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java +++ b/app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java @@ -711,7 +711,8 @@ public class Mp4FromDashWriter { for (int i = 0; i < tracks.length; i++) { if (tracks[i].trak.tkhd.matrix.length != 36) { - throw new RuntimeException("bad track matrix length (expected 36) in track n°" + i); + throw + new RuntimeException("bad track matrix length (expected 36) in track n°" + i); } makeTrak(i, durations[i], defaultMediaTime[i], tablesInfo[i], is64); } diff --git a/app/src/main/res/layout/channel_header.xml b/app/src/main/res/layout/channel_header.xml index 4a0e261c5..59e22cfb5 100644 --- a/app/src/main/res/layout/channel_header.xml +++ b/app/src/main/res/layout/channel_header.xml @@ -23,17 +23,32 @@ android:src="@drawable/channel_banner" tools:ignore="ContentDescription"/> - + android:layout_marginTop="50dp"> + + + + + + tools:text="Lorem ipsum dolor" /> + + + tools:visibility="visible" />