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

New Variant with View Binding Support #322

Closed
lkishor opened this issue Feb 12, 2020 · 6 comments
Closed

New Variant with View Binding Support #322

lkishor opened this issue Feb 12, 2020 · 6 comments

Comments

@lkishor
Copy link
Contributor

lkishor commented Feb 12, 2020

Many thanks to @lisawray and the community to create and maintain this library.👏

Now that Android Studio 3.6 ships with ViewBinding. A annotation processing free option for generating Layout bindings.

It will be great to have an option to use Groupie with it.

I can put some effort and create a PR if needed.

@lkishor lkishor added enhancement waiting for owners Waiting on an answer by project owners labels Feb 12, 2020
@ValCanBuild ValCanBuild added PRs Welcome Any pull requests to address this issue would be awesome and removed waiting for owners Waiting on an answer by project owners labels Feb 12, 2020
@ValCanBuild
Copy link
Collaborator

PRs for this are welcome 👍

@lkishor
Copy link
Contributor Author

lkishor commented Feb 12, 2020

It is rather simple at first glance, Though needed opinion on how to name the classes:

BindableItem -> ViewBindableItem?
GroupieViewHolder -> VBViewHolder?

Also, in BindableItem

@NonNull
@Override
public GroupieViewHolder<T> createViewHolder(@NonNull View itemView) {
    T viewDataBinding = DataBindingUtil.bind(itemView);
    return new GroupieViewHolder<>(viewDataBinding);
}

DataBindingUtil is not available, so we will have to provide an abstract method to create new instance of T
Something like

public abstract T initBinding(@NonNull View itemView);

@NonNull
@Override
public VBViewHolder<T> createViewHolder(@NonNull View itemView) {
    T viewBinding = initBinding(itemView);
    return new VBViewHolder<>(viewBinding);
}

So the user will now have to provide implementation of 1 more method.

Is this acceptable, or is there an alternate option?

@aoben10
Copy link

aoben10 commented Feb 18, 2020

I like this idea @lkishor

@ValCanBuild
Copy link
Collaborator

I'm open to reviewing a PR on this, though I don't like asking the user to provide one more method - would there be a way around this? I've not read too much into how Viewbinding works or how it's best used.

@aoben10
Copy link

aoben10 commented Feb 21, 2020

Groupie's BindableItem relies on DataBindingUtil#bind to create a subclass of the ViewDataBinding. There's no utility to create an instance of ViewBinding so the only way I can think of would be for the user to provide this via an abstract method

@ValCanBuild
Copy link
Collaborator

Now implemented in 2.8.0 - please give it and try and give feedback. Thanks again @nashcft

@ValCanBuild ValCanBuild removed the PRs Welcome Any pull requests to address this issue would be awesome label Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants