Search in sources :

Example 1 with Quiz

use of com.google.samples.apps.topeka.model.quiz.Quiz in project android-topeka by googlesamples.

the class ScoreAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (null == convertView) {
        convertView = createView(parent);
    }
    final Quiz quiz = getItem(position);
    ViewHolder viewHolder = (ViewHolder) convertView.getTag();
    viewHolder.mQuizView.setText(quiz.getQuestion());
    viewHolder.mAnswerView.setText(quiz.getStringAnswer());
    setSolvedStateForQuiz(viewHolder.mSolvedState, position);
    return convertView;
}
Also used : Quiz(com.google.samples.apps.topeka.model.quiz.Quiz)

Example 2 with Quiz

use of com.google.samples.apps.topeka.model.quiz.Quiz in project android-topeka by googlesamples.

the class TopekaDatabaseHelper method updateQuizzes.

/**
     * Updates a list of given quizzes.
     *
     * @param writableDatabase The database to write the quizzes to.
     * @param quizzes The quizzes to write.
     */
private static void updateQuizzes(SQLiteDatabase writableDatabase, List<Quiz> quizzes) {
    Quiz quiz;
    ContentValues quizValues = new ContentValues();
    String[] quizArgs = new String[1];
    for (int i = 0; i < quizzes.size(); i++) {
        quiz = quizzes.get(i);
        quizValues.clear();
        quizValues.put(QuizTable.COLUMN_SOLVED, quiz.isSolved());
        quizArgs[0] = quiz.getQuestion();
        writableDatabase.update(QuizTable.NAME, quizValues, QuizTable.COLUMN_QUESTION + "=?", quizArgs);
    }
}
Also used : ContentValues(android.content.ContentValues) 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)

Example 3 with Quiz

use of com.google.samples.apps.topeka.model.quiz.Quiz in project android-topeka by googlesamples.

the class TopekaDatabaseHelper method getQuizzes.

/**
     * Creates objects for quizzes according to a category id.
     *
     * @param categoryId The category to create quizzes for.
     * @param database The database containing the quizzes.
     * @return The found quizzes or an empty list if none were available.
     */
private static List<Quiz> getQuizzes(final String categoryId, SQLiteDatabase database) {
    final List<Quiz> quizzes = new ArrayList<>();
    final Cursor cursor = database.query(QuizTable.NAME, QuizTable.PROJECTION, QuizTable.FK_CATEGORY + " LIKE ?", new String[] { categoryId }, null, null, null);
    cursor.moveToFirst();
    do {
        quizzes.add(createQuizDueToType(cursor));
    } while (cursor.moveToNext());
    cursor.close();
    return quizzes;
}
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) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 4 with Quiz

use of com.google.samples.apps.topeka.model.quiz.Quiz 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 5 with Quiz

use of com.google.samples.apps.topeka.model.quiz.Quiz in project android-topeka by googlesamples.

the class TopekaDatabaseHelper method updateCategory.

/**
     * Updates values for a category.
     *
     * @param context The context this is running in.
     * @param category The category to update.
     */
public static void updateCategory(Context context, Category category) {
    if (mCategories != null && mCategories.contains(category)) {
        final int location = mCategories.indexOf(category);
        mCategories.remove(location);
        mCategories.add(location, category);
    }
    SQLiteDatabase writableDatabase = getWritableDatabase(context);
    ContentValues categoryValues = createContentValuesFor(category);
    writableDatabase.update(CategoryTable.NAME, categoryValues, CategoryTable.COLUMN_ID + "=?", new String[] { category.getId() });
    final List<Quiz> quizzes = category.getQuizzes();
    updateQuizzes(writableDatabase, quizzes);
}
Also used : ContentValues(android.content.ContentValues) 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) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

Quiz (com.google.samples.apps.topeka.model.quiz.Quiz)8 FillBlankQuiz (com.google.samples.apps.topeka.model.quiz.FillBlankQuiz)6 TrueFalseQuiz (com.google.samples.apps.topeka.model.quiz.TrueFalseQuiz)6 AlphaPickerQuiz (com.google.samples.apps.topeka.model.quiz.AlphaPickerQuiz)5 FillTwoBlanksQuiz (com.google.samples.apps.topeka.model.quiz.FillTwoBlanksQuiz)5 FourQuarterQuiz (com.google.samples.apps.topeka.model.quiz.FourQuarterQuiz)5 MultiSelectQuiz (com.google.samples.apps.topeka.model.quiz.MultiSelectQuiz)5 PickerQuiz (com.google.samples.apps.topeka.model.quiz.PickerQuiz)5 SelectItemQuiz (com.google.samples.apps.topeka.model.quiz.SelectItemQuiz)5 ToggleTranslateQuiz (com.google.samples.apps.topeka.model.quiz.ToggleTranslateQuiz)5 ContentValues (android.content.ContentValues)2 Category (com.google.samples.apps.topeka.model.Category)2 ArrayList (java.util.ArrayList)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Theme (com.google.samples.apps.topeka.model.Theme)1 AbsQuizView (com.google.samples.apps.topeka.widget.quiz.AbsQuizView)1