Trying to make a file downloadManager
we have a activity which contains recycler view, each item in recycler view represents a file which is either in downloading, downladed state. Each recycler view item has a callback this callback has 3 information: onSuccess (file), onError(Error), progress(Int). Now I want to extract this information in BindViewHolder to show the progress, but i cannot get value in callback: (removing other code for simplicity)
class DownloadActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val list = mutableListOf<DItem>()
list.add(DItem("url", callback = object : Listener{
override fun onSuccess(file: File) {
}
override fun onFailure(error: Error) {
}
override fun onProgress(progress: Int) {
}
})
// trigger from here for simplicity otherwise each list item has a download button which will trigger this:
FileDownloadManager().download("utl", list[0].callback)
}
// adapter
class DownloadAdapter : RecyclerView.Adapter<MyViewhOdler>() {
val list = mutableListOf<DItem>()
override fun onBindViewHolder(holder: MyViewhOdler, position: Int) {
// how to get value here:
list.get(0).callback
}
}
class FileDownloadManager {
override fun download(url: String, callback: Listener) {
// on donwloading start, will trigger
// callback.progress(<some value>)
}
interface Listener{
fun onSuccess(file: File)
fun onFailure(error: Error)
fun onProgress(progress: Int)
}
}
// Ditem
data class DItem (
var url: String? = null,
var callback: Listener,
var fcallback: ((File, Error, Int)-> Unit)
)
}
DItemhave a public field calledcallback? The mere existence of a constructor parameter with that name does not imply that it's an instance variable.