binder

Simple annotation based model to view binding library

License

License

GroupId

GroupId

com.kendamasoft
ArtifactId

ArtifactId

binder
Last Version

Last Version

0.9.7
Release Date

Release Date

Type

Type

aar
Description

Description

binder
Simple annotation based model to view binding library
Project URL

Project URL

https://github.com/stariy95/android-binder
Source Code Management

Source Code Management

https://github.com/stariy95/android-binder

Download binder

How to add to project

<!-- https://jarcasting.com/artifacts/com.kendamasoft/binder/ -->
<dependency>
    <groupId>com.kendamasoft</groupId>
    <artifactId>binder</artifactId>
    <version>0.9.7</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.kendamasoft/binder/
implementation 'com.kendamasoft:binder:0.9.7'
// https://jarcasting.com/artifacts/com.kendamasoft/binder/
implementation ("com.kendamasoft:binder:0.9.7")
'com.kendamasoft:binder:aar:0.9.7'
<dependency org="com.kendamasoft" name="binder" rev="0.9.7">
  <artifact name="binder" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.kendamasoft', module='binder', version='0.9.7')
)
libraryDependencies += "com.kendamasoft" % "binder" % "0.9.7"
[com.kendamasoft/binder "0.9.7"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Android Binder

This project is a simple annotation based model to view binder.

Installation

Add as a dependency to your build.gradle:

dependencies {
    compile 'com.kendamasoft.binder:0.9.7'
}

Simple Injection

class MyActivity extends Activity {
    @Inject(R.id.textView)
    TextView text;
    
    @Inject({R.id.icon1, R.id.icon2, R.id.icon3})
    List<ImageView> icons;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_test);
        Binder.register(this);
        
        text.setText("Hello World");
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Binder.unregister(this);
    }
}

Binding and callbacks

class MyModel extends Observable {

    @Bind(R.id.editText)
    String text = "World!";
    
    @Bind(R.id.textView)
    String description = "Hello";
    
    @Inject(R.id.button)
    private Button button;
    
    public void setText(String text) {
        this.text = text;
        notifyFieldChange("text");
    }
    
    public void setDescription(String description) {
        this.description = description;
        notifyFieldChange("description");
    }
    
    @Callback(R.id.checkBox)
    public void setEnabled(boolean enabled) {
        button.setEnabled(enabled);
    }
}

class MyActivity extends Activity {
    @Model
    MyModel model;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_test);
        Binder.register(this);
        
        model.setEnabled(false);
    }
    
    @OnClick(R.id.button)
    void onTestButtonClick() {
        model.setDescription("Hello World!");
    }
    
}

List View Helper

class TestListModelHelper extends ViewHolderHelper<TestListModel> {                 
    @Inject(R.id.textViewName)
    TextView nameView;

    @Inject(R.id.textViewDescription)     
    TextView descriptionView;
 
    @Override
    public void applyView(TestListModel model, View rootView) {
        nameView.setText(model.name);
        descriptionView.setText(model.description);
    }
}  

class MyActivity extends Activity {
    
    List<TestListModelHelper> listModel = new ArrayList<>();
    
    @Inject(R.id.listView)
    ListView listView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_test);
        Binder.register(this);
        
        ...
        
        listView.setAdapter(new ListViewAdapter<>(this, R.layout.list_item_test, TestListBinder.class, listModel));
    }
}

Unregister

Call Binder.unregister(...) to clean everything up. Good place for this call is onDestroy() methods.

Versions

Version
0.9.7
0.9.6
0.9.5
0.9.4
0.9.1