Skip to content

Commit d9af788

Browse files
authored
Merge pull request #8397 from notaLonelyDay/add-download-to-longpress-menu
Add download to longpress menu
2 parents 0e55803 + a4724fe commit d9af788

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

app/src/main/java/org/schabi/newpipe/info_list/dialog/InfoItemDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ public Builder addDefaultBeginningEntries() {
321321
*/
322322
public Builder addDefaultEndEntries() {
323323
addAllEntries(
324+
StreamDialogDefaultEntry.DOWNLOAD,
324325
StreamDialogDefaultEntry.APPEND_PLAYLIST,
325326
StreamDialogDefaultEntry.SHARE,
326327
StreamDialogDefaultEntry.OPEN_IN_BROWSER

app/src/main/java/org/schabi/newpipe/info_list/dialog/StreamDialogDefaultEntry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.schabi.newpipe.util.NavigationHelper.openChannelFragment;
44
import static org.schabi.newpipe.util.SparseItemUtil.fetchItemInfoIfSparse;
5+
import static org.schabi.newpipe.util.SparseItemUtil.fetchStreamInfoAndSaveToDatabase;
56
import static org.schabi.newpipe.util.SparseItemUtil.fetchUploaderUrlIfSparse;
67

78
import android.net.Uri;
@@ -11,6 +12,7 @@
1112

1213
import org.schabi.newpipe.R;
1314
import org.schabi.newpipe.database.stream.model.StreamEntity;
15+
import org.schabi.newpipe.download.DownloadDialog;
1416
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
1517
import org.schabi.newpipe.local.dialog.PlaylistDialog;
1618
import org.schabi.newpipe.local.history.HistoryRecordManager;
@@ -110,6 +112,15 @@ public enum StreamDialogDefaultEntry {
110112
ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(),
111113
item.getThumbnailUrl())),
112114

115+
DOWNLOAD(R.string.download, (fragment, item) ->
116+
fetchStreamInfoAndSaveToDatabase(fragment.requireContext(), item.getServiceId(),
117+
item.getUrl(), info -> {
118+
final DownloadDialog downloadDialog
119+
= new DownloadDialog(fragment.requireContext(), info);
120+
downloadDialog.show(fragment.getChildFragmentManager(), "downloadDialog");
121+
})
122+
),
123+
113124
OPEN_IN_BROWSER(R.string.open_in_browser, (fragment, item) ->
114125
ShareUtils.openUrlInBrowser(fragment.requireContext(), item.getUrl())),
115126

app/src/main/java/org/schabi/newpipe/util/SparseItemUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ public static void fetchUploaderUrlIfSparse(@NonNull final Context context,
9797
* @param url url of the stream to load
9898
* @param callback callback to be called with the result
9999
*/
100-
private static void fetchStreamInfoAndSaveToDatabase(@NonNull final Context context,
101-
final int serviceId,
102-
@NonNull final String url,
103-
final Consumer<StreamInfo> callback) {
100+
public static void fetchStreamInfoAndSaveToDatabase(@NonNull final Context context,
101+
final int serviceId,
102+
@NonNull final String url,
103+
final Consumer<StreamInfo> callback) {
104104
Toast.makeText(context, R.string.loading_stream_details, Toast.LENGTH_SHORT).show();
105105
ExtractorHelper.getStreamInfo(serviceId, url, false)
106106
.subscribeOn(Schedulers.io())

0 commit comments

Comments
 (0)