PRDownloader icon indicating copy to clipboard operation
PRDownloader copied to clipboard

Download from recylerview

Open demo-Ashif opened this issue 6 years ago • 3 comments

how to implement this downloader from recyclerview. faced issued due to downloadID. please provide example if possible.

demo-Ashif avatar May 22 '18 11:05 demo-Ashif

check my repo https://github.com/ghost1372/Circulars-Version3

ghost1372 avatar Jul 28 '18 15:07 ghost1372

@Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { final int[] downloadId = {i}; ...... Enjoy

truongluuxuan avatar Jul 09 '19 08:07 truongluuxuan

You can simply fix the issue following this task.

PRDownloader.download(pdfUrl, dirPath, fileName)
                .setTag(fileName)
                .build()

Declare the PRDownloader into the ViewHolder in Recycler view. setTag() is very important to control the download.

Here I add my code.

PRDownloader.download(pdfUrl, dirPath, fileName)
                .setTag(fileName)
                .build()
                .setOnStartOrResumeListener(() -> {

                })
                .setOnPauseListener(() -> {

                })
                .setOnCancelListener(() -> {

                })
                .setOnProgressListener(progress -> {
                    long progressPercent = progress.currentBytes * 100 / progress.totalBytes;
                    progressBar.setProgress((int) progressPercent);
                })
                .start(new OnDownloadListener() {

                    @Override
                    public void onDownloadComplete() {
                        relativeLayout.setVisibility(View.GONE);
                    }

                    @Override
                    public void onError(Error error) {

                    }
                });

If you want to cancel each download you can use this. PRDownloader.cancel("You're Predefined Tag");

Tarikul711 avatar Jul 21 '20 15:07 Tarikul711