Skip to content

Commit

Permalink
Merge pull request #2956 from TeamNewPipe/release_v0.18.1
Browse files Browse the repository at this point in the history
Release v0.18.1
  • Loading branch information
TobiGr authored Jan 19, 2020
2 parents 9a6e936 + fd62411 commit 42ff60c
Show file tree
Hide file tree
Showing 47 changed files with 1,717 additions and 344 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "org.schabi.newpipe"
minSdkVersion 19
targetSdkVersion 28
versionCode 800
versionName "0.18.0"
versionCode 810
versionName "0.18.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -62,7 +62,7 @@ dependencies {
exclude module: 'support-annotations'
})

implementation 'com.github.TeamNewPipe:NewPipeExtractor:8e53fda'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:2ee558fb'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'

Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<!-- channel prefix -->
<data android:pathPrefix="/channel/"/>
<data android:pathPrefix="/user/"/>
<data android:pathPrefix="/c/"/>
<!-- playlist prefix -->
<data android:pathPrefix="/playlist"/>
</intent-filter>
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import org.schabi.newpipe.MainActivity;
import org.schabi.newpipe.R;
import org.schabi.newpipe.RouterActivity;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.localization.Localization;
Expand Down Expand Up @@ -368,6 +369,9 @@ private void initToolbar(Toolbar toolbar) {
toolbar.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.okay) {
prepareSelectedDownload();
if (getActivity() instanceof RouterActivity) {
getActivity().finish();
}
return true;
}
return false;
Expand Down Expand Up @@ -555,8 +559,16 @@ private void prepareSelectedDownload() {
case R.id.audio_button:
mainStorage = mainStorageAudio;
format = audioStreamsAdapter.getItem(selectedAudioIndex).getFormat();
mime = format.mimeType;
filename += format.suffix;
switch(format) {
case WEBMA_OPUS:
mime = "audio/ogg";
filename += "opus";
break;
default:
mime = format.mimeType;
filename += format.suffix;
break;
}
break;
case R.id.video_button:
mainStorage = mainStorageVideo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
import org.schabi.newpipe.settings.tabs.TabsManager;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.ServiceHelper;
import org.schabi.newpipe.views.ScrollableTabLayout;

import java.util.ArrayList;
import java.util.List;

public class MainFragment extends BaseFragment implements TabLayout.OnTabSelectedListener {
private ViewPager viewPager;
private SelectedTabsPagerAdapter pagerAdapter;
private TabLayout tabLayout;
private ScrollableTabLayout tabLayout;

private List<Tab> tabsList = new ArrayList<>();
private TabsManager tabsManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.schabi.newpipe.local.dialog;

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.schabi.newpipe.NewPipeDatabase;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.LocalItem;
Expand Down Expand Up @@ -152,6 +153,12 @@ private void onPlaylistSelected(@NonNull LocalPlaylistManager manager,
final Toast successToast = Toast.makeText(getContext(),
R.string.playlist_add_stream_success, Toast.LENGTH_SHORT);

if (playlist.thumbnailUrl.equals("drawable://" + R.drawable.dummy_thumbnail_playlist)) {
playlistDisposables.add(manager.changePlaylistThumbnail(playlist.uid, streams.get(0).getThumbnailUrl())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show()));
}

playlistDisposables.add(manager.appendToPlaylist(playlist.uid, streams)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.ItemTouchHelper;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
Expand All @@ -18,6 +13,12 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.schabi.newpipe.NewPipeDatabase;
Expand Down Expand Up @@ -325,6 +326,16 @@ public void handleResult(@NonNull List<PlaylistStreamEntry> result) {
headerBackgroundButton.setOnClickListener(view ->
NavigationHelper.playOnBackgroundPlayer(activity, getPlayQueue(), false));

headerPopupButton.setOnLongClickListener(view -> {
NavigationHelper.enqueueOnPopupPlayer(activity, getPlayQueue(), true);
return true;
});

headerBackgroundButton.setOnLongClickListener(view -> {
NavigationHelper.enqueueOnBackgroundPlayer(activity, getPlayQueue(), true);
return true;
});

hideLoading();
}

Expand Down Expand Up @@ -403,10 +414,25 @@ private void changeThumbnailUrl(final String thumbnailUrl) {
disposables.add(disposable);
}

private void updateThumbnailUrl() {
String newThumbnailUrl;

if (!itemListAdapter.getItemsList().isEmpty()) {
newThumbnailUrl = ((PlaylistStreamEntry) itemListAdapter.getItemsList().get(0)).thumbnailUrl;
} else {
newThumbnailUrl = "drawable://" + R.drawable.dummy_thumbnail_playlist;
}

changeThumbnailUrl(newThumbnailUrl);
}

private void deleteItem(final PlaylistStreamEntry item) {
if (itemListAdapter == null) return;

itemListAdapter.removeItem(item);
if (playlistManager.getPlaylistThumbnail(playlistId).equals(item.thumbnailUrl))
updateThumbnailUrl();

setVideoCount(itemListAdapter.getItemsList().size());
saveChanges();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public Maybe<Integer> changePlaylistThumbnail(final long playlistId,
return modifyPlaylist(playlistId, null, thumbnailUrl);
}

public String getPlaylistThumbnail(final long playlistId) {
return playlistTable.getPlaylist(playlistId).blockingFirst().get(0).getThumbnailUrl();
}

private Maybe<Integer> modifyPlaylist(final long playlistId,
@Nullable final String name,
@Nullable final String thumbnailUrl) {
Expand Down
79 changes: 69 additions & 10 deletions app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.IBinder;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;
Expand All @@ -48,6 +53,7 @@
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
import org.schabi.newpipe.player.resolver.AudioPlaybackResolver;
import org.schabi.newpipe.player.resolver.MediaSourceTag;
import org.schabi.newpipe.util.BitmapUtils;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.ThemeHelper;

Expand Down Expand Up @@ -75,6 +81,7 @@ public final class BackgroundPlayer extends Service {

private BasePlayerImpl basePlayerImpl;
private LockManager lockManager;
private SharedPreferences sharedPreferences;

/*//////////////////////////////////////////////////////////////////////////
// Service-Activity Binder
Expand All @@ -95,6 +102,9 @@ public final class BackgroundPlayer extends Service {

private boolean shouldUpdateOnProgress;

private static final int NOTIFICATION_UPDATES_BEFORE_RESET = 60;
private int timesNotificationUpdated;

/*//////////////////////////////////////////////////////////////////////////
// Service's LifeCycle
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -104,6 +114,7 @@ public void onCreate() {
if (DEBUG) Log.d(TAG, "onCreate() called");
notificationManager = ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
lockManager = new LockManager(this);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

ThemeHelper.setTheme(this);
basePlayerImpl = new BasePlayerImpl(this);
Expand Down Expand Up @@ -180,6 +191,7 @@ private void onScreenOnOff(boolean on) {

private void resetNotification() {
notBuilder = createNotification();
timesNotificationUpdated = 0;
}

private NotificationCompat.Builder createNotification() {
Expand All @@ -195,12 +207,45 @@ private NotificationCompat.Builder createNotification() {
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setCustomContentView(notRemoteView)
.setCustomBigContentView(bigNotRemoteView);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setLockScreenThumbnail(builder);
}

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
builder.setPriority(NotificationCompat.PRIORITY_MAX);
}
return builder;
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void setLockScreenThumbnail(NotificationCompat.Builder builder) {
boolean isLockScreenThumbnailEnabled = sharedPreferences.getBoolean(
getString(R.string.enable_lock_screen_video_thumbnail_key),
true
);

if (isLockScreenThumbnailEnabled) {
basePlayerImpl.mediaSessionManager.setLockScreenArt(
builder,
getCenteredThumbnailBitmap()
);
} else {
basePlayerImpl.mediaSessionManager.clearLockScreenArt(builder);
}
}

@Nullable
private Bitmap getCenteredThumbnailBitmap() {
int screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels;
int screenHeight = Resources.getSystem().getDisplayMetrics().heightPixels;

return BitmapUtils.centerCrop(
basePlayerImpl.getThumbnail(),
screenWidth,
screenHeight);
}

private void setupNotification(RemoteViews remoteViews) {
if (basePlayerImpl == null) return;

Expand Down Expand Up @@ -248,10 +293,13 @@ private synchronized void updateNotification(int drawableId) {
//if (DEBUG) Log.d(TAG, "updateNotification() called with: drawableId = [" + drawableId + "]");
if (notBuilder == null) return;
if (drawableId != -1) {
if (notRemoteView != null) notRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId);
if (bigNotRemoteView != null) bigNotRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId);
if (notRemoteView != null)
notRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId);
if (bigNotRemoteView != null)
bigNotRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId);
}
notificationManager.notify(NOTIFICATION_ID, notBuilder.build());
timesNotificationUpdated++;
}

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -275,7 +323,8 @@ private void setRepeatModeIcon(final RemoteViews remoteViews, final int repeatMo

protected class BasePlayerImpl extends BasePlayer {

@NonNull final private AudioPlaybackResolver resolver;
@NonNull
final private AudioPlaybackResolver resolver;
private int cachedDuration;
private String cachedDurationString;

Expand All @@ -294,8 +343,10 @@ public void handleIntent(final Intent intent) {
super.handleIntent(intent);

resetNotification();
if (bigNotRemoteView != null) bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 0, false);
if (notRemoteView != null) notRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 0, false);
if (bigNotRemoteView != null)
bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 0, false);
if (notRemoteView != null)
notRemoteView.setProgressBar(R.id.notificationProgressBar, 100, 0, false);
startForeground(NOTIFICATION_ID, notBuilder.build());
}

Expand Down Expand Up @@ -330,6 +381,7 @@ public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
updateNotificationThumbnail();
updateNotification(-1);
}

/*//////////////////////////////////////////////////////////////////////////
// States Implementation
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -351,10 +403,15 @@ public void onUpdateProgress(int currentProgress, int duration, int bufferPercen
updateProgress(currentProgress, duration, bufferPercent);

if (!shouldUpdateOnProgress) return;
resetNotification();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O /*Oreo*/) updateNotificationThumbnail();
if (timesNotificationUpdated > NOTIFICATION_UPDATES_BEFORE_RESET) {
resetNotification();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O /*Oreo*/) {
updateNotificationThumbnail();
}
}
if (bigNotRemoteView != null) {
if(cachedDuration != duration) {
if (cachedDuration != duration) {
cachedDuration = duration;
cachedDurationString = getTimeString(duration);
}
Expand Down Expand Up @@ -382,8 +439,10 @@ public void onPlayNext() {
@Override
public void destroy() {
super.destroy();
if (notRemoteView != null) notRemoteView.setImageViewBitmap(R.id.notificationCover, null);
if (bigNotRemoteView != null) bigNotRemoteView.setImageViewBitmap(R.id.notificationCover, null);
if (notRemoteView != null)
notRemoteView.setImageViewBitmap(R.id.notificationCover, null);
if (bigNotRemoteView != null)
bigNotRemoteView.setImageViewBitmap(R.id.notificationCover, null);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 42ff60c

Please sign in to comment.