Skip to content

Releases: LightSun/data-mediator

support bind property chain

25 Nov 15:31
Compare
Choose a tag to compare

New Features

  • support bind property chain . like below:
 @@BindBackground("viewBind.background")
   View mV_bg;
 @@BindBackgroundColor("viewBindList[0].backgroundColor")
    View mV_bg_color;
  • add useful methods for property chain . like
// this is used for attach inflate callbacks from property chain.
static <T> DataMediator<T> createDataMediator(DataMediator<?> root, T t)
//inflate callbacks from property chain.
void inflatePropertyChain(String propertyChain)
//re inflate callbacks from property chain.(which was already failed previous)
 boolean reinflatePropertyChains()
// should reinflate property chain. if  any was failed previous
boolean shouldReinflatePropertyChains()
  • if you want see some demos about above. please click here

Optimise

  • fix issue #3 .
  • for use convenient, make default flags of @field to 'FieldFlags.FLAGS_MAIN_SCOPES_3'
    which not contains hash.
  • optimise 'Collector' add/change method for BaseDataMediator. see below.
 void beginBatchedDispatches(int collectorFlags)
void dropBatchedDispatches()
void endBatchedDispatches(final @Nullable PropertyEventReceiver receiver)

Release libs

    compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.2.2'
    compile 'com.heaven7.java.data.mediator:data-mediator:1.4.4'
    annotationProcessor 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.4.4'

  //not changed libs
    compile 'com.heaven7.java.data.mediator.support.gson:data-mediator-support-gson:1.0.5'
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.1.4'

add new annotations for Data-Binding

20 Nov 03:01
Compare
Choose a tag to compare

New Features

  • add new annotations for DataBinding.
    • simple mock like this.
    @BindAny(value = "prop", method = "bindAddText")
    @BindsAny(value = {"prop1", "prop2"}, methods = {"bindAddText1", "bindAddText2"})
    TextView mTv_supplier;

    @BindTextGravity("gravity")
    @BindHighlightColor("highLightColor")
    @BindHintText("hintText")
    @BindHintTextRes("hintTextRes")
    @BindHintTextColor("hintTextColor")
    @BindHintTextColorRes("hintTextColorRes")
    TextView mTv_hints;
    @BindAny(value = "prop", method = "bindAddText")
    @BindsAny(value = {"prop1", "prop2"}, methods = {"bindAddText1", "bindAddText2"})
    TextView mTv_supplier;

    @BindTextGravity("gravity")
    @BindHighlightColor("highLightColor")
    @BindHintText("hintText")
    @BindHintTextRes("hintTextRes")
    @BindHintTextColor("hintTextColor")
    @BindHintTextColorRes("hintTextColorRes")
    TextView mTv_hints;
 * actually demo like this.
/**
 * 第二种方式: 绑定一组属性到view
 * Created by heaven7 on 2017/11/13 0013.
 */
@BindMethodSupplierClass(BindMethodSupplier.DefaultBindMethodSupplier2.class)
public class TestBindArrayPropertyToOneView2 extends BaseActivity {

    //bind array properties to a TextView.
    //relative to @BindsTextView , @BindsAny has greater freedom(翻译: BindsAny注解有更大的自由度).
    // but it must use with @BindMethodSupplierClass.(翻译: 但是他必须搭配注解BindMethodSupplierClass.)
    @BindView(R.id.tv)
    @BindsAny(value = {"textSizeRes", "textRes"},    //any count you want
            methods = {"bindTextSizeRes", "bindTextRes"})
    @BindAny(value = "textColorRes", method = "bindTextColorRes") //only one property
    TextView mTv;

    private ResHelper mHelper = new ResHelper();
    private Binder<TextViewBind> mBinder;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_bind_array_prop_to_view;
    }

    @Override
    protected void onInit(Context context, Bundle savedInstanceState) {
        mHelper.init(context);

        TextViewBind data = DataMediatorFactory.createData(TextViewBind.class);
        mBinder = DataMediatorFactory.createDataBinding(this)
                .bind(data, 0, PropertyInterceptor.NULL);
    }

    @OnClick(R.id.bt_text_color)
    public void onClickChangeTextColorRes(View v) {
        mBinder.getDataProxy().setTextColorRes(mHelper.toggleTextColorRes());
    }

    @OnClick(R.id.bt_text_size)
    public void onClickChangeTextSizeRes(View v) {
        mBinder.getDataProxy().setTextSizeRes(mHelper.toggleTextSizeRes());
    }

    @OnClick(R.id.bt_text)
    public void onClickChangeTextRes(View v) {
        mBinder.getDataProxy().setTextRes(mHelper.toggleTextRes());
    }
}

Release Libs

 //changed libs,  Note:  'annotationProcessor ' must be replaced with 'apt' if gradle version lower 4.1.
    compile 'com.heaven7.java.data.mediator:data-mediator:1.4.3'
    annotationProcessor 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.4.3'
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.1.4'
    compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.2.1'

  //not changed libs.
    compile 'com.heaven7.java.data.mediator.support.gson:data-mediator-support-gson:1.0.5'

add convertor plugin and fix issue #2

15 Nov 03:23
ce44a07
Compare
Choose a tag to compare

New Features

  • add convertor plugin which can convert java bean to the module of Data-mediator. see attachment.
    named 'data-mediator-convertor-intellij-plugin.jar'

Optimise

  • plugin of 'data-mediator-intellij-plugin' update to 1.1. see attachment.

Bug fix

Release libs

 //changed libs
    compile 'com.heaven7.java.data.mediator:data-mediator:1.4.2'

  //not changed libs.
 // Note:  'annotationProcessor ' must be replaced with 'apt' if gradle version lower 4.1.
   annotationProcessor 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.4.1'
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.1.3'
    compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.2.0'
    compile 'com.heaven7.java.data.mediator.support.gson:data-mediator-support-gson:1.0.5' 

Release Plugin

  • data-mediator-convertor-intellij-plugin.jar. v1.0
  • data-mediator-intellij-plugin.jar. v1.1

support data-binding in adapter. Best partner with 'ButterKnife'

12 Nov 15:47
116e31c
Compare
Choose a tag to compare

New Feature:

  • 1, Binder .add bindList method for it which make ItemManager as parameter.
  • 2, Support data-binding adapter .(support header and footer. support add/remove/change item)
public class TestDatabindingAdapter extends BaseActivity {

    private static final String TAG = "TD adapter";
    private static final Random sRan = new Random();

    @BindView(R.id.rv)
    RecyclerView mRv;

    protected InternalAdapter mAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_test_databinding_adapter;
    }

    @Override
    protected void onInit(Context context, Bundle savedInstanceState) {
        mRv.setLayoutManager(new LinearLayoutManager(context));
        mRv.setAdapter(mAdapter = new InternalAdapter(createItems()));
    }

    //random remove item
    @OnClick(R.id.bt_remove)
    public void onClickRemove(View v){
        AdapterItemManager<Student> manager = mAdapter.getItemManager();
        int itemCount = manager.getItemSize();
        final int index = new Random().nextInt(itemCount - 1);
        Logger.i(TAG, "onClickRemove","index = " + index);
        manager.removeItemAt(index);
    }
    @OnClick(R.id.bt_add)
    public void onClickAdd(View v){
        AdapterItemManager<Student> manager = mAdapter.getItemManager();
        int itemCount = manager.getItemSize();
        final int index = new Random().nextInt(itemCount - 1);
        Logger.i(TAG, "onClickAdd","index = " + index);
        manager.addItem(index, createItem().setAge(1));
    }

    public static List<Student> createItems() {
        sIndex = 0;
        List<Student> list = new ArrayList<>();
        //just mock data
        final int count = 20;
        for (int i =0 ; i< count ; i++){
            list.add(createItem());
        }
        return list;
    }
    public static Student createItem(){
        Student data = DataMediatorFactory.createData(Student.class);
        data.setAge(sIndex ++ );
        data.setName("google__" + sRan.nextInt(100));
        return data;
    }

    private static int sIndex = 0;

    public static class InternalAdapter extends DataBindingRecyclerAdapter<Student> {

        public InternalAdapter(List<Student> mDatas) {
            super(mDatas, true);
        }
        @Override
        public DataBindingViewHolder<Student> onCreateViewHolderImpl(ViewGroup parent, int layoutId) {
            return new InnerViewHolder(LayoutInflater.from(parent.getContext())
                    .inflate(layoutId, parent, false));
        }
        @Override
        protected int getItemLayoutId(int position, Student student) {
            return R.layout.item_test_recycler_list;
        }
    }
    public static class InnerViewHolder extends DataBindingRecyclerAdapter.DataBindingViewHolder<Student>{

        @BindView(R.id.tv_name) @BindText("name")
        TextView mTv_name;

        @BindView(R.id.tv_age) @BindText("age")
        TextView mTv_age;

        public InnerViewHolder(View itemView) {
            super(itemView);
        }

        @Override
        protected void onPreCreateDataBinding(View itemView) {
            ButterKnife.bind(this, itemView);
        }

        @OnClick(R.id.tv_name)
        public void onClickName(View v){
            //here just toast
            Toast.makeText(v.getContext(), "onClickName is called, pos = "
                    + getAdapterPosition2(), Toast.LENGTH_SHORT).show();
        }
        @OnClick(R.id.tv_age)
        public void onClickAge(View v){
            //here just toast
            Toast.makeText(v.getContext(), "onClickAge is called, pos = "
                    + getAdapterPosition2(), Toast.LENGTH_SHORT).show();
        }
        @OnClick(R.id.bt_change_item)
        public void onClickChangeItem(View v){
            final int pos = getAdapterPosition2();
            getDataProxy()
                    .setAge((int) (System.currentTimeMillis() % 99))
                    .setId(pos)
                    .setName("google+__" + pos);
            //Note: no need notifyItemChanged here.
        }
    }
}

Optimise

  • 1, compiler for data-binding support non static inner class.
  • 2, add beginBatchedDispatches. and endBatchedDispatches for BaseMediator and DataMediator.
  • 3, others.

Release libs:

    //changed libs,  Note:  'annotationProcessor ' must be replaced with 'apt' if gradle version lower 4.1.
    compile 'com.heaven7.java.data.mediator:data-mediator:1.4.1'
    annotationProcessor 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.4.1'
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.1.3'

  //not changed libs.
    compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.2.0'
    compile 'com.heaven7.java.data.mediator.support.gson:data-mediator-support-gson:1.0.5'

Want we see sample ? please see project data-binding-test

support fast data-binding.

08 Nov 02:24
Compare
Choose a tag to compare

New Features

  • 1, data module support nested class now. that means data module can be decorate by ' static'.
  • 2, add member 'generateJsonAdapter' for annotation '@fields'.
  • 3, full support data-binding: annotations, compiler. call. like 'ButterKnife'.
    • 3.1, mock annotation of data-binding like this:
//mock annotation like this:
/**
 * just test generate
 * Created by heaven7 on 2017/11/6 0006.
 */
@BinderFactoryClass(MockBinderFactory.class)
@BinderClass(AndroidBinder.class)
public class MockActivity extends AppCompatActivity {

    @BindsView({"stu_backgroundRes", "stu_visibility", "stu_enable"})
    TextView mTv_name;

    @BindsView({"stu_backgroundRes2", "stu_visibility2"})
    TextView mTv_name2;

    @BindsTextView(value = {"textSizeRes", "textColorRes", "textRes"}, index = 2)
    TextView mTv_3;

    @BindsTextView(value = {"textSizeRes2", "textColorRes2"}, index = 3)
    TextView mTv_4;


    @BindCheckable("checkable")
    CheckBox mcb;

    @BindBackground("v_bg")
    @BindBackgroundColor("v_bgColor")
    @BindBackgroundRes("v_bgRes")
    @BindVisibility("v_visibility")
    @BindEnable("v_enable")
    View mV;

    @BindText("tv_text")
    @BindTextRes("tv_textRes")
    @BindTextSize("tv_textSize")
    @BindTextSizeRes("tv_textSizeRes")
    @BindTextSizePx("tv_textSizePx")
    @BindTextColor("tv_textColor")
    @BindTextColorRes("tv_textColorRes")
    TextView mTv;

    @BindImageUrl("iv_url")
    @BindImageUri("iv_uri")
    @BindImageBitmap("iv_bitmap")
    @BindImageDrawable("iv_drawable")
    @BindImageRes("iv_res")
    ImageView mIv;
}
-3.2,  call demo , like this:
/**
 * test bind image property
 * Created by heaven7 on 2017/11/7.
 */
public class TestImageViewBindActivity extends BaseActivity implements DataBinding.ParameterSupplier {

    @BindView(R.id.iv_url) @BindImageUrl("imageUrl")
    ImageView ivUrl;

    @BindView(R.id.iv_bitmap) @BindImageBitmap("imageBitmap")
    ImageView ivBitmap;

    @BindView(R.id.iv_drawable) @BindImageDrawable("imageDrawable")
    ImageView ivDrawable;

    @BindView(R.id.iv_res) @BindImageRes("imageRes")
    ImageView ivRes;

    private ResHelper mResHelper = new ResHelper();
    private Binder<ImageViewBind> mBinder;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_test_image_view_bind;
    }

    @Override
    protected void onInit(Context context, Bundle savedInstanceState) {
        mResHelper.init(context);

        final ImageViewBind data = DataMediatorFactory.createData(ImageViewBind.class);
        mBinder = DataMediatorFactory.createDataBinding(this)
                .bind(data, this, null);
    }
    @OnClick(R.id.bt_url)
    public void onClickUrl(View v){
        mBinder.getDataProxy().setImageUrl(mResHelper.toggleUrl());
    }
    @OnClick(R.id.bt_bitmap)
    public void onClickBitmap(View v){
        mBinder.getDataProxy().setImageBitmap(mResHelper.toggleBitmap());
    }
    @OnClick(R.id.bt_drawable)
    public void onClickDrawable(View v){
        mBinder.getDataProxy().setImageDrawable(mResHelper.toggleDrawable());
    }
    @OnClick(R.id.bt_res)
    public void onClickRes(View v){
        mBinder.getDataProxy().setImageRes(mResHelper.toggleRes());
    }
    @Override //bind imageUrl need pass extra parameter: 'ViewHelper.IImageLoader'
    public Object[] getParameters(Object data, String property) {
        // why here use 'ViewHelper.IImageLoader' ?
        // because the default AndroidBinder use it to load image.
        // if you want change .please override method 'bindImageUrl' and use @BinderClass/@BinderFactoryClass
        return !property.equals("imageUrl") ? null : new Object[]{ mLoader };
    }

    private final ViewHelper.IImageLoader mLoader = new ViewHelper.IImageLoader() {
        @Override
        public void load(String url, final ImageView iv) {
            Glide.with(iv.getContext())
                    .load(url)
                    .into(new SimpleTarget<Drawable>(200, 200) {
                        @Override
                        public void onResourceReady(Drawable resource,
                                                    Transition<? super Drawable> transition) {
                            iv.setImageDrawable(resource);
                        }
                    });
        }
    };

    public static class ResHelper{

       static final String URL_1 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1510078438082&di=a69c86d4cc6ab8c3f83e3d624e41e869&imgtype=0&src=http%3A%2F%2Fimg1.3lian.com%2F2015%2Fa1%2F40%2Fd%2F191.jpg";
       static final String URL_2 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1510078568038&di=d80672939c82b81fa52ad0075e793b22&imgtype=0&src=http%3A%2F%2Fimg17.3lian.com%2Fd%2Ffile%2F201701%2F20%2F70ac16a3c3336a3bc2fb28c147bf2049.jpg";

       int res1;
       int res2;

       Bitmap bitmap1;
       Bitmap bitmap2;

       Drawable drawable1;
       Drawable drawable2;

       boolean useUrl1;
       boolean useRes1;
       boolean useBitmap1;
       boolean useDrawable1;

       void init(Context context){
           final Resources res = context.getResources();
           res1 = R.mipmap.ic_launcher;
           res2 = R.mipmap.ic_launcher_round;
           drawable1 = res.getDrawable(res1);
           drawable2 = res.getDrawable(res2);
           bitmap1 = BitmapFactory.decodeResource(res, res1);
           bitmap2 = BitmapFactory.decodeResource(res, res2);
        }
        String toggleUrl(){
            String result = useUrl1 ? URL_2 : URL_1;
            useUrl1 = !useUrl1;
            return result;
        }
        int toggleRes(){
            int result = useRes1 ? res2 : res1;
            useRes1 = !useRes1;
            return result;
        }
        Bitmap toggleBitmap(){
            Bitmap result = useBitmap1 ? bitmap2 : bitmap1;
            useBitmap1 = !useBitmap1;
            return result;
        }
        Drawable toggleDrawable(){
            Drawable result = useDrawable1 ? drawable2 : drawable1;
            useDrawable1 = !useDrawable1;
            return result;
        }
    }
}
  • 4, support self Binder(annotation is @BinderClass) and BinderFactory(annotation is @BinderFactoryClass).

Optimization.

  • 1, open class 'AndroidBinder'.

    for Binder: change bindTextSize with default unit of 'dip'. add method 'bindTextSizePx' with 'pix' unit.
  • 2, make data-module support static .
  • 3, optimise other libs.

Release libs

    //all changed .
   // if you use gradle version < 4.1 please replace 'annotationProcessor ' to 'apt'.
    compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.2.0'
    compile 'com.heaven7.java.data.mediator:data-mediator:1.4.0'
    annotationProcessor 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.4.0'
    compile 'com.heaven7.java.data.mediator.support.gson:data-mediator-support-gson:1.0.5'
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.1.1'

Next Plans

  • Full support data-binding for adapter.
  • property dependency

add idea plugin and support self methods.

28 Oct 12:30
Compare
Choose a tag to compare

new feature:

  • 1, add idea-plugin for generator property methods and fields.

    • ps: idea-plugin see file: 'data-mediator-intellij-plugin.jar'
  • 2, support self method and const field.

@Fields({
       @Field(propName = "test_self1"),
       @Field(propName = "test_self2", type = int.class)
})
@ImplClass(TestUtil.class) //define the source impl class of self method 
public interface TestSelfMethod1 extends DataPools.Poolable {

 //define a constant field. add annotation @Keep for not effect by idea-plugin(Data-mediator generator)
   @Keep
   int STATE_OK = 1;

   Property PROP_test_self1 = SharedProperties.get("java.lang.String", "test_self1", 0);
   Property PROP_test_self2 = SharedProperties.get("int", "test_self2", 0);

   String getTest_self1();
   TestSelfMethod1 setTest_self1(String test_self11);

   int getTest_self2();
   TestSelfMethod1 setTest_self2(int test_self21);

   @ImplMethod("getStudentId")
   int getId(Student stu, int key);

   //not assigned method name of ImplClass. so use the same name.
   @ImplMethod
   void parseStudent(Student stu, int key);
}

public class TestUtil {
   public static int getStudentId(TestSelfMethod1 tsf, Student stu, int key){
       //do something you want.
       return  0;
   }
   public static void parseStudent(TestSelfMethod1 tsf, Student stu, int key){
       //do thing.
   }
}

Optimizations:

1, full fix the compile bug of multi module.
2, fix hashCode of SparseArray.
fix other bugs.

Release libs

//changed
   compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.1.3'
    compile 'com.heaven7.java.data.mediator:data-mediator:1.3.0'
    apt 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.3.0'
    compile 'com.heaven7.java.data.mediator.support.gson:data-mediator-support-gson:1.0.4'

//not changed.
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.0.5'

解决多module冲突问题

15 Oct 11:14
Compare
Choose a tag to compare

更新日志:
1, 解决多module冲突问题
2, 解决gson-support内部的一个bug.

release libs:

     compile 'com.heaven7.java.data.mediator:data-mediator:1.2.2'
     apt 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.2.2'
     compile 'com.heaven7.java.data.mediator.support.gson:data-mediator-support-gson:1.0.3'

not changed libs:

    compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.0.5'
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.0.5'

全面支持gson注解

13 Oct 16:13
Compare
Choose a tag to compare

1, 此版本的核心功能是支持gson所有注解。(包括自动生成JsonAdapter, SparseArray数据同样支持)
2, 新增全局配置的注解@GlobalConfig.

@GlobalConfig(
        gsonConfig = @GsonConfig(
                version = 2.0,
                forceDisable = false,
                generateJsonAdapter = true
        )
)

3, 用GsonSupport可快速序列化和反序列化。 本框架定义的数据
4, 为了简化开发,@field默认flags = FieldFlags.FLAGS_MAIN_SCOPES_2.

release version:

    compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.0.5'
    compile 'com.heaven7.java.data.mediator:data-mediator:1.2.0'

    apt 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.2.0'
   //gson支持库. 
    compile 'com.heaven7.java.data.mediator.support.gson:data-mediator-support-gson:1.0.2'
```

not changed
```java
   //android 数据绑定和SparseArray Parcel支持库 
   compile 'com.heaven7.android.data.mediator:data-mediator-android:1.0.5'
```

support SparseArray

10 Oct 02:21
Compare
Choose a tag to compare

更新内容:
1, 增加SparseArray相关支持。(SparseArray编辑器及回调)
2, 修复默认String的问题。其他优化: 比如List编辑器优化,BaseMediator优化(避免属性冲突)
3. DataMediator 增加 startActionMode 方便链式结构的数据处理 及数据统计相关

Release versions:

    compile 'com.heaven7.java.data.mediator:data-mediator:1.1.3'
    apt 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.1.3'
   // 如果SparseArray要支持Parcel. 必须添加此库
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.0.5'

not changed lib:

  compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.0.3'

add support for hashCode and equals.

28 Sep 10:42
Compare
Choose a tag to compare

1, FieldFlags:

add FLAG_HASH_EQUALS. 用于字段支持hashCode和equals.

add FLAGS_MAIN_SCOPES_2 在 FLAGS_MAIN_SCOPES的基础上增加FLAG_HASH_EQUALS.
2, 编译层增加 生成,hashCode和equals 方法

release lib:

    compile 'com.heaven7.java.data.mediator:data-mediator:1.1.1'
    apt 'com.heaven7.java.data.mediator.compiler:data-mediator-compiler:1.1.1'

not changed lib:

    compile 'com.heaven7.java.data.mediator.annotation:data-mediator-annotations:1.0.3'
    compile 'com.heaven7.android.data.mediator:data-mediator-android:1.0.2'