From d0b6d95f1b684d912cbbdb4a3d9bd012c9e614a2 Mon Sep 17 00:00:00 2001 From: Carlos Melero <10256660+carmebar@users.noreply.github.com> Date: Fri, 24 Jun 2022 16:09:08 +0200 Subject: [PATCH] Add Share option to local playlists A newline-separated text is shared --- .../local/playlist/LocalPlaylistFragment.java | 26 ++++++++++++++++--- app/src/main/res/menu/menu_local_playlist.xml | 6 +++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 6023d4b10..4bffc0983 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.local.playlist; +import static org.schabi.newpipe.error.ErrorUtil.showUiErrorSnackbar; import static org.schabi.newpipe.ktx.ViewUtils.animate; import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout; @@ -50,6 +51,7 @@ import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; import org.schabi.newpipe.info_list.dialog.StreamDialogDefaultEntry; +import org.schabi.newpipe.util.external_communication.ShareUtils; import java.util.ArrayList; import java.util.Collections; @@ -57,10 +59,12 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; import icepick.State; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; import io.reactivex.rxjava3.core.Flowable; +import io.reactivex.rxjava3.core.Single; import io.reactivex.rxjava3.disposables.CompositeDisposable; import io.reactivex.rxjava3.disposables.Disposable; import io.reactivex.rxjava3.schedulers.Schedulers; @@ -345,7 +349,11 @@ public class LocalPlaylistFragment extends BaseLocalListFragment Single.just(playlist.stream() + .map(PlaylistStreamEntry::getStreamEntity) + .map(StreamEntity::getUrl) + .collect(Collectors.joining("\n")))) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(urlsText -> ShareUtils.shareText(requireContext(), name, urlsText), + throwable -> showUiErrorSnackbar(this, "Sharing playlist", throwable))); + } + public void removeWatchedStreams(final boolean removePartiallyWatched) { if (isRemovingWatched) { return; diff --git a/app/src/main/res/menu/menu_local_playlist.xml b/app/src/main/res/menu/menu_local_playlist.xml index 41791b791..0ff182b48 100644 --- a/app/src/main/res/menu/menu_local_playlist.xml +++ b/app/src/main/res/menu/menu_local_playlist.xml @@ -2,6 +2,12 @@ + +