Search in sources :

Example 1 with EmptyCallback

use of app.insti.api.EmptyCallback 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)

Example 2 with EmptyCallback

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

the class ComplaintsAdapter method subscribeToComplaint.

private void subscribeToComplaint(final Venter.Complaint detailedComplaint, final ImageButton notificationsoff, final ImageButton notificationson) {
    final RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    if (detailedComplaint.isComplaintSubscribed()) {
        AlertDialog.Builder unsubscribe = new AlertDialog.Builder(context);
        unsubscribe.setMessage("Are you sure you want to unsubscribe to this complaint?");
        unsubscribe.setCancelable(true);
        unsubscribe.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                retrofitInterface.subscribetoComplaint(Utils.getSessionIDHeader(), detailedComplaint.getComplaintID(), 0).enqueue(new Callback<Venter.Complaint>() {

                    @Override
                    public void onResponse(Call<Venter.Complaint> call, Response<Venter.Complaint> response) {
                        if (response.isSuccessful()) {
                            notificationson.setVisibility(View.GONE);
                            notificationsoff.setVisibility(View.VISIBLE);
                            detailedComplaint.setComplaintSubscribed(false);
                            Toast.makeText(context, "You have been unsubscribed from this complaint!", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onFailure(Call<Venter.Complaint> call, Throwable t) {
                        Log.i(TAG, "failure in subscribe: " + t.toString());
                    }
                });
            }
        });
        unsubscribe.setNegativeButton("No", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        AlertDialog alert11 = unsubscribe.create();
        alert11.show();
    } else if (!detailedComplaint.isComplaintSubscribed()) {
        retrofitInterface.subscribetoComplaint(Utils.getSessionIDHeader(), detailedComplaint.getComplaintID(), 1).enqueue(new EmptyCallback<Venter.Complaint>() {

            @Override
            public void onResponse(Call<Venter.Complaint> call, Response<Venter.Complaint> response) {
                if (response.isSuccessful()) {
                    notificationson.setVisibility(View.VISIBLE);
                    notificationsoff.setVisibility(View.GONE);
                    detailedComplaint.setComplaintSubscribed(true);
                    Toast.makeText(context, "You have been subscribed to this complaint!", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Venter(app.insti.api.model.Venter) Call(retrofit2.Call) DialogInterface(android.content.DialogInterface) EmptyCallback(app.insti.api.EmptyCallback) Response(retrofit2.Response) EmptyCallback(app.insti.api.EmptyCallback) Callback(retrofit2.Callback) RetrofitInterface(app.insti.api.RetrofitInterface)

Aggregations

EmptyCallback (app.insti.api.EmptyCallback)2 RetrofitInterface (app.insti.api.RetrofitInterface)2 Call (retrofit2.Call)2 Response (retrofit2.Response)2 DialogInterface (android.content.DialogInterface)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 Venter (app.insti.api.model.Venter)1 UserFCMPatchRequest (app.insti.api.request.UserFCMPatchRequest)1 InstanceIdResult (com.google.firebase.iid.InstanceIdResult)1 Callback (retrofit2.Callback)1