fix thumbnail not shown in background player

This commit is contained in:
Christian Schabesberger 2018-08-22 16:04:32 +02:00
parent ce83fd9a10
commit 2003f51d49
6 changed files with 85 additions and 109 deletions

View file

@ -87,12 +87,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
RxView.clicks(errorButtonRetry) RxView.clicks(errorButtonRetry)
.debounce(300, TimeUnit.MILLISECONDS) .debounce(300, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Object>() { .subscribe(o -> onRetryButtonClicked());
@Override
public void accept(Object o) throws Exception {
onRetryButtonClicked();
}
});
} }
protected void onRetryButtonClicked() { protected void onRetryButtonClicked() {

View file

@ -169,38 +169,35 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
context.getResources().getString(R.string.share) context.getResources().getString(R.string.share)
}; };
final DialogInterface.OnClickListener actions = new DialogInterface.OnClickListener() { final DialogInterface.OnClickListener actions = (DialogInterface dialogInterface, int i) -> {
@Override final int index = Math.max(infoListAdapter.getItemsList().indexOf(item), 0);
public void onClick(DialogInterface dialogInterface, int i) { switch (i) {
final int index = Math.max(infoListAdapter.getItemsList().indexOf(item), 0); case 0:
switch (i) { NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item));
case 0: break;
NavigationHelper.enqueueOnBackgroundPlayer(context, new SinglePlayQueue(item)); case 1:
break; NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item));
case 1: break;
NavigationHelper.enqueueOnPopupPlayer(activity, new SinglePlayQueue(item)); case 2:
break; NavigationHelper.playOnMainPlayer(context, getPlayQueue(index));
case 2: break;
NavigationHelper.playOnMainPlayer(context, getPlayQueue(index)); case 3:
break; NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index));
case 3: break;
NavigationHelper.playOnBackgroundPlayer(context, getPlayQueue(index)); case 4:
break; NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index));
case 4: break;
NavigationHelper.playOnPopupPlayer(activity, getPlayQueue(index)); case 5:
break; if (getFragmentManager() != null) {
case 5: PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item))
if (getFragmentManager() != null) { .show(getFragmentManager(), TAG);
PlaylistAppendDialog.fromStreamInfoItems(Collections.singletonList(item)) }
.show(getFragmentManager(), TAG); break;
} case 6:
break; shareUrl(item.getName(), item.getUrl());
case 6: break;
shareUrl(item.getName(), item.getUrl()); default:
break; break;
default:
break;
}
} }
}; };
@ -258,12 +255,12 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
private static final int BUTTON_DEBOUNCE_INTERVAL = 100; private static final int BUTTON_DEBOUNCE_INTERVAL = 100;
private void monitorSubscription(final ChannelInfo info) { private void monitorSubscription(final ChannelInfo info) {
final Consumer<Throwable> onError = new Consumer<Throwable>() { final Consumer<Throwable> onError = (Throwable throwable) -> {
@Override
public void accept(Throwable throwable) throws Exception {
animateView(headerSubscribeButton, false, 100); animateView(headerSubscribeButton, false, 100);
showSnackBarError(throwable, UserAction.SUBSCRIPTION, NewPipe.getNameOfService(currentInfo.getServiceId()), "Get subscription status", 0); showSnackBarError(throwable, UserAction.SUBSCRIPTION,
} NewPipe.getNameOfService(currentInfo.getServiceId()),
"Get subscription status",
0);
}; };
final Observable<List<SubscriptionEntity>> observable = subscriptionService.subscriptionTable() final Observable<List<SubscriptionEntity>> observable = subscriptionService.subscriptionTable()
@ -279,50 +276,38 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
// so only update the UI for the latest emission ("sync" the subscribe button's state) // so only update the UI for the latest emission ("sync" the subscribe button's state)
.debounce(100, TimeUnit.MILLISECONDS) .debounce(100, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<List<SubscriptionEntity>>() { .subscribe((List<SubscriptionEntity> subscriptionEntities) ->
@Override updateSubscribeButton(!subscriptionEntities.isEmpty())
public void accept(List<SubscriptionEntity> subscriptionEntities) throws Exception { , onError));
updateSubscribeButton(!subscriptionEntities.isEmpty());
}
}, onError));
} }
private Function<Object, Object> mapOnSubscribe(final SubscriptionEntity subscription) { private Function<Object, Object> mapOnSubscribe(final SubscriptionEntity subscription) {
return new Function<Object, Object>() { return (@NonNull Object o) -> {
@Override subscriptionService.subscriptionTable().insert(subscription);
public Object apply(@NonNull Object o) throws Exception { return o;
subscriptionService.subscriptionTable().insert(subscription);
return o;
}
}; };
} }
private Function<Object, Object> mapOnUnsubscribe(final SubscriptionEntity subscription) { private Function<Object, Object> mapOnUnsubscribe(final SubscriptionEntity subscription) {
return new Function<Object, Object>() { return (@NonNull Object o) -> {
@Override subscriptionService.subscriptionTable().delete(subscription);
public Object apply(@NonNull Object o) throws Exception { return o;
subscriptionService.subscriptionTable().delete(subscription);
return o;
}
}; };
} }
private void updateSubscription(final ChannelInfo info) { private void updateSubscription(final ChannelInfo info) {
if (DEBUG) Log.d(TAG, "updateSubscription() called with: info = [" + info + "]"); if (DEBUG) Log.d(TAG, "updateSubscription() called with: info = [" + info + "]");
final Action onComplete = new Action() { final Action onComplete = () -> {
@Override
public void run() throws Exception {
if (DEBUG) Log.d(TAG, "Updated subscription: " + info.getUrl()); if (DEBUG) Log.d(TAG, "Updated subscription: " + info.getUrl());
}
}; };
final Consumer<Throwable> onError = new Consumer<Throwable>() { final Consumer<Throwable> onError = (@NonNull Throwable throwable) ->
@Override onUnrecoverableError(throwable,
public void accept(@NonNull Throwable throwable) throws Exception { UserAction.SUBSCRIPTION,
onUnrecoverableError(throwable, UserAction.SUBSCRIPTION, NewPipe.getNameOfService(info.getServiceId()), "Updating Subscription for " + info.getUrl(), R.string.subscription_update_failed); NewPipe.getNameOfService(info.getServiceId()),
} "Updating Subscription for " + info.getUrl(),
}; R.string.subscription_update_failed);
disposables.add(subscriptionService.updateChannelInfo(info) disposables.add(subscriptionService.updateChannelInfo(info)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -331,19 +316,16 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
} }
private Disposable monitorSubscribeButton(final Button subscribeButton, final Function<Object, Object> action) { private Disposable monitorSubscribeButton(final Button subscribeButton, final Function<Object, Object> action) {
final Consumer<Object> onNext = new Consumer<Object>() { final Consumer<Object> onNext = (@NonNull Object o) -> {
@Override
public void accept(@NonNull Object o) throws Exception {
if (DEBUG) Log.d(TAG, "Changed subscription status to this channel!"); if (DEBUG) Log.d(TAG, "Changed subscription status to this channel!");
}
}; };
final Consumer<Throwable> onError = new Consumer<Throwable>() { final Consumer<Throwable> onError = (@NonNull Throwable throwable) ->
@Override onUnrecoverableError(throwable,
public void accept(@NonNull Throwable throwable) throws Exception { UserAction.SUBSCRIPTION,
onUnrecoverableError(throwable, UserAction.SUBSCRIPTION, NewPipe.getNameOfService(currentInfo.getServiceId()), "Subscription Change", R.string.subscription_change_failed); NewPipe.getNameOfService(currentInfo.getServiceId()),
} "Subscription Change",
}; R.string.subscription_change_failed);
/* Emit clicks from main thread unto io thread */ /* Emit clicks from main thread unto io thread */
return RxView.clicks(subscribeButton) return RxView.clicks(subscribeButton)
@ -355,25 +337,25 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
} }
private Consumer<List<SubscriptionEntity>> getSubscribeUpdateMonitor(final ChannelInfo info) { private Consumer<List<SubscriptionEntity>> getSubscribeUpdateMonitor(final ChannelInfo info) {
return new Consumer<List<SubscriptionEntity>>() { return (List<SubscriptionEntity> subscriptionEntities) -> {
@Override if (DEBUG)
public void accept(List<SubscriptionEntity> subscriptionEntities) throws Exception { Log.d(TAG, "subscriptionService.subscriptionTable.doOnNext() called with: subscriptionEntities = [" + subscriptionEntities + "]");
if (DEBUG) if (subscribeButtonMonitor != null) subscribeButtonMonitor.dispose();
Log.d(TAG, "subscriptionService.subscriptionTable.doOnNext() called with: subscriptionEntities = [" + subscriptionEntities + "]");
if (subscribeButtonMonitor != null) subscribeButtonMonitor.dispose();
if (subscriptionEntities.isEmpty()) { if (subscriptionEntities.isEmpty()) {
if (DEBUG) Log.d(TAG, "No subscription to this channel!"); if (DEBUG) Log.d(TAG, "No subscription to this channel!");
SubscriptionEntity channel = new SubscriptionEntity(); SubscriptionEntity channel = new SubscriptionEntity();
channel.setServiceId(info.getServiceId()); channel.setServiceId(info.getServiceId());
channel.setUrl(info.getUrl()); channel.setUrl(info.getUrl());
channel.setData(info.getName(), info.getAvatarUrl(), info.getDescription(), info.getSubscriberCount()); channel.setData(info.getName(),
subscribeButtonMonitor = monitorSubscribeButton(headerSubscribeButton, mapOnSubscribe(channel)); info.getAvatarUrl(),
} else { info.getDescription(),
if (DEBUG) Log.d(TAG, "Found subscription to this channel!"); info.getSubscriberCount());
final SubscriptionEntity subscription = subscriptionEntities.get(0); subscribeButtonMonitor = monitorSubscribeButton(headerSubscribeButton, mapOnSubscribe(channel));
subscribeButtonMonitor = monitorSubscribeButton(headerSubscribeButton, mapOnUnsubscribe(subscription)); } else {
} if (DEBUG) Log.d(TAG, "Found subscription to this channel!");
final SubscriptionEntity subscription = subscriptionEntities.get(0);
subscribeButtonMonitor = monitorSubscribeButton(headerSubscribeButton, mapOnUnsubscribe(subscription));
} }
}; };
} }
@ -491,8 +473,11 @@ public class ChannelFragment extends BaseListInfoFragment<ChannelInfo> {
super.handleNextItems(result); super.handleNextItems(result);
if (!result.getErrors().isEmpty()) { if (!result.getErrors().isEmpty()) {
showSnackBarError(result.getErrors(), UserAction.REQUESTED_CHANNEL, NewPipe.getNameOfService(serviceId), showSnackBarError(result.getErrors(),
"Get next page of: " + url, R.string.general_error); UserAction.REQUESTED_CHANNEL,
NewPipe.getNameOfService(serviceId),
"Get next page of: " + url,
R.string.general_error);
} }
} }

View file

@ -309,7 +309,6 @@ public final class BackgroundPlayer extends Service {
@Override @Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage); super.onLoadingComplete(imageUri, view, loadedImage);
resetNotification();
updateNotificationThumbnail(); updateNotificationThumbnail();
updateNotification(-1); updateNotification(-1);
} }
@ -342,7 +341,6 @@ public final class BackgroundPlayer extends Service {
updateProgress(currentProgress, duration, bufferPercent); updateProgress(currentProgress, duration, bufferPercent);
if (!shouldUpdateOnProgress) return; if (!shouldUpdateOnProgress) return;
resetNotification();
if (bigNotRemoteView != null) { if (bigNotRemoteView != null) {
bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false); bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false);
bigNotRemoteView.setTextViewText(R.id.notificationTime, getTimeString(currentProgress) + " / " + getTimeString(duration)); bigNotRemoteView.setTextViewText(R.id.notificationTime, getTimeString(currentProgress) + " / " + getTimeString(duration));
@ -531,8 +529,6 @@ public final class BackgroundPlayer extends Service {
@Override @Override
public void onPlaying() { public void onPlaying() {
super.onPlaying(); super.onPlaying();
resetNotification();
updateNotificationThumbnail();
updateNotification(R.drawable.ic_pause_white); updateNotification(R.drawable.ic_pause_white);
lockManager.acquireWifiAndCpu(); lockManager.acquireWifiAndCpu();
} }

View file

@ -51,6 +51,7 @@ import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
@ -98,7 +99,7 @@ import static org.schabi.newpipe.report.UserAction.PLAY_STREAM;
public abstract class BasePlayer implements public abstract class BasePlayer implements
Player.EventListener, PlaybackListener, ImageLoadingListener { Player.EventListener, PlaybackListener, ImageLoadingListener {
public static final boolean DEBUG = true; public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
@NonNull public static final String TAG = "BasePlayer"; @NonNull public static final String TAG = "BasePlayer";
@NonNull final protected Context context; @NonNull final protected Context context;

View file

@ -6,6 +6,7 @@ import android.util.Log;
import org.reactivestreams.Subscriber; import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription; import org.reactivestreams.Subscription;
import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.player.playqueue.events.AppendEvent; import org.schabi.newpipe.player.playqueue.events.AppendEvent;
import org.schabi.newpipe.player.playqueue.events.ErrorEvent; import org.schabi.newpipe.player.playqueue.events.ErrorEvent;
import org.schabi.newpipe.player.playqueue.events.InitEvent; import org.schabi.newpipe.player.playqueue.events.InitEvent;
@ -41,7 +42,7 @@ import io.reactivex.subjects.BehaviorSubject;
public abstract class PlayQueue implements Serializable { public abstract class PlayQueue implements Serializable {
private final String TAG = "PlayQueue@" + Integer.toHexString(hashCode()); private final String TAG = "PlayQueue@" + Integer.toHexString(hashCode());
public static final boolean DEBUG = true; public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
private ArrayList<PlayQueueItem> backup; private ArrayList<PlayQueueItem> backup;
private ArrayList<PlayQueueItem> streams; private ArrayList<PlayQueueItem> streams;

View file

@ -31,8 +31,6 @@ import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.Stream;
import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.MainFragment;
import org.schabi.newpipe.fragments.detail.VideoDetailFragment; import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
import org.schabi.newpipe.fragments.list.channel.ChannelFragment; import org.schabi.newpipe.fragments.list.channel.ChannelFragment;