Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ dependencies {
implementation "com.nononsenseapps:filepicker:4.2.1"

implementation "ch.acra:acra-core:5.5.0"
compileOnly "com.google.auto.service:auto-service-annotations:1.0-rc7"
kapt "com.google.auto.service:auto-service:1.0-rc7"

implementation "io.reactivex.rxjava2:rxjava:2.2.19"
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import org.acra.config.ACRAConfigurationException;
import org.acra.config.CoreConfiguration;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.sender.ReportSenderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.report.AcraReportSenderFactory;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.settings.SettingsActivity;
Expand Down Expand Up @@ -65,9 +63,6 @@

public class App extends Application {
protected static final String TAG = App.class.toString();
@SuppressWarnings("unchecked")
private static final Class<? extends ReportSenderFactory>[]
REPORT_SENDER_FACTORY_CLASSES = new Class[]{AcraReportSenderFactory.class};
private static App app;

public static App getApp() {
Expand Down Expand Up @@ -210,7 +205,6 @@ protected void initACRA() {

try {
final CoreConfiguration acraConfig = new CoreConfigurationBuilder(this)
.setReportSenderFactoryClasses(REPORT_SENDER_FACTORY_CLASSES)
.setBuildConfigClass(BuildConfig.class)
.build();
ACRA.init(this, acraConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
import org.schabi.newpipe.fragments.BaseStateFragment;
import org.schabi.newpipe.fragments.EmptyFragment;
import org.schabi.newpipe.fragments.list.comments.CommentsFragment;
import org.schabi.newpipe.fragments.list.playlist.AppendPlaylistDialog;
import org.schabi.newpipe.fragments.list.videos.RelatedVideosFragment;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.player.MainVideoPlayer;
import org.schabi.newpipe.player.PopupVideoPlayer;
Expand Down Expand Up @@ -409,7 +409,7 @@ public void onClick(final View v) {
break;
case R.id.detail_controls_playlist_append:
if (getFragmentManager() != null && currentInfo != null) {
PlaylistAppendDialog.fromStreamInfo(currentInfo)
AppendPlaylistDialog.fromStreamInfo(currentInfo)
.show(getFragmentManager(), TAG);
}
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.schabi.newpipe.fragments.list.playlist;

import android.os.Bundle;
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 org.schabi.newpipe.R;
import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry;
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity;
import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.player.playqueue.PlayQueueItem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import io.reactivex.android.schedulers.AndroidSchedulers;

public final class AppendPlaylistDialog extends PlaylistDialog
implements PlaylistDialog.OnSelectedListener {
public static final String TAG = AppendPlaylistDialog.class.getSimpleName();

public AppendPlaylistDialog(@Nullable final List<StreamEntity> streamEntities) {
super(streamEntities, false);
setOnSelectedListener(this);
}

@Override
public View onCreateView(@NonNull final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {

final View view = super.onCreateView(inflater, container, savedInstanceState);

final View newPlaylistButton = Objects.requireNonNull(view).findViewById(R.id.newPlaylist);
newPlaylistButton.setVisibility(View.VISIBLE);
newPlaylistButton.setOnClickListener(v -> openCreatePlaylistDialog());

view.findViewById(R.id.titleTextView).setVisibility(View.GONE);

return view;
}

public static AppendPlaylistDialog fromStreamInfo(final StreamInfo streamInfo) {
return new AppendPlaylistDialog(Collections.singletonList(new StreamEntity(streamInfo)));
}

public static AppendPlaylistDialog fromStreamInfoItems(
final List<StreamInfoItem> streamInfoItems) {

final List<StreamEntity> streamEntities = new ArrayList<>(streamInfoItems.size());
for (final StreamInfoItem streamInfoItem : streamInfoItems) {
streamEntities.add(new StreamEntity(streamInfoItem));
}
return new AppendPlaylistDialog(streamEntities);
}

public static AppendPlaylistDialog fromPlayQueueItems(
final List<PlayQueueItem> playQueueItems) {

final List<StreamEntity> streamEntities = new ArrayList<>(playQueueItems.size());
for (final PlayQueueItem playQueueItem : playQueueItems) {
streamEntities.add(new StreamEntity(playQueueItem));
}
return new AppendPlaylistDialog(streamEntities);
}


@Override
public void onLocalPlaylistSelected(final PlaylistMetadataEntry localPlaylist) {
if (getStoredStreamEntities() != null) {
final Toast successToast = Toast.makeText(getContext(),
R.string.playlist_add_stream_success, Toast.LENGTH_SHORT);

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

dialogDisposables.add(getLocalPlaylistManager()
.appendToPlaylist(localPlaylist.uid, getStoredStreamEntities())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(ignored -> successToast.show()));

requireDialog().dismiss();
}
}

@Override
public void onRemotePlaylistSelected(final PlaylistRemoteEntity remotePlaylist) {
// unreachable code
}

public void openCreatePlaylistDialog() {
if (getStoredStreamEntities() == null) {
return;
}

new CreatePlaylistDialog(getStoredStreamEntities())
.show(getParentFragmentManager(), TAG);
requireDialog().dismiss();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package org.schabi.newpipe.fragments.list.playlist;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import org.schabi.newpipe.NewPipeDatabase;
import org.schabi.newpipe.R;
import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
import org.schabi.newpipe.util.StateSaver;

import java.util.List;
import java.util.Queue;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;

public final class CreatePlaylistDialog extends DialogFragment implements StateSaver.WriteRead {

/*//////////////////////////////////////////////////////////////////////////
// Dialog
//////////////////////////////////////////////////////////////////////////*/

private Disposable createPlaylistDisposable;

private List<StreamEntity> streamEntities;
private StateSaver.SavedState savedState;

CreatePlaylistDialog(final List<StreamEntity> streamEntities) {
this.streamEntities = streamEntities;
}

protected List<StreamEntity> getStreams() {
return streamEntities;
}

/*//////////////////////////////////////////////////////////////////////////
// LifeCycle
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
savedState = StateSaver.tryToRestore(savedInstanceState, this);
}

@Override
public void onDestroy() {
super.onDestroy();
StateSaver.onDestroy(savedState);

if (createPlaylistDisposable != null) {
createPlaylistDisposable.dispose();
}
}

@NonNull
@Override
public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
if (getStreams() == null) {
final Dialog dialog = super.onCreateDialog(savedInstanceState);
//remove title
final Window window = dialog.getWindow();
if (window != null) {
window.requestFeature(Window.FEATURE_NO_TITLE);
}
return dialog;
}

View dialogView = View.inflate(getContext(), R.layout.dialog_playlist_name, null);
EditText nameInput = dialogView.findViewById(R.id.playlist_name);

final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext())
.setTitle(R.string.create_playlist)
.setView(dialogView)
.setCancelable(true)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.create, (dialogInterface, i) -> {
final String name = nameInput.getText().toString();
final LocalPlaylistManager playlistManager =
new LocalPlaylistManager(NewPipeDatabase.getInstance(requireContext()));
final Toast successToast = Toast.makeText(getActivity(),
R.string.playlist_creation_success,
Toast.LENGTH_SHORT);

createPlaylistDisposable = playlistManager.createPlaylist(name, getStreams())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(longs -> successToast.show());
});

return dialogBuilder.create();
}

/*//////////////////////////////////////////////////////////////////////////
// State Saving
//////////////////////////////////////////////////////////////////////////*/

@Override
public String generateSuffix() {
final int size = streamEntities == null ? 0 : streamEntities.size();
return "." + size + ".list";
}

@Override
public void writeTo(final Queue<Object> objectsToSave) {
objectsToSave.add(streamEntities);
}

@Override
@SuppressWarnings("unchecked")
public void readFrom(@NonNull final Queue<Object> savedObjects) {
streamEntities = (List<StreamEntity>) savedObjects.poll();
}

@Override
public void onSaveInstanceState(@NonNull final Bundle outState) {
super.onSaveInstanceState(outState);
if (getActivity() != null) {
savedState = StateSaver.tryToSave(getActivity().isChangingConfigurations(),
savedState, outState, this);
}
}
}
Loading