From 7700cff5e51ea9d7b91e0d47ff80d9956e63da62 Mon Sep 17 00:00:00 2001 From: John Zhen Mo Date: Sat, 4 Nov 2017 11:30:01 -0700 Subject: [PATCH] -Added play buttons to channel fragment similar to playlist fragment. -Fixed abstract info play queue reloading the same initial page. -Fixed OOB on get item for abstract play queue. --- .../list/channel/ChannelFragment.java | 51 +++++ .../playlist/AbstractInfoPlayQueue.java | 7 +- .../newpipe/playlist/ChannelPlayQueue.java | 8 +- .../schabi/newpipe/playlist/PlayQueue.java | 2 +- .../newpipe/playlist/PlaylistPlayQueue.java | 8 +- app/src/main/res/layout/channel_header.xml | 192 ++++++++++++------ 6 files changed, 191 insertions(+), 77 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 64875b17f..908997a11 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 @@ -3,6 +3,7 @@ package org.schabi.newpipe.fragments.list.channel; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -10,6 +11,7 @@ import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; import android.text.TextUtils; import android.util.Log; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -19,6 +21,7 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import com.jakewharton.rxbinding2.view.RxView; @@ -30,10 +33,14 @@ import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.fragments.subscription.SubscriptionService; +import org.schabi.newpipe.playlist.ChannelPlayQueue; +import org.schabi.newpipe.playlist.PlayQueue; import org.schabi.newpipe.report.UserAction; import org.schabi.newpipe.util.AnimationUtils; import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.Localization; +import org.schabi.newpipe.util.NavigationHelper; +import org.schabi.newpipe.util.PermissionHelper; import java.util.List; import java.util.concurrent.TimeUnit; @@ -69,6 +76,10 @@ public class ChannelFragment extends BaseListInfoFragment { private TextView headerSubscribersTextView; private Button headerSubscribeButton; + private Button headerPlayAllButton; + private Button headerPopupButton; + private Button headerBackgroundButton; + private MenuItem menuRssButton; public static ChannelFragment getInstance(int serviceId, String url, String name) { @@ -125,6 +136,10 @@ public class ChannelFragment extends BaseListInfoFragment { headerSubscribersTextView = headerRootLayout.findViewById(R.id.channel_subscriber_view); headerSubscribeButton = headerRootLayout.findViewById(R.id.channel_subscribe_button); + headerPlayAllButton = headerRootLayout.findViewById(R.id.playlist_play_all_button); + headerPopupButton = headerRootLayout.findViewById(R.id.playlist_play_popup_button); + headerBackgroundButton = headerRootLayout.findViewById(R.id.playlist_play_bg_button); + return headerRootLayout; } @@ -391,6 +406,42 @@ public class ChannelFragment extends BaseListInfoFragment { if (subscribeButtonMonitor != null) subscribeButtonMonitor.dispose(); updateSubscription(result); monitorSubscription(result); + + headerPlayAllButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + NavigationHelper.playOnMainPlayer(activity, getPlayQueue()); + } + }); + headerPopupButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !PermissionHelper.checkSystemAlertWindowPermission(activity)) { + Toast toast = Toast.makeText(activity, R.string.msg_popup_permission, Toast.LENGTH_LONG); + TextView messageView = toast.getView().findViewById(android.R.id.message); + if (messageView != null) messageView.setGravity(Gravity.CENTER); + toast.show(); + return; + } + NavigationHelper.playOnPopupPlayer(activity, getPlayQueue()); + } + }); + headerBackgroundButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue()); + } + }); + } + + private PlayQueue getPlayQueue() { + return new ChannelPlayQueue( + currentInfo.service_id, + currentInfo.url, + currentInfo.next_streams_url, + infoListAdapter.getItemsList(), + 0 + ); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/playlist/AbstractInfoPlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/AbstractInfoPlayQueue.java index b35271b8f..74a68b880 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/AbstractInfoPlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/AbstractInfoPlayQueue.java @@ -26,7 +26,7 @@ abstract class AbstractInfoPlayQueue ext transient Disposable fetchReactor; AbstractInfoPlayQueue(final U item) { - this(item.service_id, item.url, item.url, Collections.emptyList(), 0); + this(item.service_id, item.url, null, Collections.emptyList(), 0); } AbstractInfoPlayQueue(final int serviceId, @@ -55,7 +55,7 @@ abstract class AbstractInfoPlayQueue ext return new SingleObserver() { @Override public void onSubscribe(@NonNull Disposable d) { - if (isComplete || (fetchReactor != null && !fetchReactor.isDisposed())) { + if (isComplete || !isInitial || (fetchReactor != null && !fetchReactor.isDisposed())) { d.dispose(); } else { fetchReactor = d; @@ -64,6 +64,7 @@ abstract class AbstractInfoPlayQueue ext @Override public void onSuccess(@NonNull T result) { + isInitial = false; if (!result.has_more_streams) isComplete = true; nextUrl = result.next_streams_url; @@ -86,7 +87,7 @@ abstract class AbstractInfoPlayQueue ext return new SingleObserver() { @Override public void onSubscribe(@NonNull Disposable d) { - if (isComplete || (fetchReactor != null && !fetchReactor.isDisposed())) { + if (isComplete || isInitial || (fetchReactor != null && !fetchReactor.isDisposed())) { d.dispose(); } else { fetchReactor = d; diff --git a/app/src/main/java/org/schabi/newpipe/playlist/ChannelPlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/ChannelPlayQueue.java index 239024f28..3c615608c 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/ChannelPlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/ChannelPlayQueue.java @@ -16,10 +16,10 @@ public final class ChannelPlayQueue extends AbstractInfoPlayQueue streams, - final int index) { + final String url, + final String nextPageUrl, + final List streams, + final int index) { super(serviceId, url, nextPageUrl, streams, index); } diff --git a/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java index 4d73e1cfd..b86450b10 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/PlayQueue.java @@ -123,7 +123,7 @@ public abstract class PlayQueue implements Serializable { * May throw {@link IndexOutOfBoundsException}. * */ public PlayQueueItem getItem(int index) { - if (index >= streams.size() || streams.get(index) == null) return null; + if (index < 0 || index >= streams.size() || streams.get(index) == null) return null; return streams.get(index); } diff --git a/app/src/main/java/org/schabi/newpipe/playlist/PlaylistPlayQueue.java b/app/src/main/java/org/schabi/newpipe/playlist/PlaylistPlayQueue.java index 30edcec7c..64d263346 100644 --- a/app/src/main/java/org/schabi/newpipe/playlist/PlaylistPlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/playlist/PlaylistPlayQueue.java @@ -16,10 +16,10 @@ public final class PlaylistPlayQueue extends AbstractInfoPlayQueue streams, - final int index) { + final String url, + final String nextPageUrl, + final List streams, + final int index) { super(serviceId, url, nextPageUrl, streams, index); } diff --git a/app/src/main/res/layout/channel_header.xml b/app/src/main/res/layout/channel_header.xml index a817f7f79..7f08e5932 100644 --- a/app/src/main/res/layout/channel_header.xml +++ b/app/src/main/res/layout/channel_header.xml @@ -5,76 +5,138 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/channel_header_layout" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginBottom="12dp"> + android:layout_height="wrap_content"> - + android:layout_height="wrap_content"> - + - + + + + + + + + + - - - - + android:layout_marginEnd="2dp" + android:layout_below="@+id/channel_metadata"> + +