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 can i call custom function? #15

Closed hamza0786 closed 2 months ago

hamza0786 commented 2 months ago

Hi! how can i call a custom function when currently running download is finished.basically i want to know how can i track the downloads running and do something when the download is completed?

hamza0786 commented 2 months ago

i am calling a function like this:

if (downloadModel.status == Status.SUCCESS){ myfunction() } if (downloadModel.status == Status.FAILED){ myfunction() }

the function is only calling when download is failed but not working when the download is success.

khushpanchal commented 2 months ago

Could you tell the steps to reproduce? Pls note if you are using observeDownloads, list will get called every time db is update. In case you want to do anything specific but only one time on success, either user observeDowloadById or maintain some variable to make sure it get called only once.

Also Pls update to latest version 2.0.1, minor bugs are fixed

hamza0786 commented 2 months ago

i just want to know how can i trace the download when they finished so that i can do something when download is success?

khushpanchal commented 2 months ago

You can check with downloaModel.status

For single download use observeDownloadById, and when status is Success, perform some action.

In case you are using observeDownloads, you have to keep a track for each id, when download status come from non success to success state perform some action otherwise not

hamza0786 commented 2 months ago

can you give example code how can i observe with download id?

khushpanchal commented 2 months ago

Please check readme file

hamza0786 commented 2 months ago

ok thanks anyway!