Skip to content

Commit

Permalink
Add download option to long-press menu
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita.artikhovich authored and Stypox committed Jul 6, 2022
1 parent 0e55803 commit 15ea0fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public Builder addDefaultBeginningEntries() {
*/
public Builder addDefaultEndEntries() {
addAllEntries(
StreamDialogDefaultEntry.DOWNLOAD,
StreamDialogDefaultEntry.APPEND_PLAYLIST,
StreamDialogDefaultEntry.SHARE,
StreamDialogDefaultEntry.OPEN_IN_BROWSER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@

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;

import java.util.Collections;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
* <p>
Expand Down Expand Up @@ -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())),

Expand Down

0 comments on commit 15ea0fc

Please sign in to comment.