use of com.bluestacks.bugzy.data.remote.NetworkBoundTask in project bugzy by cpunq.
the class Repository method login.
public LiveData<Resource<Response<LoginData>>> login(String email, String password) {
NetworkBoundTask<Response<LoginData>> task = new NetworkBoundTask<Response<LoginData>>(mAppExecutors, mGson) {
@Override
public void saveCallResult(@NonNull Response<LoginData> result) {
String token = result.getData().getToken();
mPrefs.setString(PrefsHelper.Key.ACCESS_TOKEN, token);
mPrefs.setBoolean(PrefsHelper.Key.USER_LOGGED_IN, true);
mSsRespository.insertDefaultSearchSuggestions();
mAppExecutors.mainThread().execute(new Runnable() {
@Override
public void run() {
mToken.setValue(token);
}
});
}
@NonNull
@Override
protected Call<Response<LoginData>> createCall() {
return mApiService.login(new LoginRequest(email, password));
}
};
mAppExecutors.networkIO().execute(task);
return task.asLiveData();
}
Aggregations