data-mediator

Platform compiler gson-support binder SparseArray data-binding
java ok ok need manual impl ok need manual impl
android ok ok ok ok ok
workflow

a data-mediator framework which uses annotation processing to generate boilerplate code for you.
文档还是中文的好

Features

//.............more views

private ResHelper mHelper = new ResHelper();
private Binder<RootModule> rootBinder;
private DataMediator<ViewBind> dm_viewBind;

@Override
protected int getLayoutId() {
    return R.layout.ac_test_view_bind;
}
@Override
protected void onInit(Context context, Bundle savedInstanceState) {
    mHelper.init(context);

    RootModule rootModule = DataMediatorFactory.createData(RootModule.class);
    rootModule.setViewBind(DataMediatorFactory.createData(ViewBind.class));

    //bind data.
    rootBinder = DataMediatorFactory.bind(this, rootModule);
    dm_viewBind = DataMediatorFactory.createDataMediator(
            rootBinder.getDataMediator(), rootModule.getViewBind());
}

@OnClick(R.id.bt_change_bg)
public void onClickChangeBg(View v){
    //change bg(drawable)
    dm_viewBind.getDataProxy().setBackground(mHelper.toggleDrawable());
}
//.............

}

* 13, Plugin support: <br>
  * the plugin of 'data-mediator-intellij-plugin' used to generate module.<br>
     <img src="res/data-mediator-generator.gif" alt="generattor demo"/>
  * the plugin of 'data-mediator-convertor-intellij-plugin' used to convert java bean to the base module of this framework.<br>
     <img src="res/data-mediator-convertor.gif" alt="convertor demo"/>
* 14, support android lint.    
```java
  compile 'com.heaven7.android.data.mediator.lint:dmlint:1.2'

Install

Quick Start.

1,[Optional] global configuration.

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

2, define your data module。eg: if i want to define a student module , and need impl Serializable, Parcelable. And if the student module has age, name, id property。 thus the simple data module can be define like :


@Fields({
        @Field(propName = "age" , type = int.class),
        @Field(propName = "name" , type = String.class),
        @Field(propName = "id" , type = long.class),
})
public interface Student extends Serializable, Parcelable{
}

3, use 'data-mediator-intellij-plugin' generate code, hot key like alt + insert. (you should instanll the plugin , see release).

4, call sample (from project(data-mediator-demo) TestPropertyChangeActivity

/**
 * listen property change demo
 * Created by heaven7 on 2017/9/18 0018.
 */
public class TestPropertyChangeActivity extends BaseActivity {

    @BindView(R.id.tv_desc)
    TextView mTv_desc;

    @BindView(R.id.bt_set_text_on_TextView)
    Button mBt_changeProperty;
    @BindView(R.id.bt_set_text_on_mediator)
    Button mBt_temp;

    DataMediator<Student> mMediator;

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

    @Override
    protected void onInit(Context context, Bundle savedInstanceState) {
        mBt_changeProperty.setText("click this to change property");
        mBt_temp.setVisibility(View.GONE);

        //create data mediator from data module
        mMediator = DataMediatorFactory.createDataMediator(Student.class);
        //add callback
        mMediator.addDataMediatorCallback(new DataMediatorCallback<Student>() {
            @Override
            public void onPropertyValueChanged(Student data, Property prop, Object oldValue, Object newValue) {
                Logger.w("TestPropertyChangeActivity","onPropertyValueChanged","prop = "
                        + prop.getName() + " ,oldValue = " + oldValue + " ,newValue = " + newValue);
                mTv_desc.setText(String.valueOf(newValue));
            }
        });
        mMediator.getDataProxy().setName("heaven7");
    }

    @OnClick(R.id.bt_set_text_on_TextView)
    public void onClickSetTextOnTextView(View v){
        mMediator.getDataProxy().setName("time: " + System.currentTimeMillis());
    }
}

Proguard

-dontwarn com.heaven7.adapter.**
-keepclasseswithmembers public class * implements com.heaven7.java.data.mediator.DataPools$Poolable{
   *;
}
-keepclasseswithmembers public interface * extends com.heaven7.java.data.mediator.DataPools$Poolable{
   *;
}
-keep class * extends com.heaven7.java.data.mediator.BaseMediator{
   *;
}
-keep class com.heaven7.java.data.mediator.BaseMediator
-keep public class com.heaven7.android.data.mediator.DataMediatorDelegateImpl
-keep class com.heaven7.java.data.mediator.internal.$StaticLoader

# needed since 1.4.0
-keepclasseswithmembers class com.heaven7.java.data.mediator.Binder{*;}
-keepclasseswithmembers class * extends com.heaven7.java.data.mediator.Binder{*;}
-keep public class * extends com.heaven7.java.data.mediator.DataBinding { *; }
-keep public class * extends com.heaven7.java.data.mediator.Gps { *; }

Todo

Thanks

License

Copyright 2017   
            group of data-mediator
    member: heaven7([email protected])

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.