Search in sources :

Example 1 with CategoryEntity

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;
}
Also used : CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 2 with CategoryEntity

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;
}
Also used : CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 3 with CategoryEntity

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;
}
Also used : CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 4 with CategoryEntity

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;
}
Also used : Category(com.ushahidi.java.sdk.api.Category) ArrayList(java.util.ArrayList) CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 5 with CategoryEntity

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);
                }
            }
        }
    }
}
Also used : ListReportModel(com.ushahidi.android.app.models.ListReportModel) CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Aggregations

CategoryEntity (com.ushahidi.android.app.entities.CategoryEntity)11 ListReportModel (com.ushahidi.android.app.models.ListReportModel)3 Category (com.ushahidi.java.sdk.api.Category)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 Util (com.ushahidi.android.app.util.Util)1 UshahidiException (com.ushahidi.java.sdk.UshahidiException)1 ArrayList (java.util.ArrayList)1