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();
}
}
});
}
});
}
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();
}
}
});
}
}
Aggregations