Search in sources :

Example 1 with NetworkBoundTask

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();
}
Also used : Response(com.bluestacks.bugzy.data.remote.model.Response) ApiResponse(com.bluestacks.bugzy.data.remote.ApiResponse) LoginData(com.bluestacks.bugzy.data.remote.model.LoginData) NonNull(android.support.annotation.NonNull) LoginRequest(com.bluestacks.bugzy.data.remote.model.LoginRequest) NetworkBoundTask(com.bluestacks.bugzy.data.remote.NetworkBoundTask)

Aggregations

NonNull (android.support.annotation.NonNull)1 ApiResponse (com.bluestacks.bugzy.data.remote.ApiResponse)1 NetworkBoundTask (com.bluestacks.bugzy.data.remote.NetworkBoundTask)1 LoginData (com.bluestacks.bugzy.data.remote.model.LoginData)1 LoginRequest (com.bluestacks.bugzy.data.remote.model.LoginRequest)1 Response (com.bluestacks.bugzy.data.remote.model.Response)1