Paul Woitaschek
11/29/2018, 6:59 AMleosan
11/29/2018, 9:08 AMPaul Woitaschek
11/29/2018, 10:10 AMBaseDelegateAdapter
?leosan
11/29/2018, 10:17 AMPaul Woitaschek
11/29/2018, 10:18 AMExtensionsViewHolder
which extends ViewHolder
and implements LayoutContainer
and return that subclass there.leosan
11/29/2018, 10:18 AMleosan
11/29/2018, 10:22 AMItem
which is basically what you said?
I looked at the byte code and it stills this
Intrinsics.checkParameterIsNotNull(viewHolder, "viewHolder");
TextView var10000 = (TextView)((LayoutContainer)viewHolder).getContainerView().findViewById(id.tvHeadline);
leosan
11/29/2018, 10:23 AMgetContainerView().findViewById
is the same thing as calling _$_findCachedViewById
leosan
11/29/2018, 10:27 AMLayoutContainer
internally the kotlin synthetic doesn't know about the delegated class and don´t generate the findCacheViewById
I could be wrong but it seems to me that it's the same thing as not using LayoutContainer
Paul Woitaschek
11/29/2018, 10:38 AMPaul Woitaschek
11/29/2018, 10:38 AMPaul Woitaschek
11/29/2018, 10:38 AMclass ExtensionViewHolder(view: View) : RecyclerView.ViewHolder(view), LayoutContainer {
override val containerView: View = itemView
}
fun bind(holder: ExtensionViewHolder) {
holder.title.text = "hello"
}
Paul Woitaschek
11/29/2018, 10:39 AMPaul Woitaschek
11/29/2018, 10:39 AMLINENUMBER 13 L1
ALOAD 0
GETSTATIC com/yazio/android/coach/R$id.title : I
INVOKEVIRTUAL com/yazio/android/coach/data/ExtensionViewHolder._$_findCachedViewById (I)Landroid/view/View;
CHECKCAST android/widget/TextView
DUP
LDC "holder.title"
INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkExpressionValueIsNotNull (Ljava/lang/Object;Ljava/lang/String;)V
LDC "hello"
CHECKCAST java/lang/CharSequence
INVOKEVIRTUAL android/widget/TextView.setText (Ljava/lang/CharSequence;)V
L2
leosan
11/29/2018, 10:41 AMPaul Woitaschek
11/29/2018, 10:41 AMPaul Woitaschek
11/29/2018, 10:41 AMleosan
11/29/2018, 10:42 AMleosan
11/29/2018, 10:42 AMinner class ViewHolder(
parent: ViewGroup,
@LayoutRes layoutRes: Int
) : RecyclerView.ViewHolder(parent.inflate(layoutRes)) {
//This will delegate to another class
fun bind(item: BaseViewType) = delegateAdapters[item.getViewType()]?.bindView(itemView, item, this)
}
`
Paul Woitaschek
11/29/2018, 10:42 AMleosan
11/29/2018, 10:43 AMPaul Woitaschek
11/29/2018, 10:43 AMthe one I sent you from groupie, doesn't know anything about LayoutContainer
Paul Woitaschek
11/29/2018, 10:43 AMPaul Woitaschek
11/29/2018, 10:43 AMPaul Woitaschek
11/29/2018, 10:44 AMleosan
11/29/2018, 10:45 AMPaul Woitaschek
11/29/2018, 10:47 AMPaul Woitaschek
11/29/2018, 10:47 AMPaul Woitaschek
11/29/2018, 10:47 AMoverride fun bindView(itemView: View, item: BaseViewType, viewHolder: RecyclerView.ViewHolder) {
Paul Woitaschek
11/29/2018, 10:47 AMviewHolder: RecyclerView.ViewHolder
must be viewHolder: ExtensionViewHolder
leosan
11/29/2018, 10:48 AMleosan
11/29/2018, 11:27 AMleosan
11/29/2018, 11:32 AMPaul Woitaschek
11/29/2018, 12:50 PMPaul Woitaschek
11/29/2018, 12:50 PMPaul Woitaschek
11/29/2018, 12:50 PMPaul Woitaschek
11/29/2018, 12:51 PMPaul Woitaschek
11/29/2018, 12:51 PMviewHolder.textView...
, not <http://containerView.xyz|containerView.xyz>
.leosan
11/29/2018, 12:53 PMleosan
11/29/2018, 12:53 PMPaul Woitaschek
11/29/2018, 12:54 PMleosan
11/29/2018, 12:56 PMviewHolder.textView
or <http://containerView.xyz|containerView.xyz>
or <http://itemView.xyz|itemView.xyz>
or <http://viewHolder.containerView.xyz|viewHolder.containerView.xyz>
produces the same exactly bythe code which is findViewById
Paul Woitaschek
11/29/2018, 12:56 PMt should be, notviewHolder.textView...
.<http://containerView.xyz|containerView.xyz>
Paul Woitaschek
11/29/2018, 12:56 PMPaul Woitaschek
11/29/2018, 12:57 PMleosan
11/29/2018, 12:57 PMleosan
11/29/2018, 12:58 PMbind
method so the container class doesn't have a clue about LayoutContainer
this way kotlin compiler can't generate findViewByCache
leosan
11/29/2018, 12:59 PMleosan
11/29/2018, 1:02 PMPaul Woitaschek
11/29/2018, 1:03 PMleosan
11/29/2018, 1:04 PMleosan
11/29/2018, 1:15 PMviewHolder.textView
as you mention, just so you can see that I triedPaul Woitaschek
11/29/2018, 1:16 PMleosan
11/29/2018, 1:17 PMoverride fun bind(viewHolder: ViewHolder, position: Int) {
viewHolder.textView.text = content
}
leosan
11/29/2018, 1:17 PMTextView var10000 = (TextView)((LayoutContainer)viewHolder).getContainerView().findViewById(id.textView);
Paul Woitaschek
11/29/2018, 1:21 PMPaul Woitaschek
11/29/2018, 1:21 PMPaul Woitaschek
11/29/2018, 1:21 PMandroidExtensions {
experimental = true
}
Paul Woitaschek
11/29/2018, 1:22 PMleosan
11/29/2018, 1:22 PMPaul Woitaschek
11/29/2018, 1:23 PM// IMPORTANT! Enables view caching in viewholders.
// See: <https://github.com/Kotlin/KEEP/blob/master/proposals/android-extensions-entity-caching.md>
androidExtensions {
experimental = true
}
leosan
11/29/2018, 1:24 PMclass CachedViewHolder(override val containerView: View) : RecyclerView.ViewHolder(containerView), LayoutContainer {
fun bind(model: DummyModel) {
textView.text = model.content
}
}
leosan
11/29/2018, 1:25 PMPaul Woitaschek
11/29/2018, 1:27 PMPaul Woitaschek
11/29/2018, 1:27 PMExtensionsViewHolder
as it's signatureleosan
11/29/2018, 1:29 PMTextView var10000 = (TextView)itemView.findViewById(id.textView);
Paul Woitaschek
11/29/2018, 1:30 PMleosan
11/29/2018, 1:37 PMPaul Woitaschek
11/29/2018, 1:45 PMPaul Woitaschek
11/29/2018, 1:45 PMleosan
11/29/2018, 1:48 PMleosan
11/29/2018, 1:49 PMDummyModel
specifically