Search in sources :

Example 1 with Question

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

the class AppDataManager method seedDatabaseQuestions.

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

        @Override
        public ObservableSource<? extends Boolean> apply(Boolean isEmpty) throws Exception {
            if (isEmpty) {
                Type type = $Gson$Types.newParameterizedTypeWithOwner(null, List.class, Question.class);
                List<Question> questionList = gson.fromJson(CommonUtils.loadJSONFromAsset(mContext, AppConstants.SEED_DATABASE_QUESTIONS), type);
                return saveQuestionList(questionList);
            }
            return Observable.just(false);
        }
    });
}
Also used : Type(java.lang.reflect.Type) GsonBuilder(com.google.gson.GsonBuilder) ObservableSource(io.reactivex.ObservableSource) Gson(com.google.gson.Gson) List(java.util.List) Question(com.mindorks.framework.mvp.data.db.model.Question)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Question (com.mindorks.framework.mvp.data.db.model.Question)1 ObservableSource (io.reactivex.ObservableSource)1 Type (java.lang.reflect.Type)1 List (java.util.List)1