Search in sources :

Example 6 with CategoryEntity

use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.

the class AddReportActivity method setCheckedCategories.

/**
	 * Get check selected categories
	 * 
	 * @param aSelectedCategories
	 */
private boolean[] setCheckedCategories() {
    // FIXME: Look into making this more efficient
    if (mVectorCategories != null && mVectorCategories.size() > 0) {
        ListReportModel mListReportModel = new ListReportModel();
        List<CategoryEntity> listCategories = mListReportModel.getAllCategories();
        if (listCategories != null && listCategories.size() > 0) {
            int categoryCount = listCategories.size();
            int categoryAmount = 0;
            if (categoryCount > 0) {
                categoryAmount = categoryCount;
            } else {
                categoryAmount = 1;
            }
            boolean[] categories = new boolean[categoryAmount];
            mCategoryLength = categories.length;
            int i = 0;
            for (CategoryEntity category : mListReportModel.getAllCategories()) {
                if (mVectorCategories.contains(String.valueOf(category.getCategoryId()))) {
                    categories[i] = true;
                } else {
                    categories[i] = false;
                }
                i++;
            }
            return categories;
        }
    }
    return null;
}
Also used : ListReportModel(com.ushahidi.android.app.models.ListReportModel) CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 7 with CategoryEntity

use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.

the class CategoriesApi method getCategoriesList.

/**
	 * Fetch categories using the Ushahidi API
	 * 
	 * @return boolean Successful return true otherwise return false
	 */
public boolean getCategoriesList() {
    new Util().log("Save categories list");
    if (processingResult) {
        try {
            List<Category> cats = task.all();
            if (cats != null) {
                for (com.ushahidi.java.sdk.api.Category cat : cats) {
                    CategoryEntity category = new CategoryEntity();
                    category.addCategory(cat);
                    categories.add(category);
                }
                return saveCategories(categories);
            }
        } catch (UshahidiException e) {
            log("UshahidiException", e);
            processingResult = false;
        } catch (JsonSyntaxException e) {
            log("JSONSyntaxException", e);
        }
    }
    return false;
}
Also used : Category(com.ushahidi.java.sdk.api.Category) JsonSyntaxException(com.google.gson.JsonSyntaxException) Util(com.ushahidi.android.app.util.Util) UshahidiException(com.ushahidi.java.sdk.UshahidiException) Category(com.ushahidi.java.sdk.api.Category) CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 8 with CategoryEntity

use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.

the class CategoryDao method fetchCategoryByReportId.

@Override
public List<CategoryEntity> fetchCategoryByReportId(int reportId) {
    final String sql = "SELECT *" + " FROM " + TABLE + " category INNER JOIN " + IReportCategorySchema.TABLE + " categories ON category." + CATEGORY_ID + " = categories." + IReportCategorySchema.CATEGORY_ID + " AND categories." + IReportCategorySchema.REPORT_ID + " =? " + " ORDER BY  category." + CATEGORY_ID + " ASC";
    listCategory = new ArrayList<CategoryEntity>();
    cursor = super.rawQuery(sql, new String[] { String.valueOf(reportId) });
    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 9 with CategoryEntity

use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.

the class CategoryDao method fetchAllCategories.

@Override
public List<CategoryEntity> fetchAllCategories() {
    cursor = super.query(TABLE, COLUMNS, null, null, GROUP_BY, null, SORT_ORDER, null);
    listCategory = new ArrayList<CategoryEntity>();
    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 10 with CategoryEntity

use of com.ushahidi.android.app.entities.CategoryEntity in project Ushahidi_Android by ushahidi.

the class CategoryDao method fetchChildrenCategories.

public List<CategoryEntity> fetchChildrenCategories(int parentId) {
    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(parentId) }, 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)

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