/** * create binder for target module class.. * @param moduleClass the module data class. * @param <T> the module data type * @return the binder. * @since 1.0.8 */ public static <T> Binder<T> createBinder(Class<T> moduleClass){ return createBinder(createDataMediator(moduleClass)); } /**
/** * create data-binding view holder for target item view. * * @param itemView the item view */ public DataBindingViewHolder(View itemView) { super(itemView); onPreCreateDataBinding(itemView); mDataBinding = DataMediatorFactory.createDataBinding(this); }
/** * create module data for target interface class. * @param clazz the interface class. * @param <T> the module type. must be interface. * @return the module data. */ public static <T> T createData(Class<T> clazz){ try { return (T) Class.forName(getImplClassName(clazz)).newInstance(); } catch (Exception e) { throw new IllegalArgumentException("can't create module for class("+ clazz.getName() + ")! have you make project or rebuild ? ", e); } }
/** * create date mediator by target module. * @param t the module data * @param <T> the module data type * @return the data mediator. * @since 1.1.3 */ public static <T> DataMediator<T> createDataMediator(T t){ return createDataMediator(null, t); }
public void test1(){ DataMediator<TestItem> root = DataMediatorFactory.createDataMediator(TestItem.class); root.getData().setTestItem_6(DataMediatorFactory.createData(TestParcelableData.class)); root.inflatePropertyChain("testItem_6.test_int"); final String pName = "test_int"; DataMediator<TestParcelableData> dm_child = DataMediatorFactory.createDataMediator( root, root.getData().getTestItem_6()); dm_child.addDataMediatorCallback(callback);
@Override protected void onInit(Context context, Bundle savedInstanceState) { initAdapter(); mBinder = DataMediatorFactory.createBinder(RecyclerListBind.class); onBindListItems(mBinder); }
public static TestGroupProperty createItem(){ TestGroupProperty data = DataMediatorFactory.createData(TestGroupProperty.class); data.setState(0); return data; }
/** * create data mediator for target interface class. * @param clazz the interface class * @param <T> the module type * @return the proxy helper for target module type. */ public static <T> DataMediator<T> createDataMediator(Class<T> clazz){ T t = createData(clazz); try { Class<?> proxyClazz = Class.forName(getProxyClassName(clazz)); return new DataMediator<T>((BaseMediator<T>) proxyClazz.getConstructor(clazz).newInstance(t)); } catch (Exception e) { throw new IllegalArgumentException("can't create module proxy for class("+ clazz.getName() + ")! have you make project or rebuild ? " ,e); } }
/** * create expression context by target module class. * @param clazz the module class * @return the expression context. * @since 1.4.5 */ public static ExpreEvaluator.ExpreContext createExpreContext(Class<?> clazz){ return createModuleRelativeObject(clazz, "_$ExpreContext"); } /**
/** * get the impl class name of interface which is generate by data-mediator. * @param interClazz the interface class. * @param <T> the data module type * @return the impl class name. * @since 1.1.3 */ public static <T> String getImplClassName(Class<T> interClazz){ return checkAndGetName(interClazz) + SUFFIX_IMPL; } /**
private void applyProperty(Property main, Property prop, Object newValue, Object proxy, ExpreEvaluator eval) { final String expre = connector.connect((BaseMediator<?>) proxy, main, prop); ExpreEvaluator.ExpreContext context = DataMediatorFactory.createExpreContext(proxy.getClass()); if(context == null){ throw new ExpreEvaluator.ExpreEvaluatorException("create ExpreContext failed .has your module declare @ImportDesc ?"); } //add newValue. context.addVariable(main.getName(), newValue); Object value = eval.evaluate(context, expre); ReflectUtils.setValue(prop, proxy, value); } }
/** * create date mediator by target module. * @param t the module data * @param <T> the module data type * @return the data mediator. * @since 1.1.3 */ public static <T> DataMediator<T> createDataMediator(T t){ return createDataMediator(null, t); }
@Override protected void onInit(Context context, Bundle savedInstanceState) { Binder<TestSelfMethod> binder = DataMediatorFactory.createBinder(TestSelfMethod.class); //bind property to textView binder.bindText(TestSelfMethod.PROP_text, mTv); //get proxy mProxy = binder.getDataProxy(); }
private static Student createItem(){ Student data = DataMediatorFactory.createData(Student.class); data.setAge(sRan.nextInt(10001)); data.setName("google__" + sRan.nextInt(100)); return data; } @NonNull
/** * create data mediator for target interface class. * @param clazz the interface class * @param <T> the module type * @return the proxy helper for target module type. */ public static <T> DataMediator<T> createDataMediator(Class<T> clazz){ T t = createData(clazz); try { Class<?> proxyClazz = Class.forName(getProxyClassName(clazz)); return new DataMediator<T>((BaseMediator<T>) proxyClazz.getConstructor(clazz).newInstance(t)); } catch (Exception e) { throw new IllegalArgumentException("can't create module proxy for class("+ clazz.getName() + ")! have you make project or rebuild ? " ,e); } }
/** * create 'Fgs' represent the family group property description by target module class. * @param clazz the module class * @return the Fgs * @since 1.4.5 */ public static FamilyManager.Fgs createFgs(Class<?> clazz){ return createModuleRelativeObject(clazz, "_$FGS"); } /**
/** * get the impl class name of interface which is generate by data-mediator. * @param interClazz the interface class. * @param <T> the data module type * @return the impl class name. * @since 1.1.3 */ public static <T> String getImplClassName(Class<T> interClazz){ return checkAndGetName(interClazz) + SUFFIX_IMPL; } /**
private void applyProperty(Property main, Property prop, Object newValue, Object proxy, ExpreEvaluator eval) { final String expre = connector.connect((BaseMediator<?>) proxy, main, prop); ExpreEvaluator.ExpreContext context = DataMediatorFactory.createExpreContext(proxy.getClass()); if(context == null){ throw new ExpreEvaluator.ExpreEvaluatorException("create ExpreContext failed .has your module declare @ImportDesc ?"); } //add newValue. context.addVariable(main.getName(), newValue); Object value = eval.evaluate(context, expre); ReflectUtils.setValue(prop, proxy, value); } }
/** * create binder for target module data. * @param module the module data. * @param <T> the module data type * @return the binder. * @since 1.4.0 */ public static <T> Binder<T> createBinder(T module){ return createBinder(createDataMediator(module)); }
/** * <p><h2>use {@linkplain #createDataMediator(Object)} instead.</h2></p> * wrap the module data to data mediator. * @param t the module data. * @param <T> the module data type * @return the data mediator . * @see DataMediator */ @Deprecated public static <T> DataMediator<T> wrapToDataMediator(T t){ return createDataMediator(t); }