-
Notifications
You must be signed in to change notification settings - Fork 1
How To Use
Required to instantiate Model and DatabaseFacade.
public class Model
Model is a singleton holder for LSClient and SimpleItemManager. The following gives an fragment of Model class.
public class Model {
private LSClient client;
private SimpleItemManager simpleItemManager;
public LSClient getClient() {
return client;
}
public SimpleItemManager getSimpleItemManager() {
return simpleItemManager;
}
private Model(Context context) {
client = new LSClient(context);
simpleItemManager = new SimpleItemManager(client);
}
}
public class DatabaseFacade
DatabaseFacade is a singleton that wraps DatabaseHelper and SQLiteDatabase. It is responsible for: open/close a database, create query, save/update/delete database table. You can use it without any changes.
public class BaseRequestBuilder
For example, here is an implementation of BaseRequestBuilder.
public class StubItemRequestBuilder extends BaseRequestBuilder {
public ItemRequestBuilder() {
setRequestMethod(BaseRequest.RequestMethod.GET);
setResponseFormat(BaseRequest.ResponseFormat.JSON);
Type listType = new TypeToken<List<StubItemVO>>() {}.getType();
setResponseClassSpecifier(listType);
setRequestURL(“set your url here”);
}
}
public class ItemStubManager extends SynchronizedDatabaseManager<List<StubItemVO>, Bundle, String>
In order to perform server request SynchrondizedDatabaseManager should be extended. For each request a separate manager should be created. Then it is needed to create a fetch request in getFetchRequest() method.
##Application
public class StubRecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder>
The main feature of RecyclerAdapteris is a possibility to load feed. For example, the following methods are useful to load page.
private void loadPage() {
Model.instance().getSimpleItemManager().pullPage();
}
public void enableDataLoad() {
Model.instance().getSimpleItemManager().addDataFetchCompleteListener(listener);
loadPage();
}
public void disableDataLoad() {
Model.instance().getSimpleItemManager().removeDataFetchCompleteListener(listener);
}
public class SimpleListActivity extends BaseActivity
SimpleListActivity consists of CoordinatorLayout with wrap RecyclerView. It is using RecyclerAdapter to disable/enable data loading.
public class SimpleListActivity extends BaseActivity {
private StubItemAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new StubItemAdapter(this);
adapter.enableDataLoad();
}
@Override
protected void onDestroy() {
super.onDestroy();
if(adapter != null)
{
adapter.disableDataLoad();
}
}
}
To work with a database you need create a subclass of the SQLiteOpenHelper class. In this class you need to override the methods to create and update your database.
All queries to create set of tables are placed in string resources. For example, this snippet defines the table name and column names for a single table:
<resources>
<string name="create_table_stub_items">
create table stub_items(
_id string primary key,
imageURL string,
description string,
isFavorite integer,
page_id string
)
</string>
</resources>
public class StubItemDAO extends AbstractDAO<StubItemVO, String>
You need to extend AbstractDAO and implement abstract methods.