use of com.google.samples.apps.topeka.model.Category in project android-topeka by googlesamples.
the class BaseQuizActivityTest method testCategory.
/**
* End to end test for the given category.
*/
protected void testCategory() {
final Category category = getCurrentCategory();
onView(withId(R.id.fab_quiz)).perform(click());
for (Quiz quiz : category.getQuizzes()) {
SolveQuizUtil.solveQuiz(quiz);
onView(allOf(withId(R.id.submitAnswer), isDisplayed())).check(matches(isDisplayed())).perform(click());
}
}
use of com.google.samples.apps.topeka.model.Category in project android-topeka by googlesamples.
the class TopekaDatabaseHelper method getCategory.
/**
* Gets a category from the given position of the cursor provided.
*
* @param cursor The Cursor containing the data.
* @param readableDatabase The database that contains the quizzes.
* @return The found category.
*/
private static Category getCategory(Cursor cursor, SQLiteDatabase readableDatabase) {
// "magic numbers" based on CategoryTable#PROJECTION
final String id = cursor.getString(0);
final String name = cursor.getString(1);
final String themeName = cursor.getString(2);
final Theme theme = Theme.valueOf(themeName);
final String isSolved = cursor.getString(3);
final boolean solved = getBooleanFromDatabase(isSolved);
final int[] scores = JsonHelper.jsonArrayToIntArray(cursor.getString(4));
final List<Quiz> quizzes = getQuizzes(id, readableDatabase);
return new Category(name, id, theme, quizzes, scores, solved);
}
use of com.google.samples.apps.topeka.model.Category in project android-topeka by googlesamples.
the class TopekaDatabaseHelper method getScore.
/**
* Scooooooooooore!
*
* @param context The context this is running in.
* @return The score over all Categories.
*/
public static int getScore(Context context) {
final List<Category> categories = getCategories(context, false);
int score = 0;
for (Category cat : categories) {
score += cat.getScore();
}
return score;
}
use of com.google.samples.apps.topeka.model.Category in project android-topeka by googlesamples.
the class TopekaDatabaseHelper method loadCategories.
private static List<Category> loadCategories(Context context) {
Cursor data = TopekaDatabaseHelper.getCategoryCursor(context);
List<Category> tmpCategories = new ArrayList<>(data.getCount());
final SQLiteDatabase readableDatabase = TopekaDatabaseHelper.getReadableDatabase(context);
do {
final Category category = getCategory(data, readableDatabase);
tmpCategories.add(category);
} while (data.moveToNext());
return tmpCategories;
}
use of com.google.samples.apps.topeka.model.Category in project android-topeka by googlesamples.
the class CategoryAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
ItemCategoryBinding binding = holder.getBinding();
Category category = mCategories.get(position);
binding.setCategory(category);
binding.executePendingBindings();
setCategoryIcon(category, binding.categoryIcon);
holder.itemView.setBackgroundColor(getColor(category.getTheme().getWindowBackgroundColor()));
binding.categoryTitle.setTextColor(getColor(category.getTheme().getTextPrimaryColor()));
binding.categoryTitle.setBackgroundColor(getColor(category.getTheme().getPrimaryColor()));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mOnItemClickListener.onClick(v, holder.getAdapterPosition());
}
});
}
Aggregations