mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-11-04 01:03:00 +00:00 
			
		
		
		
	Add download option to long-press menu
This commit is contained in:
		
				
					committed by
					
						
						Stypox
					
				
			
			
				
	
			
			
			
						parent
						
							0e5580390f
						
					
				
				
					commit
					a4724fec4a
				
			@@ -321,6 +321,7 @@ public final class InfoItemDialog {
 | 
			
		||||
         */
 | 
			
		||||
        public Builder addDefaultEndEntries() {
 | 
			
		||||
            addAllEntries(
 | 
			
		||||
                    StreamDialogDefaultEntry.DOWNLOAD,
 | 
			
		||||
                    StreamDialogDefaultEntry.APPEND_PLAYLIST,
 | 
			
		||||
                    StreamDialogDefaultEntry.SHARE,
 | 
			
		||||
                    StreamDialogDefaultEntry.OPEN_IN_BROWSER
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package org.schabi.newpipe.info_list.dialog;
 | 
			
		||||
 | 
			
		||||
import static org.schabi.newpipe.util.NavigationHelper.openChannelFragment;
 | 
			
		||||
import static org.schabi.newpipe.util.SparseItemUtil.fetchItemInfoIfSparse;
 | 
			
		||||
import static org.schabi.newpipe.util.SparseItemUtil.fetchStreamInfoAndSaveToDatabase;
 | 
			
		||||
import static org.schabi.newpipe.util.SparseItemUtil.fetchUploaderUrlIfSparse;
 | 
			
		||||
 | 
			
		||||
import android.net.Uri;
 | 
			
		||||
@@ -11,6 +12,7 @@ import androidx.annotation.StringRes;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
@@ -110,6 +112,15 @@ public enum StreamDialogDefaultEntry {
 | 
			
		||||
            ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(),
 | 
			
		||||
                    item.getThumbnailUrl())),
 | 
			
		||||
 | 
			
		||||
    DOWNLOAD(R.string.download, (fragment, item) ->
 | 
			
		||||
            fetchStreamInfoAndSaveToDatabase(fragment.requireContext(), item.getServiceId(),
 | 
			
		||||
                    item.getUrl(), info -> {
 | 
			
		||||
                        final DownloadDialog downloadDialog
 | 
			
		||||
                                = new DownloadDialog(fragment.requireContext(), info);
 | 
			
		||||
                        downloadDialog.show(fragment.getChildFragmentManager(), "downloadDialog");
 | 
			
		||||
                    })
 | 
			
		||||
    ),
 | 
			
		||||
 | 
			
		||||
    OPEN_IN_BROWSER(R.string.open_in_browser, (fragment, item) ->
 | 
			
		||||
            ShareUtils.openUrlInBrowser(fragment.requireContext(), item.getUrl())),
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -97,10 +97,10 @@ public final class SparseItemUtil {
 | 
			
		||||
     * @param url       url of the stream to load
 | 
			
		||||
     * @param callback  callback to be called with the result
 | 
			
		||||
     */
 | 
			
		||||
    private static void fetchStreamInfoAndSaveToDatabase(@NonNull final Context context,
 | 
			
		||||
                                                         final int serviceId,
 | 
			
		||||
                                                         @NonNull final String url,
 | 
			
		||||
                                                         final Consumer<StreamInfo> callback) {
 | 
			
		||||
    public static void fetchStreamInfoAndSaveToDatabase(@NonNull final Context context,
 | 
			
		||||
                                                        final int serviceId,
 | 
			
		||||
                                                        @NonNull final String url,
 | 
			
		||||
                                                        final Consumer<StreamInfo> callback) {
 | 
			
		||||
        Toast.makeText(context, R.string.loading_stream_details, Toast.LENGTH_SHORT).show();
 | 
			
		||||
        ExtractorHelper.getStreamInfo(serviceId, url, false)
 | 
			
		||||
                .subscribeOn(Schedulers.io())
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user