1
  • I need to track and update download status(start,pause,play,done) of multiple files in a list that I get from some Api (can't share), onto a RecyclerView.

  • I am also getting a fileId so each file can be distinguished.

  • I need download tracking based on the fileId because the Download list is also searchable, it means that the position of items will change and so we can't rely on position based ViewHolder refreshing.

  • Also if for some reason you close the app, and then go back to the list, search the file, it should show the file download status.

  • Now there are three options :
    a) WorkManager based implementation (how this option can be implemented?)
    b) PRDownloader (how this option can be implemented?)
    c) Or Android's download manager? (Need to be sure that we need to show progress of multiple files at same time in a list.)

  • Which one is better and more reliable?

  • Which one is the shortest method?

    Also can someone share if you have code based on work manager?(how will you manage to relate fileId to workManger's work id. Do I need to make a DB table for keeping track of downloads by the Worker? How to use LiveData from workManager, iff we can in the ViewHolder )

[Reference to Blog/Code/Repos will be most helpful]

K D
  • 27
  • 4

1 Answers1

-1

Answering my own question(strange!).

  1. I used Fetch Downloader Library
  2. Initialized and used the "Fetch Instance" as a Singleton
  3. Added the download using tag (Maybe I wrongly used the tag. It was supposed to be used for group of downloads. But I used one tag for each download. But it worked.)
  4. Now I did following in the ViewHolder's bind() method :
  • Took the file Id as a "tag" and removed the FetchObserver linked to the "tag" i.e. Id using the method of "Fetch Instance" (//will update the method)
  • Then again find the download in the "Fetch Instance" using the Id as "tag".(getDownloadsByTag() method)
  • If there is a download, you will receive a downloadList whose 0th element will be your download because I am using one tag per download and not for group.
  • Now add the FetchObserver again for that "tag".
  • Inside the FetchObserver's lambda, update the progress and other values.

Note : The code can not be shared for non-disclosure purposes. Can share small snippets if you find this confusing.

K D
  • 27
  • 4