mikepenz / MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
https://mikepenz.dev
Apache License 2.0
11.67k stars 2.05k forks source link

[6.1.2] Log contains error log message #2789

Closed panovvitalik closed 1 year ago

panovvitalik commented 1 year ago
E FastAdapter: The bindView method of this item should set the `Tag` on its itemView (https://github.com/mikepenz/FastAdapter/blob/develop/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java#L189)

I reopen bug: #2729

You wrote "use kotlin", but I can't use kotlin version lib due to this bug: #2786

You wrote "use kotlin classes inside java project", but I can't migrate these classes from java to kotlin.

Now I try to extend all DrawerItem.... classes and add viewHolder.itemView.setTag(R.id.fastadapter_item, this);

public class ExpandableDrawerItemBase extends ExpandableDrawerItem {
    @Override
    public void bindView(ViewHolder viewHolder, List payloads) {
        viewHolder.itemView.setTag(R.id.fastadapter_item, this);
        super.bindView(viewHolder, payloads);
    }
}

But it doesnt work :(

How can I resolve this issue? Do you have java sources for 6.1.2 lib?

Details [ ] Used library version: com.mikepenz:materialdrawer:6.1.2

[ ] Used support library version: 'androidx.legacy:legacy-support-v4:1.0.0' 'androidx.legacy:legacy-support-v4:1.0.0' 'androidx.legacy:legacy-support-v13:1.0.0'

[ ] Used gradle build tools version: com.android.tools.build:gradle:7.3.1

[ ] Android Studio version: Android Studio Dolphin | 2021.3.1 Patch 1

How can I resolve this issue?

mikepenz commented 1 year ago

You can find the old java sources of the project here: https://github.com/mikepenz/MaterialDrawer/tree/v6.1.2 v6.x was still depending on the FastAdapter v3.3.0 -> https://github.com/mikepenz/FastAdapter/blob/v3.3.0/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java

The error itself is logged from here: https://github.com/mikepenz/FastAdapter/blob/v3.3.1/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java#L56

Which is expecting the item to be found via: https://github.com/mikepenz/FastAdapter/blob/v3.3.1/library-core/src/main/java/com/mikepenz/fastadapter/FastAdapter.java#L1422

Normally this should already get set here: https://github.com/mikepenz/FastAdapter/blob/v3.3.1/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java#L25C3-L34

Versions below v9 are provided as-is and I sadly can't provide any major support for these.

panovvitalik commented 1 year ago

You can find the old java sources of the project here: https://github.com/mikepenz/MaterialDrawer/tree/v6.1.2 v6.x was still depending on the FastAdapter v3.3.0 -> https://github.com/mikepenz/FastAdapter/blob/v3.3.0/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.java

The error itself is logged from here: https://github.com/mikepenz/FastAdapter/blob/v3.3.1/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java#L56

Which is expecting the item to be found via: https://github.com/mikepenz/FastAdapter/blob/v3.3.1/library-core/src/main/java/com/mikepenz/fastadapter/FastAdapter.java#L1422

Normally this should already get set here: https://github.com/mikepenz/FastAdapter/blob/v3.3.1/library-core/src/main/java/com/mikepenz/fastadapter/listeners/OnBindViewHolderListenerImpl.java#L25C3-L34

Versions below v9 are provided as-is and I sadly can't provide any major support for these.

As I see you set IItem objects:

IItem item = fastAdapter.getItem(position);
...
//set the R.id.fastadapter_item tag of this item to the item object (can be used when retrieving the view)
viewHolder.itemView.setTag(R.id.fastadapter_item, item);

Always item is PrimaryDrawerItem or SecondaryDrawerItem, and not a FastAdapter object. But you try to find for FastAdapter class:

Object item = holder.itemView.getTag(com.mikepenz.fastadapter.R.id.fastadapter_item);
            if (item instanceof FastAdapter) {
                return (Item) item;
            }
        }
        return null; // !!!! THIS LINE WORKS ALL THE TIME !!!!

Is there any way to fix the issue?

p.s. Of course, except getting full sources and copy/paste inside my project

panovvitalik commented 1 year ago

The solution I have found is below. I have created this class:

public class OnBindViewHolderListenerImplBase extends OnBindViewHolderListenerImpl {
        @Override
        public void unBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
            IItem item = FastAdapter.getHolderAdapterItemTag(viewHolder);
            if (item != null) {
                super.unBindViewHolder(viewHolder, position);
            }
        }
    }

And use this class this way:

Drawer mMenu;
mMenu.getAdapter().withOnBindViewHolderListener(new OnBindViewHolderListenerImplBase());

This is resolved my issue.

But I'm afraid maybe I have broken something else? Or it's correct solution?

mikepenz commented 1 year ago

@panovvitalik nothing should be broken with this approach, it may only be slightly less efficient as getHolderAdapterItemTag(viewHolder); is being called twice

panovvitalik commented 1 year ago

@panovvitalik nothing should be broken with this approach, it may only be slightly less efficient as getHolderAdapterItemTag(viewHolder); is being called twice

Ok. Thank you for your help!