Closed longnguyencmg closed 5 years ago
@elihart Can u please help me here?
fun setProgress(progress: Float) {
this.myProgress = progress
}
this doesn't make the models get built again - you need to call requestModelBuild
there.
also, you shouldn't be passing in context like this
@EpoxyAttribute
lateinit var context: Context
get it off of your viewholder views instead
@elihart, thank you for your response.
Actually, I tried requestModelBuild() before and got exception You cannot call 'requestModelBuild' directly. Call 'setData' instead to trigger a model refresh with new data.
I'm using Typed4EpoxyController
So when I handle click Download action, I have to update progress value into the controller. And then call setData
again in function handleDataState
(below)
private fun handleDataState(resource: Resource<List<CourseChapterView>>) {
when (resource.status) {
ResourceState.SUCCESS -> {
resource.data?.let { chapterViews ->
val chapters = chapterViews.map { courseChapterViewMapper.mapFromView(it) }
controller.setData(false, chapters, isPurchased, isAuthenticated)
checkIfChapterIsPlaying()
}
}
ResourceState.LOADING -> {
controller.setData(true, emptyList(), isPurchased, isAuthenticated)
}
ResourceState.ERROR -> {
Timber.d(resource.message)
}
}
}
And then, the setData
function update progress for all models at the same time instead of the selected item. That's what I unexpected.
What I try to do here is when I click on button 'Download' on each row, then the Model just update the progress itself separately.
Oh, I see what you are saying - this is because your data structure isn't set up properly - you are using the same progress value for all models.
Epoxy always rebuilds all models - get in the mindset of thinking of your entire data set mapping to the models, and all models are rebuilt from the data.
you need to change your data structure to completely represent your models. The MvRx library is good for that and works very nicely with epoxy, but you can also just use a data class. You shouldn't be using the typed adapter - it's messy when you have 4 parameters, plus you are setting data via the progress setter.
anyway, for your specific problem, you need a map of chapter to progress
val progressMap = mutableMapOf<Chapter, Float>()
fun setProgress(chapter: Chapter, progress: Float) = progressMap[chapter] = progress
and when you build models, grab the right progress for the chapter
Thank you very much for your solution. It works well now. Cheers :)
Hello, I'm new to the library and I have an issue while implementing my example app. In general, I have a list view of model (using
@EpoxyModelClass
and@EpoxyAttribute
manually). In each model, I have a buttondownload
anddownload_progress_view
(updated by progress). When clicking ondownload
button, then it will update progress of view in model with different values. I have problem with this, click ondownload
then all model update progress instead of the clicked one. Do you have any suggestions?Thanks for great library. Please have a look at relevant code below:
My Model
My controller
Handle onDownloadClicked