khushpanchal / Ketch

An Android File downloader library based on WorkManager with pause and resume support.
https://medium.com/@khush.panchal123/ketch-android-file-downloader-library-7369f7b93bd1
440 stars 33 forks source link

How to automatically delete the download when finished from recyclerview? #11

Closed hamza0786 closed 2 months ago

hamza0786 commented 2 months ago

Hi! How to automatically delete the download when finished from recyclerview?

khushpanchal commented 2 months ago

To automatically delete the downloaded file from the RecyclerView, you can observe the Flow of DownloadModel list and check the status field. When the status is SUCCESS, you can remove the item from the RecyclerView adapter.

Something like this:

downloadModelList.collect { list ->
    val filteredList = list.filter { it.status != Status.SUCCESS }
    adapter.setItems(filteredList)
}
hamza0786 commented 2 months ago

Screenshot (10)

i am getting this when i paste your code in observe method.

hamza0786 commented 2 months ago

and remember i only want to delete the downloaded item view from recyclerview not the downloaded file itself from the storage.

khushpanchal commented 2 months ago

Not like this, that was for reference, do like this

ketch.observeDownloads().collect { list -> val filteredList = list.filter { it.status != Status.SUCCESS } adapter.submitList(filteredList) }
hamza0786 commented 2 months ago

Thank you very much for helping me out brother!