Search in sources :

Example 16 with RetrofitInterface

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);
        }
    });
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Event(app.insti.api.model.Event) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 17 with RetrofitInterface

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());
                }
            }
        }
    });
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) SuppressLint(android.annotation.SuppressLint) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 18 with RetrofitInterface

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());
        }
    });
}
Also used : CommentCreateRequest(app.insti.api.request.CommentCreateRequest) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 19 with RetrofitInterface

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());
            }
        });
    }
}
Also used : Response(retrofit2.Response) Venter(app.insti.api.model.Venter) Call(retrofit2.Call) OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback) Callback(retrofit2.Callback) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 20 with RetrofitInterface

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());
    }
}
Also used : ServiceGenerator(app.insti.api.ServiceGenerator) RetrofitInterface(app.insti.api.RetrofitInterface)

Aggregations

RetrofitInterface (app.insti.api.RetrofitInterface)35 List (java.util.List)12 Venter (app.insti.api.model.Venter)6 Call (retrofit2.Call)6 Response (retrofit2.Response)6 Event (app.insti.api.model.Event)5 ArrayList (java.util.ArrayList)5 Callback (retrofit2.Callback)5 User (app.insti.api.model.User)4 DialogInterface (android.content.DialogInterface)3 TextView (android.widget.TextView)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Toolbar (androidx.appcompat.widget.Toolbar)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 SessionManager (app.insti.SessionManager)2 UpdatableList (app.insti.UpdatableList)2