Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.
Adrián Rivero edited this page May 8, 2017 · 24 revisions

Models are Enhanced Beans which depends on @UseModel. The need of having a @Mode, it's to be able to pass parameters to the injection process.

Basic usage:

@UseModel
public class MyModel {

}

Models injections

Once you annotate your models you can inject them in any AndroidAnnotations Enhanced Component.

Basic model injection:

@Model
MyModel myModel;

Parameters:

A parameter to the injection process, this parameters supports Formatted Syntax

String query() default "";

A parameter to the injection process, this parameters supports Formatted Syntax

String orderBy() default "";

The load of the field will be done asynchronously, in a different thread.

boolean async() default false;

The storage of the field will be done asynchronously, in a different thread.

boolean asyncPut() default true;

The field will be loaded lazily, this method generates a getter for the field, in order to be accessed, it can be done with a reference to the enhanced view, using "get" + the name of the field starting with capital letter, or you can simply load the model with the action $LoadModel

boolean lazy() default false;

Methods after Loading and Putting a Model

Inside a model, methods annotated with "@AfterLoad" and "@AfterPut" can be used to execute local code in the method after the Injection or Storing process.

@AfterLoad
void executeAfterLoad() {

}

@AfterPut
void executeAfterPut() {

}

From within these methods you can access to the variables that where used to Inject or Store the object, or to the Injected model, for instance:

@AfterLoad
void initializeModel(Model_ model, String query) {
    //Make any operations over model depending of the provided query
}

Useful methods to manage Models

  • exists()

After injecting a model, it is a common situation to ask if it "existed", this means it was injected from SQLite, Network, Preferences; and not that it was simply instantiated because it didn't exist before.

Example:

See Also: