binding-collection-adapter icon indicating copy to clipboard operation
binding-collection-adapter copied to clipboard

BaseAdapter#isEnabled support

Open r-gurzkowski opened this issue 9 years ago • 9 comments

Hey,

I was wandering is it possible to easly use BaseAdapter#isEnabled function. I was looking at the source code of the BindingListViewAdapter however no straight forward solution comes into my mind. Any hints?

r-gurzkowski avatar Dec 09 '15 17:12 r-gurzkowski

Can you give an example of where you are trying to call it? You can just get a reference to the adapter and call it. Or you can subclass the adapter and have access to it that way.

evant avatar Dec 09 '15 18:12 evant

Looked up how that method is used, seems like a reasonable thing to add. In the mean time, subclassing the adapter should work fine.

evant avatar Dec 10 '15 16:12 evant

Added in 1.0.0 see README for details.

evant avatar Dec 13 '15 22:12 evant

Great news. Do you have any plans to add change observer in order to invalidate adapter data if itemEnabled field has changed?

r-gurzkowski avatar Dec 13 '15 22:12 r-gurzkowski

Not sure I understand, could you give an example where the current implementation does not work?

evant avatar Dec 14 '15 22:12 evant

Correct me if I am wrong, because I did not try latest version, i just read the code. If I want to disable one of the items in runtime (eg. result of some validation) I have will change itemEnabled based on some viewmodel property:

adapter.setItemEnabled(new BindingListViewAdapter.ItemEnabled<ProductViewModel>() {
    @Override
    public boolean isEnabled(int position, ProductViewModel product) {
        return product.isInStock
    }
});

Then if isInStock will change after populating a list, will adapter be notified in order to update view state (notifyDataSetChanged)?

r-gurzkowski avatar Dec 15 '15 13:12 r-gurzkowski

Alright, I'll see what you mean. I'm a bit hesitant on forcing a dataSetChange if it might not actually be needed. I'm reopening and I'll investigate this further.

evant avatar Dec 16 '15 22:12 evant

Note your example would not trigger a notifyDataSetChanged since it's only changing the contents of an item.

evant avatar Dec 16 '15 22:12 evant

Thank you for your support. I guess current implementation will be suitable for most cases.

I think it is a good idea to update a documentation with the information when exactly BindingListViewAdapter.ItemEnabled interface will be queried.

r-gurzkowski avatar Dec 17 '15 15:12 r-gurzkowski