use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.
the class CategoryDao method fetchAllCategoryTitles.
@Override
public List<CategoryEntity> fetchAllCategoryTitles() {
final String[] columns = { ID, CATEGORY_ID, TITLE, COLOR, POSITION, PARENT_ID };
final String selection = PARENT_ID + " = ?";
listCategory = new ArrayList<CategoryEntity>();
cursor = super.query(TABLE, columns, selection, new String[] { String.valueOf(0) }, GROUP_BY, null, SORT_ORDER, null);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
CategoryEntity category = cursorToEntity(cursor);
listCategory.add(category);
cursor.moveToNext();
}
cursor.close();
}
return listCategory;
}
use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.
the class CategoryDao method addCategories.
@Override
public boolean addCategories(List<CategoryEntity> categories) {
try {
mDb.beginTransaction();
for (CategoryEntity category : categories) {
addCategory(category);
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
return true;
}
use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.
the class CategoryDao method cursorToEntity.
@SuppressWarnings("unchecked")
@Override
protected CategoryEntity cursorToEntity(Cursor cursor) {
CategoryEntity category = new CategoryEntity();
int titleIndex;
int idIndex;
int colorIndex;
int positionIndex;
int descriptionIndex;
int categoryIdIndex;
int parentIdIndex;
if (cursor != null) {
if (cursor.getColumnIndex(ID) != -1) {
idIndex = cursor.getColumnIndexOrThrow(ID);
category.setDbId(cursor.getInt(idIndex));
}
if (cursor.getColumnIndex(CATEGORY_ID) != -1) {
categoryIdIndex = cursor.getColumnIndexOrThrow(CATEGORY_ID);
category.setCategoryId(cursor.getInt(categoryIdIndex));
}
if (cursor.getColumnIndex(PARENT_ID) != -1) {
parentIdIndex = cursor.getColumnIndexOrThrow(PARENT_ID);
category.setParentId(cursor.getInt(parentIdIndex));
}
if (cursor.getColumnIndex(TITLE) != -1) {
titleIndex = cursor.getColumnIndexOrThrow(TITLE);
category.setCategoryTitle(cursor.getString(titleIndex));
}
if (cursor.getColumnIndex(COLOR) != -1) {
colorIndex = cursor.getColumnIndexOrThrow(COLOR);
category.setCategoryColor(cursor.getString(colorIndex));
}
if (cursor.getColumnIndex(POSITION) != -1) {
positionIndex = cursor.getColumnIndexOrThrow(POSITION);
category.setCategoryPosition(Integer.valueOf(cursor.getString(positionIndex)));
}
if (cursor.getColumnIndex(DESCRIPTION) != -1) {
descriptionIndex = cursor.getColumnIndexOrThrow(DESCRIPTION);
category.setCategoryDescription(cursor.getString(descriptionIndex));
}
}
return category;
}
use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.
the class ListPendingReportAdapter method fetchCategoriesId.
public List<Category> fetchCategoriesId(int reportId) {
List<Category> categories = new ArrayList<Category>();
Category c = new Category();
for (CategoryEntity category : mListReportModel.getCategoriesByReportId(reportId)) {
c.setId(category.getCategoryId());
categories.add(c);
}
return categories;
}
use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.
the class CategorySpinnerAdater method refresh.
/*
* (non-Javadoc)
*
* @see com.ushahidi.android.app.adapters.BaseArrayAdapter#refresh()
*/
@Override
public void refresh() {
ListReportModel mListReportModel = new ListReportModel();
List<CategoryEntity> listCategories = mListReportModel.getParentCategories();
if (listCategories != null && listCategories.size() > 0) {
// This is to make room for all categories label
CategoryEntity cat = new CategoryEntity();
cat.setCategoryTitle(context.getString(R.string.all_categories));
cat.setCategoryPosition(0);
cat.setDbId(0);
cat.setCategoryId(0);
cat.setParentId(0);
cat.setCategoryColor("000000");
add(cat.getCategoryTitle(), cat);
for (CategoryEntity category : listCategories) {
add(category.getCategoryTitle(), category);
// add child categories
List<CategoryEntity> listChildrenCategories = mListReportModel.getChildrenCategories(category.getCategoryId());
if (listChildrenCategories != null && listChildrenCategories.size() > 0) {
for (CategoryEntity childrenCategories : listChildrenCategories) {
add(childrenCategories.getCategoryTitle(), childrenCategories);
}
}
}
}
}
Aggregations