use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class MainActivity method openEventFragment.
/**
* Open the event fragment from the provided id
*/
private void openEventFragment(String id) {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
final FragmentActivity self = this;
retrofitInterface.getEvent(Utils.getSessionIDHeader(), id).enqueue(new EmptyCallback<Event>() {
@Override
public void onResponse(Call<Event> call, Response<Event> response) {
Utils.openEventFragment(response.body(), self);
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class MainActivity method checkLatestVersion.
/**
* Check for updates in andro.json
*/
private void checkLatestVersion() {
final int versionCode = getCurrentVersion();
if (versionCode == 0) {
return;
}
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getLatestVersion().enqueue(new EmptyCallback<JsonObject>() {
@Override
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
if (response.isSuccessful()) {
final JsonElement currentVersion = response.body().get("version");
if (currentVersion != null && currentVersion.getAsInt() > versionCode) {
showUpdateSnackBar(response.body().get("message").getAsString());
}
}
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class ComplaintDetailsFragment method postComment.
private void postComment() {
final CommentCreateRequest commentCreateRequest = new CommentCreateRequest(editTextComment.getText().toString());
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.postComment(Utils.getSessionIDHeader(), cId, commentCreateRequest).enqueue(new Callback<Venter.Comment>() {
@Override
public void onResponse(Call<Venter.Comment> call, Response<Venter.Comment> response) {
if (response.isSuccessful()) {
Venter.Comment comment = response.body();
addNewComment(comment);
editTextComment.setText(null);
}
}
@Override
public void onFailure(Call<Venter.Comment> call, Throwable t) {
Log.i(TAG, "failure in posting comments: " + t.toString());
}
});
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class ComplaintDetailsFragment method upVote.
private void upVote(final Venter.Complaint detailedComplaint) {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
if (!detailedComplaint.isComplaintUpvoted()) {
retrofitInterface.upVote(Utils.getSessionIDHeader(), cId, 1).enqueue(new Callback<Venter.Complaint>() {
@Override
public void onResponse(Call<Venter.Complaint> call, Response<Venter.Complaint> response) {
if (response.isSuccessful()) {
Venter.Complaint complaint = response.body();
detailedComplaint.setComplaintUpvoted(true);
addVotesToView(complaint);
}
}
@Override
public void onFailure(Call<Venter.Complaint> call, Throwable t) {
Log.i(TAG, "failure in up vote: " + t.toString());
}
});
} else if (detailedComplaint.isComplaintUpvoted()) {
retrofitInterface.upVote(Utils.getSessionIDHeader(), cId, 0).enqueue(new Callback<Venter.Complaint>() {
@Override
public void onResponse(Call<Venter.Complaint> call, Response<Venter.Complaint> response) {
if (response.isSuccessful()) {
Venter.Complaint complaint = response.body();
detailedComplaint.setComplaintUpvoted(false);
addVotesToView(complaint);
}
}
@Override
public void onFailure(Call<Venter.Complaint> call, Throwable t) {
Log.i(TAG, "failure in up vote: " + t.toString());
}
});
}
}
use of app.insti.api.RetrofitInterface in project IITB-App by wncc.
the class NotificationBroadcastReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Constants.NOTIF_CANCELLED)) {
// Get the notification id
String id = intent.getExtras().getString(Constants.FCM_BUNDLE_NOTIFICATION_ID);
if (id == null || id.equals(""))
return;
// Get retrofit and session id
ServiceGenerator serviceGenerator = new ServiceGenerator(context);
RetrofitInterface retrofitInterface = serviceGenerator.getRetrofitInterface();
SessionManager session = new SessionManager(context);
if (session.isLoggedIn()) {
Utils.setSessionId(session.getSessionID());
}
// Mark as read
retrofitInterface.markNotificationDeleted(Utils.getSessionIDHeader(), id).enqueue(new EmptyCallback<Void>());
// Reduce current count
ShortcutBadger.applyCount(context.getApplicationContext(), NotificationId.decrementAndGetCurrentCount());
}
}
Aggregations