Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Protected function call from public-API inline function is prohibited with Kotlin 1.4.0 #94

Closed
wants to merge 1 commit into from

Conversation

vanniktech
Copy link
Contributor

#89 is no longer working for me

@sockeqwe
Copy link
Owner

Thanks for this.
But making it public would break too many apps out there (everyone would need to change their AdapterDelegates from protected to public if I'm not mistaken). I think we could wrap the AdapterDelegates into a public API version just for the inline DSL functions. This should solve calling protected methods from Inline dunctions and should not break all other AdapterDelegates out there. Will give it a try tomorrow.

@sockeqwe
Copy link
Owner

Wait, I just checked it the demo app and it compiles just fine with Kotlin 1.4.0.

I think I dont understand what your "modification does" so that it requires to make these methods to be public. Can you explain?

@vanniktech
Copy link
Contributor Author

vanniktech commented Aug 25, 2020

package com.hannesdorfmann.adapterdelegates4

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.hannesdorfmann.adapterdelegates4.dsl.AdapterDelegateViewHolder

@Suppress("UNCHECKED_CAST", "PROTECTED_CALL_FROM_PUBLIC_INLINE")
inline fun <Old, reified I : T, T> AdapterDelegate<List<Old>>.wrap(noinline mapper: (I) -> Old): AdapterDelegate<List<T>> {
  val listItemAdapterDelegate = this as AbsListItemAdapterDelegate<Old, Old, AdapterDelegateViewHolder<Old>>
  return object : AbsListItemAdapterDelegate<I, T, RecyclerView.ViewHolder>() {
    override fun isForViewType(item: T, items: MutableList<T>, position: Int): Boolean = item is I

    override fun onBindViewHolder(item: I, holder: RecyclerView.ViewHolder, payloads: MutableList<Any>) {
      listItemAdapterDelegate.onBindViewHolder(mapper.invoke(item), holder as AdapterDelegateViewHolder<Old>, payloads)
    }

    override fun onCreateViewHolder(parent: ViewGroup) = listItemAdapterDelegate.onCreateViewHolder(parent)
  }
}

Screenshot 2020-08-25 at 06 26 25

@vanniktech
Copy link
Contributor Author

I forked and made those methods public :/

Is there any update from your side?

@sockeqwe
Copy link
Owner

sockeqwe commented Nov 13, 2020 via email

@vanniktech
Copy link
Contributor Author

No longer need this 🤷

@vanniktech vanniktech closed this Mar 22, 2021
@vanniktech vanniktech deleted the patch-1 branch March 22, 2021 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants