Android recyclerview, databinding and sub view animation -
could me find proper way without leak animate recylcerview's item's sub item?
i want create 2 level drawer menu, menu items in recyclerview created adapter. of menu items contain sub items, , items can open arrow @ end add sub items list below parent item. want animate arrows rotate 180 degree when adapter detects parent item have open/close , show/remove sub items.
the whole thing working i'm not happy solution of animation. :(
what tricky part i'm using databinding fill item's data.
here's class contains data:
public class menuitem extends baseobservable { public observablefield<string> name = new observablefield<>(); public observableboolean selected = new observableboolean(false); public observableboolean issubitem = new observableboolean(false); public menuitem parent; public list<menuitem> subitems = new arraylist<>(0); private draweradapter.ondraweritemclicklistener listener; /* it's potencial leak */ public view arrow; ..... public void animatearrow(boolean isopen) { if(arrow == null) return; float degrees = isopen ? 180f : 0f; arrow.animate().roatate(degrees).setduration(300).start(); } }
here's viewholder:
public class draweritemholder extends recyclerview.viewholder { public draweritembinder ui; public draweritemholder(view itemview) { super(itemview); ui = databindingutil.bind(itemview); } }
here's how bind viewholder:
@override public void onbindviewholder(draweritemholder holder, int position) { menuitem item = items.get(position); if(!item.subitems.isempty()) item.arrow = holder.ui.arrow; holder.ui.setdata(item); }
i attach arrow view items has sub item.
and when adapter decides open item calls method:
private void opencategories(menuitem item) { ... /* animate close state opened category's arrow */ if(openedcategory != null) openedcategory.animateopener(false); openedcategory = item; /* animate opened state newly opened category */ openedcategory.animateopener(true); notifyitemrangeinserted(...); }
the openedcategory menuitem, reference parent item open.
and when want close item calls this:
private void closecategories() { if (openedcategory == null) return; ... notifyitemrangeremoved(...); /* animate closed state opened category's arrow */ openedcategory.animateopener(false); openedcategory = null; }
so problem this. how can animate subview of parent items without leaking arrow views holding reference them in menuitem class?
best regards!
Comments
Post a Comment