I'm currently working on an app that downloads videos from the internet. I'm using RecyclerView to show a list of videos and I'm using a ProgressBar in each item. The problem is, when a download starts, the ProgressBar shows the download progress, but when I try to scroll or even touch the screen the progress goes back down to 0.
My question is: Is there a way to prevent it?
I'm using ThinDownloadManager to download the videos.
Downloader.class
private DownloadRequest downloadRequest(Context context,
String destinationFolder, ArrayList<String> information) {
return new DownloadRequest
.setRetryPolicy(new DefaultRetryPolicy())
.setDestinationURI(Uri.parse(context.getExternalCacheDir() + destinationFolder))
.setDownloadResumable(true)
.setPriority(DownloadRequest.Priority.HIGH)
.setStatusListener(new DownloadStatusListenerV1() {
@Override
public void onDownloadComplete(DownloadRequest downloadRequest) {
addToFavorites(context, information, destinationFolder);
@Override
public void onDownloadFailed(DownloadRequest downloadRequest, int errorCode, String errorMessage) {
}
@Override
public void onProgress(DownloadRequest downloadRequest, long totalBytes, long downloadedBytes, int progress) {
mProgressBar.setProgress(progress);
}
});
An Adapter for YouTube Playlist:
Adapter.class
@NonNull
@Override
public VideoHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = mLayoutInflater.inflate(mResource, parent, false);
return new VideoHolder(view, mClickListener, mDownloadListener);
}
@Override
public void onBindViewHolder(@NonNull VideoHolder holder, int position) {
RelatedVideosResponse.RelatedItems relatedItems = mPlayListResults.get(position);
RelatedVideosResponse.RelatedSnippet relatedSnippet = relatedItems.getRelatedSnippet();
Glide.with(mContext).load(relatedSnippet.getRelatedThumbNails().getHigh().getUrl()).into(holder.image);
holder.title.setText(relatedSnippet.getTitle());
}
ViewHolder
private LinearLayout itemBackground;
private CircleImageView image;
private TextView title;
private ImageButton more;
private NumberProgressBar downloadProgress;
private OnRelatedVideoClickListener mPlayVideoClickListener;
private MoreClickListener mMoreListener;
VideoHolder(View itemView, OnRelatedVideoClickListener clickListener, MoreClickListener moreListener) {
super(itemView);
itemBackground = itemView.findViewById(R.id.ll_related_videos);
image = itemView.findViewById(R.id.civ_related_video);
title = itemView.findViewById(R.id.tv_related_video_title);
more = itemView.findViewById(R.id.btn_download_related_video);
downloadProgress = itemView.findViewById(R.id.pb_download);
mPlayVideoClickListener = clickListener;
mMoreListener = moreListener;
itemView.setOnClickListener(this);
more.setOnClickListener(this);
}
ANSWER: The reason for that behavior is because some view covered my RecyclerView a little bit, so I fixed it by moving the view away.