From 15ea0fc8533430fe80df9cda4cd5b8e36de2aaab Mon Sep 17 00:00:00 2001 From: "nikita.artikhovich" Date: Fri, 13 May 2022 23:42:18 +0300 Subject: [PATCH] Add download option to long-press menu --- .../info_list/dialog/InfoItemDialog.java | 1 + .../dialog/StreamDialogDefaultEntry.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/info_list/dialog/InfoItemDialog.java b/app/src/main/java/org/schabi/newpipe/info_list/dialog/InfoItemDialog.java index 5afaea0384a..61a88bb8f22 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/dialog/InfoItemDialog.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/dialog/InfoItemDialog.java @@ -321,6 +321,7 @@ public Builder addDefaultBeginningEntries() { */ public Builder addDefaultEndEntries() { addAllEntries( + StreamDialogDefaultEntry.DOWNLOAD, StreamDialogDefaultEntry.APPEND_PLAYLIST, StreamDialogDefaultEntry.SHARE, StreamDialogDefaultEntry.OPEN_IN_BROWSER diff --git a/app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java b/app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java index 7e87318ee39..02f3c5decd6 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java @@ -8,12 +8,15 @@ import androidx.annotation.NonNull; import androidx.annotation.StringRes; +import androidx.fragment.app.FragmentManager; import org.schabi.newpipe.R; import org.schabi.newpipe.database.stream.model.StreamEntity; +import org.schabi.newpipe.download.DownloadDialog; import org.schabi.newpipe.local.dialog.PlaylistAppendDialog; import org.schabi.newpipe.local.dialog.PlaylistDialog; import org.schabi.newpipe.local.history.HistoryRecordManager; +import org.schabi.newpipe.util.ExtractorHelper; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.external_communication.KoreUtils; import org.schabi.newpipe.util.external_communication.ShareUtils; @@ -21,6 +24,7 @@ import java.util.Collections; import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers; +import io.reactivex.rxjava3.schedulers.Schedulers; /** *

@@ -110,6 +114,25 @@ public enum StreamDialogDefaultEntry { ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(), item.getThumbnailUrl())), + DOWNLOAD(R.string.download, (fragment, item) -> ExtractorHelper.getStreamInfo( + item.getServiceId(), + item.getUrl(), + false + ) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(info -> { + final DownloadDialog downloadDialog = + DownloadDialog.newInstance(fragment.requireContext(), info); + final FragmentManager fm = fragment.getChildFragmentManager(); + downloadDialog.show(fm, "downloadDialog"); + fm.executePendingTransactions(); + }, + throwable -> { + } + ) + ), + OPEN_IN_BROWSER(R.string.open_in_browser, (fragment, item) -> ShareUtils.openUrlInBrowser(fragment.requireContext(), item.getUrl())),