Search in sources :

Example 1 with UserFCMPatchRequest

use of app.insti.api.request.UserFCMPatchRequest in project IITB-App by wncc.

the class MainActivity method updateFCMId.

/**
 * Update FCM Id and update profile
 */
private void updateFCMId() {
    FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {

        @Override
        public void onSuccess(InstanceIdResult instanceIdResult) {
            final String fcmId = instanceIdResult.getToken();
            RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
            retrofitInterface.patchUserMe(Utils.getSessionIDHeader(), new UserFCMPatchRequest(fcmId, getCurrentVersion())).enqueue(new EmptyCallback<User>() {

                @Override
                public void onResponse(Call<User> call, Response<User> response) {
                    if (response.isSuccessful()) {
                        session.createLoginSession(response.body().getUserName(), response.body(), session.getSessionID());
                        currentUser = response.body();
                        Utils.currentUserCache = currentUser;
                    } else {
                        session.logout();
                        currentUser = null;
                        Toast.makeText(MainActivity.this, "Your session has expired!", Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
    });
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) EmptyCallback(app.insti.api.EmptyCallback) InstanceIdResult(com.google.firebase.iid.InstanceIdResult) RetrofitInterface(app.insti.api.RetrofitInterface) UserFCMPatchRequest(app.insti.api.request.UserFCMPatchRequest)

Aggregations

EmptyCallback (app.insti.api.EmptyCallback)1 RetrofitInterface (app.insti.api.RetrofitInterface)1 UserFCMPatchRequest (app.insti.api.request.UserFCMPatchRequest)1 InstanceIdResult (com.google.firebase.iid.InstanceIdResult)1 Call (retrofit2.Call)1 Response (retrofit2.Response)1