Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.mindorks.framework.mvvm.data;

import android.content.Context;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.internal.$Gson$Types;
import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -48,6 +50,8 @@
@Singleton
public class AppDataManager implements DataManager {

private static final String TAG = "AppDataManager";

private final ApiHelper mApiHelper;

private final Context mContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ public AppDbHelper(AppDatabase appDatabase) {

@Override
public Observable<List<Question>> getAllQuestions() {
return Observable.fromCallable(new Callable<List<Question>>() {
@Override
public List<Question> call() throws Exception {
return mAppDatabase.questionDao().loadAll();
}
});
return mAppDatabase.questionDao().loadAll()
.toObservable();
}

@Override
Expand All @@ -61,12 +57,8 @@ public List<User> call() throws Exception {

@Override
public Observable<List<Option>> getOptionsForQuestionId(final Long questionId) {
return Observable.fromCallable(new Callable<List<Option>>() {
@Override
public List<Option> call() throws Exception {
return mAppDatabase.optionDao().loadAllByQuestionId(questionId);
}
});
return mAppDatabase.optionDao().loadAllByQuestionId(questionId)
.toObservable();
}

@Override
Expand All @@ -82,22 +74,15 @@ public Boolean call() throws Exception {

@Override
public Observable<Boolean> isOptionEmpty() {
return Observable.fromCallable(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return mAppDatabase.optionDao().loadAll().isEmpty();
}
});
return mAppDatabase.optionDao().loadAll()
.flatMapObservable(options -> Observable.just(options.isEmpty()));
}

@Override
public Observable<Boolean> isQuestionEmpty() {
return Observable.fromCallable(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return mAppDatabase.questionDao().loadAll().isEmpty();
}
});
return mAppDatabase.questionDao().loadAll()
.flatMapObservable(questions -> Observable.just(questions.isEmpty()));

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.mindorks.framework.mvvm.data.model.db.Option;
import java.util.List;

import io.reactivex.Single;

/**
* Created by amitshekhar on 08/07/17.
*/
Expand All @@ -36,8 +38,8 @@ public interface OptionDao {
void insertAll(List<Option> options);

@Query("SELECT * FROM options")
List<Option> loadAll();
Single<List<Option>> loadAll();

@Query("SELECT * FROM options WHERE question_id = :questionId")
List<Option> loadAllByQuestionId(Long questionId);
Single<List<Option>> loadAllByQuestionId(Long questionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.mindorks.framework.mvvm.data.model.db.Question;
import java.util.List;

import io.reactivex.Single;

/**
* Created by amitshekhar on 08/07/17.
*/
Expand All @@ -36,5 +38,5 @@ public interface QuestionDao {
void insertAll(List<Question> questions);

@Query("SELECT * FROM questions")
List<Question> loadAll();
Single<List<Question>> loadAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.mindorks.framework.mvvm.data.model.db.User;
import java.util.List;

import io.reactivex.Single;

/**
* Created by amitshekhar on 07/07/17.
*/
Expand All @@ -35,7 +37,7 @@ public interface UserDao {
void delete(User user);

@Query("SELECT * FROM users WHERE name LIKE :name LIMIT 1")
User findByName(String name);
Single<User> findByName(String name);

@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(User user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;
import android.text.TextUtils;
import android.util.Log;

import com.mindorks.framework.mvvm.data.DataManager;
import com.mindorks.framework.mvvm.data.model.others.QuestionCardData;
import com.mindorks.framework.mvvm.ui.base.BaseViewModel;
Expand All @@ -34,6 +36,8 @@

public class MainViewModel extends BaseViewModel<MainNavigator> {

private static final String TAG = "MainViewModel";

public static final int NO_ACTION = -1, ACTION_ADD_ALL = 0, ACTION_DELETE_SINGLE = 1;

private final ObservableField<String> appVersion = new ObservableField<>();
Expand Down Expand Up @@ -93,15 +97,17 @@ public ObservableField<String> getUserProfilePicUrl() {
public void loadQuestionCards() {
getCompositeDisposable().add(getDataManager()
.getQuestionCardData()
.doOnNext(list -> Log.d(TAG, "loadQuestionCards: " + list.size()))
.subscribeOn(getSchedulerProvider().io())
.observeOn(getSchedulerProvider().ui())
.subscribe(questionList -> {
if (questionList != null) {
Log.d(TAG, "loadQuestionCards: " + questionList.size());
action = ACTION_ADD_ALL;
questionCardData.setValue(questionList);
}
}, throwable -> {

Log.d(TAG, "loadQuestionCards: " + throwable);
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class SplashActivity extends BaseActivity<ActivitySplashBinding, SplashVi

@Inject
ViewModelProviderFactory factory;

private SplashViewModel mSplashViewModel;

@Override
Expand Down