Search in sources :

Example 1 with Category

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());
    }
}
Also used : Category(com.google.samples.apps.topeka.model.Category) Quiz(com.google.samples.apps.topeka.model.quiz.Quiz)

Example 2 with Category

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);
}
Also used : AlphaPickerQuiz(com.google.samples.apps.topeka.model.quiz.AlphaPickerQuiz) Quiz(com.google.samples.apps.topeka.model.quiz.Quiz) MultiSelectQuiz(com.google.samples.apps.topeka.model.quiz.MultiSelectQuiz) FillTwoBlanksQuiz(com.google.samples.apps.topeka.model.quiz.FillTwoBlanksQuiz) FillBlankQuiz(com.google.samples.apps.topeka.model.quiz.FillBlankQuiz) TrueFalseQuiz(com.google.samples.apps.topeka.model.quiz.TrueFalseQuiz) SelectItemQuiz(com.google.samples.apps.topeka.model.quiz.SelectItemQuiz) ToggleTranslateQuiz(com.google.samples.apps.topeka.model.quiz.ToggleTranslateQuiz) PickerQuiz(com.google.samples.apps.topeka.model.quiz.PickerQuiz) FourQuarterQuiz(com.google.samples.apps.topeka.model.quiz.FourQuarterQuiz) Category(com.google.samples.apps.topeka.model.Category) Theme(com.google.samples.apps.topeka.model.Theme)

Example 3 with Category

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;
}
Also used : Category(com.google.samples.apps.topeka.model.Category)

Example 4 with Category

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;
}
Also used : Category(com.google.samples.apps.topeka.model.Category) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 5 with Category

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());
        }
    });
}
Also used : ItemCategoryBinding(com.google.samples.apps.topeka.databinding.ItemCategoryBinding) Category(com.google.samples.apps.topeka.model.Category) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

Category (com.google.samples.apps.topeka.model.Category)5 Quiz (com.google.samples.apps.topeka.model.quiz.Quiz)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 ItemCategoryBinding (com.google.samples.apps.topeka.databinding.ItemCategoryBinding)1 Theme (com.google.samples.apps.topeka.model.Theme)1 AlphaPickerQuiz (com.google.samples.apps.topeka.model.quiz.AlphaPickerQuiz)1 FillBlankQuiz (com.google.samples.apps.topeka.model.quiz.FillBlankQuiz)1 FillTwoBlanksQuiz (com.google.samples.apps.topeka.model.quiz.FillTwoBlanksQuiz)1 FourQuarterQuiz (com.google.samples.apps.topeka.model.quiz.FourQuarterQuiz)1 MultiSelectQuiz (com.google.samples.apps.topeka.model.quiz.MultiSelectQuiz)1 PickerQuiz (com.google.samples.apps.topeka.model.quiz.PickerQuiz)1 SelectItemQuiz (com.google.samples.apps.topeka.model.quiz.SelectItemQuiz)1 ToggleTranslateQuiz (com.google.samples.apps.topeka.model.quiz.ToggleTranslateQuiz)1 TrueFalseQuiz (com.google.samples.apps.topeka.model.quiz.TrueFalseQuiz)1 ArrayList (java.util.ArrayList)1