@Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); if(mGDM != null){ mGDM.attachAll(); } } @Override
/** * attach a group of 'mediator-delegate' to GroupDataManager. * * @param sa the group of 'mediator-delegate' * @param gps the group properties. * @param <T> the data type * @param <D> the mediator delegate type * @return the GroupDataManager. */ public static <T, D extends MediatorDelegate<T>> GroupDataManager<T> of(SparseArray<D> sa, List<GroupProperty> gps) { GroupDataManager<T> gdm = new GroupDataManager<>(sa); gdm.prepare(gps); return gdm; }
@Override protected void setUp() throws Exception { super.setUp(); List<TestState> mDatas = createDatas(); List<GroupDataManager.MediatorDelegate<TestState>> list = new ArrayList<>(); this.mList = list; for (final TestState data : mDatas) { list.add(new GroupDataManager.MediatorDelegate<TestState>() { final DataMediator<TestState> mediator = DataMediatorFactory.createDataMediator(data); @Override public DataMediator<TestState> getDataMediator() { return mediator; } }); } GroupDataManager.GroupProperty gp = new GroupDataManager.GroupProperty(); gp.setType(GroupDataManager.TYPE_MUTEX); gp.setProperty(TestState.PROP_state); gp.setValue(FOCUS_VALUE); gp.setOppositeValue(OPPISITE_VALUE); GroupDataManager.of(list, Arrays.asList(gp)).attachAll(); }
/** * create data-binding adapter for target data. * * @param list the list data to show in {@linkplain RecyclerView}. * @param mayRemoveOrAddItem true if you may want to remove/add item. false otherwise. * this is help of data-binding, if you really want to remove/add item. */ public DataBindingRecyclerAdapter(List<T> list, boolean mayRemoveOrAddItem) { this.mItemManager = new AdapterItemManager<T>(this, this, list); if (mayRemoveOrAddItem) { mItemManager.setAdapterDataObserver2(new InternalDataObserver()); } Gps gps = DataMediatorFactory.createGps(getActuallyParameterClass()); this.mGDM = gps == null ? null : GroupDataManager.of(mBinderMap, gps.getGroupProperties()); } @SuppressWarnings("unchecked")
private void setMutexValue(GroupProperty target, MediatorDelegate<T> md) { DataMediator<T> mediator = md.getDataMediator(); //before mutex we should just remove this callback for reduce unnecessary callback. mediator.removeDataMediatorCallback(mCallback); T proxy = mediator.getDataProxy(); Object value = ReflectUtils.getValue(target.prop, proxy); setMutexValue0(target, proxy, value); //restore mediator.addDataMediatorCallback(mCallback); }
private void onPropertyValueChanged(T data, Property prop, Object oldValue, Object newValue) { //currently only support int and long. boolean. if (prop.getType() != int.class && prop.getType() != long.class && prop.getType() != boolean.class) { return; } List<GroupProperty> list = mPropMap.get(TYPE_MUTEX); //process mutex if (!Predicates.isEmpty(list)) { if (newValue instanceof Boolean) { boolean value = Boolean.valueOf(newValue.toString()); for (GroupProperty gp : list) { if (gp.prop == prop && mutex(gp, data, value ? 1 : 0)) { break; } } } else { long value = Long.valueOf(newValue.toString()); for (GroupProperty gp : list) { if (gp.prop == prop && mutex(gp, data, value)) { break; } } } } }
@Override public void onDetachedFromRecyclerView(RecyclerView recyclerView) { super.onDetachedFromRecyclerView(recyclerView); if(mGDM != null){ mGDM.detachAll(); } }
@Override protected void setUp() throws Exception { super.setUp(); List<TestState> mDatas = createDatas(); List<GroupDataManager.MediatorDelegate<TestState>> list = new ArrayList<>(); this.mList = list; for (final TestState data : mDatas) { list.add(new GroupDataManager.MediatorDelegate<TestState>() { final DataMediator<TestState> mediator = DataMediatorFactory.createDataMediator(data); @Override public DataMediator<TestState> getDataMediator() { return mediator; } }); } GroupDataManager.GroupProperty gp = new GroupDataManager.GroupProperty(); gp.setType(GroupDataManager.TYPE_MUTEX); gp.setProperty(TestState.PROP_state); gp.setValue(FOCUS_VALUE); gp.setOppositeValue(OPPISITE_VALUE); GroupDataManager.of(list, Arrays.asList(gp)).attachAll(); }
private void setMutexValue(GroupProperty target, MediatorDelegate<T> md) { DataMediator<T> mediator = md.getDataMediator(); //before mutex we should just remove this callback for reduce unnecessary callback. mediator.removeDataMediatorCallback(mCallback); T proxy = mediator.getDataProxy(); Object value = ReflectUtils.getValue(target.prop, proxy); setMutexValue0(target, proxy, value); //restore mediator.addDataMediatorCallback(mCallback); }
private void onPropertyValueChanged(T data, Property prop, Object oldValue, Object newValue) { //currently only support int and long. boolean. if (prop.getType() != int.class && prop.getType() != long.class && prop.getType() != boolean.class) { return; } List<GroupProperty> list = mPropMap.get(TYPE_MUTEX); //process mutex if (!Predicates.isEmpty(list)) { if (newValue instanceof Boolean) { boolean value = Boolean.valueOf(newValue.toString()); for (GroupProperty gp : list) { if (gp.prop == prop && mutex(gp, data, value ? 1 : 0)) { break; } } } else { long value = Long.valueOf(newValue.toString()); for (GroupProperty gp : list) { if (gp.prop == prop && mutex(gp, data, value)) { break; } } } } }
/** * attach a group of 'mediator-delegate' to GroupDataManager. * * @param array the group of 'mediator-delegate' * @param gps the group properties. * @param <T> the data type * @param <D> the mediator delegate type * @return the GroupDataManager. */ public static <T, D extends MediatorDelegate<T>> GroupDataManager<T> of(D[] array, List<GroupProperty> gps) { GroupDataManager<T> gdm = new GroupDataManager<>(array); gdm.prepare(gps); return gdm; }
/** * attach a group of 'mediator-delegate' to GroupDataManager. * * @param sa the group of 'mediator-delegate' * @param gps the group properties. * @param <T> the data type * @param <D> the mediator delegate type * @return the GroupDataManager. */ public static <T, D extends MediatorDelegate<T>> GroupDataManager<T> of(SparseArray<D> sa, List<GroupProperty> gps) { GroupDataManager<T> gdm = new GroupDataManager<>(sa); gdm.prepare(gps); return gdm; }
/** * attach a group of 'mediator-delegate' to GroupDataManager. * * @param delegateList the group of 'mediator-delegate' * @param gps the group properties. * @param <T> the data type * @param <D> the mediator delegate type * @return the GroupDataManager. */ public static <T, D extends MediatorDelegate<T>> GroupDataManager<T> of(List<D> delegateList, List<GroupProperty> gps) { GroupDataManager<T> gdm = new GroupDataManager<>(delegateList); gdm.prepare(gps); return gdm; }
/** * attach a group of 'mediator-delegate' to GroupDataManager. * * @param array the group of 'mediator-delegate' * @param gps the group properties. * @param <T> the data type * @param <D> the mediator delegate type * @return the GroupDataManager. */ public static <T, D extends MediatorDelegate<T>> GroupDataManager<T> of(D[] array, List<GroupProperty> gps) { GroupDataManager<T> gdm = new GroupDataManager<>(array); gdm.prepare(gps); return gdm; }
/** * attach a group of 'mediator-delegate' to GroupDataManager. * * @param delegateList the group of 'mediator-delegate' * @param gps the group properties. * @param <T> the data type * @param <D> the mediator delegate type * @return the GroupDataManager. */ public static <T, D extends MediatorDelegate<T>> GroupDataManager<T> of(List<D> delegateList, List<GroupProperty> gps) { GroupDataManager<T> gdm = new GroupDataManager<>(delegateList); gdm.prepare(gps); return gdm; }