Entity Loaders¶
Introduction¶
The “entity loader” is a class provided by the developer (you) that gives Socialize a way to navigate your application.
When a user views a social action (e.g. a comment) the Entity Loader allows the user to navigate to the entity (content) to which the social action pertains.
This is particularly important for SmartAlerts (push notifications) and as such an entity loader is required for SmartAlerts.
Creating the Entity Loader¶
To create an Entity Loader you need to define a new class in your application that implements the SocializeEntityLoader interface.
Note
An entity loader MUST define a parameterless constructor
There is only one Entity Loader per application and it can be set on the Socialize instance:
// This is a class you need to create in your app
public class MyEntityLoader implements SocializeEntityLoader {
// MUST define a parameterless constructor
public MyEntityLoader() {
super();
}
/*
* (non-Javadoc)
* @see com.socialize.ui.SocializeEntityLoader#loadEntity(android.app.Activity, com.socialize.entity.Entity)
*/
@Override
public void loadEntity(Activity activity, Entity entity) {
// This is where you would load an Activity within your app to render the entity
}
/*
* (non-Javadoc)
* @see com.socialize.ui.SocializeEntityLoader#canLoad(android.content.Context, com.socialize.entity.Entity)
*/
@Override
public boolean canLoad(Context context, Entity entity) {
// Return true if this entity can be loaded
return true;
}
}
The loadEntity method will be called by Socialize when the user selects an item rendered by Socialize which corresponds directly to content in your app.
For example you may want to start an activity in the entity loader:
// This is a class you need to create in your app
public class MyEntityLoader implements SocializeEntityLoader {
// MUST define a parameterless constructor
public MyEntityLoader() {
super();
}
/*
* (non-Javadoc)
* @see com.socialize.ui.SocializeEntityLoader#loadEntity(android.app.Activity, com.socialize.entity.Entity)
*/
@Override
public void loadEntity(Activity activity, Entity entity) {
// Launch an activity from here...
Intent intent = new Intent(activity, MyContentActivity.class);
// Add the key from the entity
intent.putExtra("some_key", entity.getKey());
activity.startActivity(intent);
}
/*
* (non-Javadoc)
* @see com.socialize.ui.SocializeEntityLoader#canLoad(android.content.Context, com.socialize.entity.Entity)
*/
@Override
public boolean canLoad(Context context, Entity entity) {
// Return true if this entity can be loaded
return true;
}
}
Adding the Entity Loader to Socialize¶
To add your Entity Loader to Socialize simply add an entry to socialize.properties
# Entity Loader Class Name
socialize.entity.loader=com.mypackage.MyEntityLoader
Replace com.mypackage.MyEntityLoader with the fully qualified class name of your entity loader.