Search in sources :

Example 26 with RetrofitInterface

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

the class FileComplaintFragment method prepareTags.

private void prepareTags() {
    try {
        RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
        retrofitInterface.getTags("sessionid=" + getArguments().getString(Constants.SESSION_ID)).enqueue(new Callback<List<Venter.TagUri>>() {

            @Override
            public void onResponse(Call<List<Venter.TagUri>> call, Response<List<Venter.TagUri>> response) {
                if (response != null && response.isSuccessful()) {
                    List<Venter.TagUri> tagsApiList = response.body();
                    tagList = new ArrayList<>();
                    for (int i = 0; i < tagsApiList.size(); i++) {
                        Venter.TagUri tagUri = tagsApiList.get(i);
                        ComplaintTag complaintTag = new ComplaintTag(tagUri.getTagUri());
                        tagList.add(complaintTag);
                    }
                    swipeContainer.setRefreshing(false);
                    linearLayoutAll.setVisibility(View.VISIBLE);
                    error_message_me.setVisibility(View.GONE);
                    getMapReady();
                } else {
                    error_message_me.setVisibility(View.VISIBLE);
                    error_message_me.setText(getString(R.string.no_complaints));
                    swipeContainer.setRefreshing(false);
                    linearLayoutAll.setVisibility(View.GONE);
                }
            }

            @Override
            public void onFailure(Call<List<Venter.TagUri>> call, Throwable t) {
                Log.i(TAG, "failure in getting Tags: " + t.toString());
                swipeContainer.setRefreshing(false);
                error_message_me.setVisibility(View.VISIBLE);
                linearLayoutAll.setVisibility(View.GONE);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
        swipeContainer.setRefreshing(false);
        linearLayoutAll.setVisibility(View.GONE);
    }
}
Also used : Venter(app.insti.api.model.Venter) ComplaintTag(app.insti.ComplaintTag) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ApiException(com.google.android.gms.common.api.ApiException) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 27 with RetrofitInterface

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

the class MessMenuFragment method updateMessMenu.

private void updateMessMenu(final String hostel) {
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    retrofitInterface.getInstituteMessMenu(Utils.getSessionIDHeader()).enqueue(new Callback<List<HostelMessMenu>>() {

        @Override
        public void onResponse(Call<List<HostelMessMenu>> call, Response<List<HostelMessMenu>> response) {
            if (response.isSuccessful()) {
                if (getActivity() == null || getView() == null || response.body() == null)
                    return;
                instituteMessMenu = response.body();
                if (!initialized) {
                    initialize();
                } else {
                    displayMenu(hostel);
                }
            }
            // Server Error
            messMenuSwipeRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onFailure(Call<List<HostelMessMenu>> call, Throwable t) {
            // Network Error
            messMenuSwipeRefreshLayout.setRefreshing(false);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 28 with RetrofitInterface

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

the class NotificationsFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    /* Show cached notifications */
    if (Utils.notificationCache != null) {
        showNotifications(Utils.notificationCache);
    } else {
        Utils.notificationCache = new UpdatableList<>();
    }
    /* Update notifications */
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    retrofitInterface.getNotifications(Utils.getSessionIDHeader()).enqueue(new EmptyCallback<List<Notification>>() {

        @Override
        public void onResponse(Call<List<Notification>> call, Response<List<Notification>> response) {
            if (response.isSuccessful()) {
                Utils.notificationCache.setList(response.body());
                showNotifications(Utils.notificationCache);
                NotificationId.setCurrentCount(Utils.notificationCache.size());
                ShortcutBadger.applyCount(getContext(), NotificationId.getCurrentCount());
            }
        }
    });
}
Also used : UpdatableList(app.insti.UpdatableList) List(java.util.List) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 29 with RetrofitInterface

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

Example 30 with RetrofitInterface

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

the class ComplaintDetailsFragment method subscribeToComplaint.

private void subscribeToComplaint(final Venter.Complaint detailedComplaint) {
    final RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    if (detailedComplaint.isComplaintSubscribed()) {
        AlertDialog.Builder unsubscribe = new AlertDialog.Builder(getActivity());
        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()) {
                            detailedComplaint.setComplaintSubscribed(false);
                            notificationson.setVisibility(View.GONE);
                            notificationsoff.setVisibility(View.VISIBLE);
                        }
                    }

                    @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 Callback<Venter.Complaint>() {

            @Override
            public void onResponse(Call<Venter.Complaint> call, Response<Venter.Complaint> response) {
                if (response.isSuccessful()) {
                    detailedComplaint.setComplaintSubscribed(true);
                    notificationsoff.setVisibility(View.GONE);
                    notificationson.setVisibility(View.VISIBLE);
                    Toast.makeText(getActivity(), "You are subscribed to this complaint!", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(Call<Venter.Complaint> call, Throwable t) {
                Log.i(TAG, "failure in subscribe: " + t.toString());
            }
        });
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Response(retrofit2.Response) Venter(app.insti.api.model.Venter) Call(retrofit2.Call) OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback) Callback(retrofit2.Callback) DialogInterface(android.content.DialogInterface) 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