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

Payload processing refactoring #337

Closed
wants to merge 4 commits into from
Closed

Conversation

vbuberen
Copy link
Collaborator

@vbuberen vbuberen commented May 4, 2020

📄 Context

ConcatAdapter seems like a very suitable component for Chucker and its payload RecyclerView. Having 3 separate adapters for each part of payload (headers, text body or image body) can help us to incorporate lots of improvements, like #324 or #195 much easier.

For example, we could get rid of having all headers formatted as a single String with HTML markup as it is done now (this code is already in PR) and use just raw names and values, which gives us more flexibility like being able to set spans however we need it.

I came to this idea after doing some work on search improvements for #195. Moreover, as we already discussed in some PRs as a side topic we need to move payload processing for output into a ViewModel.
My intention here is to have 3 lazily initialised adapters which we will add into parent only if there is a corresponding content (like add ImageAdapter only if there is an image in a payload).
Also, I am going to switch to something similar to MVI approach to have states which view observes and renders (loading, data, empty).

This PR is in early preview, so no need for review. However, feedback is welcome.
I made it visible to everyone, since it might help some contributors to see where this part of the library is heading and to not produce too much conflicts.

📝 Changes

  • Changed PayloadAdapter to be a new MergeAdapter
  • Added 3 separate adapters for headers, text body, image body.
    to be continued...

📎 Related PR

Will add later

@vbuberen vbuberen mentioned this pull request Jul 4, 2020
Comment on lines +67 to +69
fun CharSequence.applyBoldSpan() = SpannableString(this).apply {
setSpan(StyleSpan(Typeface.BOLD), 0, this.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be ok to name it .bold()?

It could be called as "${headerItem.name}: ".bold().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.


internal class TransactionHeadersAdapter : RecyclerView.Adapter<TransactionHeadersAdapter.HeaderViewHolder>() {

private val headers = arrayListOf<HttpHeader>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generaly speaking, I don't get why we should use arrayListOf instead of mutableListOf.

Comment on lines +49 to +51
private val headerAdapter by lazy { TransactionHeadersAdapter() }
private val bodyAdapter by lazy { TransactionBodyAdapter() }
private val imageAdapter by lazy { TransactionImageAdapter() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 adapter are not yet called, is it normal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a draft PR, it is not finalized as well as not meant for review.

@vbuberen
Copy link
Collaborator Author

Looks like RecyclerView update isn't a priority for Google now, because 1.2.0 is still in alpha.
I doubt that we get a stable version any time soon, so this PR will have to live quite a long time gathering some conflicts etc.

Closing till we have a stable RecyclerView version with ConcatAdapter.

@vbuberen vbuberen closed this Nov 15, 2020
@vbuberen vbuberen deleted the payload_refactoring branch February 14, 2021 08:13
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