Open alouanemed opened 6 years ago
A couple suggestions
EmptyViewModel_()
.id("empty")
.message(emptyMessage)
.actionText(actionText)
.spanSizeOverride { _, _, _ -> 2 }
.onEmptyActionClicked(onEmptyActionClicked)
.addTo(this)
use the generated kotlin extension functions instead to write this as
emptyViewModel {
id("empty")
message(emptyMessage)
actionText(actionText)
spanSizeOverride { _, _, _ -> 2 }
onEmptyActionClicked(onEmptyActionClicked)
}
instead of using addIf
do this
if (showListProgress) progressViewSmallModel {
id("ProgressViewSmallModel_0")
spanSizeOverride { _, _, _ -> 2 }
}
instead of doing this
.message(context.getString(R.string.plutus__main_search_result_list_empty))
use @TextProp to generate a method that takes the string resource directly. this is more efficient so you don't have to look up the string while you're building models, it is deferred to when the view is bound
.message(R.string.plutus__main_search_result_list_empty)
instead of creating your id string by concatenation you can pass multiple arguments
.id("ProductItemModel_" + it.id)
do instead. this is more efficient to avoid creating a new string
.id("ProductItemModel_", it.id)
besides that the boolean logic looks as simple as it can get - i don't think you can get rid of inherent complexity
Thank you Eli. Really appreciated.
@elihart I seem to can't resolve this when using kotlin extensions. Is there any config should be done to enable this?
emptyViewModel {
id("empty")
message(emptyMessage)
actionText(actionText)
spanSizeOverride { _, _, _ -> 2 }
onEmptyActionClicked(onEmptyActionClicked)
}
Do you use kapt for your annotation processing? You'll have to add the epoxy-processor as kapt and not annotationProcessor in your build.gradle file for Epoxy to generate Kotlin extensions.
Thanks!
Sorry for reopning this,I just checked that I am indeed using kapt :
implementation "com.airbnb.android:epoxy:$versions.epoxyversion"
kapt "com.airbnb.android:epoxy-processor:$versions.epoxyversion"
have you applied the kapt plugin?
Yes, I already have those on my gradle file.
@alouanemed did you manage to get this working?
Unfortunately, no.
@alouanemed
This happened to me recently make sure you have following in your module gradle file
apply plugin: 'kotlin-kapt'
// to enable error type infering in stubs
kapt {
correctErrorTypes = true
}
dependencies{
implementation OtherDeps.EPOXY_CORE
implementation OtherDeps.EPOXY_DATABINDING
kapt OtherDeps.EPOXY_ANNOTATION_PROCESSOR
}
then clean and rebuild the project.
If the errors are still there, just highlight the word extension functions name in your case emptyViewModel
start retryping the word emptyViewModel
in that place you will get a suggestion called emptyViewModel{ ... }
select it and press tab. This will generate the extension functions source inside modules build folder and import the extension function in your current file.
Hi, I saw that @elihart suggest using @TextProp
to do .message(R.string.plutus__main_search_result_list_empty)
. I'm using @EpoxyDataBindingPattern
, how can I achieve the @TextProp
in my case. Thank you so much
I am using epoxy controller to show the results of 2 types: Products and Product Lists. I am seeing myself repeating a lot of states changes using booleans. Is there an efficient way to do this? Thanks.
The Controller : https://gist.github.com/alouanemed/71c63c9d91e5676dd6bb1c563e56ee1b