Search in sources :

Example 1 with Option

use of com.mindorks.framework.mvp.data.db.model.Option in project android-mvp-architecture by MindorksOpenSource.

the class QuestionCard method showCorrectOptions.

private void showCorrectOptions() {
    for (int i = 0; i < 3; i++) {
        Option option = mQuestion.getOptionList().get(i);
        Button button = null;
        switch(i) {
            case 0:
                button = mOption1Button;
                break;
            case 1:
                button = mOption2Button;
                break;
            case 2:
                button = mOption3Button;
                break;
        }
        if (button != null) {
            if (option.isCorrect()) {
                button.setBackgroundColor(Color.GREEN);
            } else {
                button.setBackgroundColor(Color.RED);
            }
        }
    }
}
Also used : Button(android.widget.Button) Option(com.mindorks.framework.mvp.data.db.model.Option)

Example 2 with Option

use of com.mindorks.framework.mvp.data.db.model.Option in project android-mvp-architecture by MindorksOpenSource.

the class AppDataManager method seedDatabaseOptions.

@Override
public Observable<Boolean> seedDatabaseOptions() {
    GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
    final Gson gson = builder.create();
    return mDbHelper.isOptionEmpty().concatMap(new Function<Boolean, ObservableSource<? extends Boolean>>() {

        @Override
        public ObservableSource<? extends Boolean> apply(Boolean isEmpty) throws Exception {
            if (isEmpty) {
                Type type = new TypeToken<List<Option>>() {
                }.getType();
                List<Option> optionList = gson.fromJson(CommonUtils.loadJSONFromAsset(mContext, AppConstants.SEED_DATABASE_OPTIONS), type);
                return saveOptionList(optionList);
            }
            return Observable.just(false);
        }
    });
}
Also used : Type(java.lang.reflect.Type) GsonBuilder(com.google.gson.GsonBuilder) ObservableSource(io.reactivex.ObservableSource) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Option(com.mindorks.framework.mvp.data.db.model.Option) List(java.util.List)

Aggregations

Option (com.mindorks.framework.mvp.data.db.model.Option)2 Button (android.widget.Button)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 ObservableSource (io.reactivex.ObservableSource)1 Type (java.lang.reflect.Type)1 List (java.util.List)1