Search in sources :

Example 31 with RetrofitInterface

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

the class FeedFragment method updateFeed.

private void updateFeed() {
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    retrofitInterface.getNewsFeed(Utils.getSessionIDHeader()).enqueue(new Callback<NewsFeedResponse>() {

        @Override
        public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
            if (response.isSuccessful()) {
                Utils.eventCache.setList(response.body().getEvents());
                displayEvents(Utils.eventCache);
            }
            // Server Error
            feedSwipeRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
            // Network Error
            feedSwipeRefreshLayout.setRefreshing(false);
        }
    });
}
Also used : NewsFeedResponse(app.insti.api.response.NewsFeedResponse) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 32 with RetrofitInterface

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

the class FileComplaintFragment method addComplaint.

private void addComplaint() {
    final String complaint = descriptionAutoCompleteTextview.getText().toString();
    final String suggestion;
    final String locationDetails;
    if (!(editTextSuggestions.getText().toString().isEmpty())) {
        suggestion = editTextSuggestions.getText().toString();
    } else {
        suggestion = "";
    }
    if (!(editTextLocationDetails.getText().toString().isEmpty())) {
        locationDetails = editTextLocationDetails.getText().toString();
    } else {
        locationDetails = "";
    }
    if (Location == null) {
        // Show an explanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response!
        new AlertDialog.Builder(getContext()).setTitle("Location Needed").setMessage("You have not specified your location. The app will by default make \"IIT Area\" as your location.").setPositiveButton("OK", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Location = new LatLng(19.133810, 72.913257);
                Address = "IIT Area";
                ComplaintCreateRequest complaintCreateRequest = new ComplaintCreateRequest(complaint, suggestion, locationDetails, Address, (float) Location.latitude, (float) Location.longitude, Tags, uploadedImagesUrl);
                RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
                retrofitInterface.postComplaint("sessionid=" + getArguments().getString(Constants.SESSION_ID), complaintCreateRequest).enqueue(new Callback<ComplaintCreateResponse>() {

                    @Override
                    public void onResponse(Call<ComplaintCreateResponse> call, Response<ComplaintCreateResponse> response) {
                        Toast.makeText(getContext(), "Complaint successfully posted", Toast.LENGTH_LONG).show();
                        Bundle bundle = getArguments();
                        bundle.putString(Constants.USER_ID, userId);
                        ComplaintsFragment complaintsFragment = new ComplaintsFragment();
                        complaintsFragment.setArguments(bundle);
                        FragmentManager manager = getFragmentManager();
                        FragmentTransaction transaction = manager.beginTransaction();
                        transaction.replace(R.id.framelayout_for_fragment, complaintsFragment, complaintsFragment.getTag());
                        transaction.addToBackStack(complaintsFragment.getTag());
                        manager.popBackStackImmediate("Complaint Fragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);
                        transaction.commit();
                    }

                    @Override
                    public void onFailure(Call<ComplaintCreateResponse> call, Throwable t) {
                        Log.i(TAG, "failure in addComplaint: " + t.toString());
                        Toast.makeText(getContext(), "Complaint Creation Failed", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getContext(), "Submission aborted", Toast.LENGTH_SHORT).show();
                dialog.cancel();
            }
        }).create().show();
    } else {
        ComplaintCreateRequest complaintCreateRequest = new ComplaintCreateRequest(complaint, suggestion, locationDetails, Address, (float) Location.latitude, (float) Location.longitude, Tags, uploadedImagesUrl);
        RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
        retrofitInterface.postComplaint("sessionid=" + getArguments().getString(Constants.SESSION_ID), complaintCreateRequest).enqueue(new Callback<ComplaintCreateResponse>() {

            @Override
            public void onResponse(Call<ComplaintCreateResponse> call, Response<ComplaintCreateResponse> response) {
                Toast.makeText(getContext(), "Complaint successfully posted", Toast.LENGTH_LONG).show();
                Bundle bundle = getArguments();
                bundle.putString(Constants.USER_ID, userId);
                ComplaintsFragment complaintsFragment = new ComplaintsFragment();
                complaintsFragment.setArguments(bundle);
                FragmentManager manager = getFragmentManager();
                FragmentTransaction transaction = manager.beginTransaction();
                transaction.replace(R.id.framelayout_for_fragment, complaintsFragment, complaintsFragment.getTag());
                transaction.addToBackStack(complaintsFragment.getTag());
                manager.popBackStackImmediate("Complaint Fragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);
                transaction.commit();
            }

            @Override
            public void onFailure(Call<ComplaintCreateResponse> call, Throwable t) {
                Log.i(TAG, "failure in addComplaint: " + t.toString());
                Toast.makeText(getContext(), "Complaint Creation Failed", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) ComplaintCreateResponse(app.insti.api.response.ComplaintCreateResponse) Bundle(android.os.Bundle) FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ComplaintCreateRequest(app.insti.api.request.ComplaintCreateRequest) LatLng(com.google.android.gms.maps.model.LatLng) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 33 with RetrofitInterface

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

the class RecyclerViewFragment method initRecyclerView.

/**
 * Initialize scrolling on the adapter
 */
private void initRecyclerView() {
    getActivityBuffer().safely(new ActivityBuffer.IRunnable() {

        @Override
        public void run(Activity pActivity) {
            recyclerView.setAdapter(adapter);
            recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    if (dy > 0) {
                        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
                        if (((layoutManager.getChildCount() + layoutManager.findFirstVisibleItemPosition()) > (layoutManager.getItemCount() - 5)) && (!loading) && (!allLoaded)) {
                            loading = true;
                            String sessionIDHeader = Utils.getSessionIDHeader();
                            RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
                            Call<List<T>> call = getCall(retrofitInterface, sessionIDHeader, getPostCount());
                            call.enqueue(new Callback<List<T>>() {

                                @Override
                                public void onResponse(Call<List<T>> call, Response<List<T>> response) {
                                    if (getActivity() == null || getView() == null)
                                        return;
                                    loading = false;
                                    if (response.isSuccessful()) {
                                        List<T> posts = adapter.getPosts();
                                        posts.addAll(response.body());
                                        if (response.body().size() == 0) {
                                            showLoader = false;
                                            allLoaded = true;
                                        }
                                        adapter.setPosts(posts);
                                        adapter.notifyDataSetChanged();
                                    }
                                }

                                @Override
                                public void onFailure(Call<List<T>> call, Throwable t) {
                                    loading = false;
                                }
                            });
                        }
                    }
                }
            });
        }
    });
}
Also used : ActivityBuffer(app.insti.ActivityBuffer) MainActivity(app.insti.activity.MainActivity) Activity(android.app.Activity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) List(java.util.List) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 34 with RetrofitInterface

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

the class UserFragment method loadUser.

public void loadUser(String userID) {
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    retrofitInterface.getUser(Utils.getSessionIDHeader(), userID).enqueue(new EmptyCallback<User>() {

        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            if (response.isSuccessful()) {
                if (getActivity() == null || getView() == null)
                    return;
                user = response.body();
                populateViews();
            }
        }
    });
}
Also used : User(app.insti.api.model.User) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 35 with RetrofitInterface

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

the class MessMenuWidget method updateAppWidget.

private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
    // Construct the RemoteViews object
    views = new RemoteViews(context.getPackageName(), R.layout.mess_menu_widget);
    SessionManager sessionManager = new SessionManager(context);
    if (sessionManager.isLoggedIn()) {
        ServiceGenerator serviceGenerator = new ServiceGenerator(context);
        RetrofitInterface retrofitInterface = serviceGenerator.getRetrofitInterface();
        retrofitInterface.getInstituteMessMenu(sessionManager.getSessionID()).enqueue(new Callback<List<HostelMessMenu>>() {

            @Override
            public void onResponse(Call<List<HostelMessMenu>> call, Response<List<HostelMessMenu>> response) {
                if (response.isSuccessful()) {
                    instituteMessMenu = response.body();
                    displayMenu(sessionManager.getCurrentUser().getHostel());
                    // Instruct the widget manager to update the widget
                    appWidgetManager.updateAppWidget(appWidgetId, views);
                }
            }

            @Override
            public void onFailure(Call<List<HostelMessMenu>> call, Throwable t) {
            // Network error
            }
        });
    } else {
        views.setTextViewText(R.id.meal_text_view, "Login to see your mess menu");
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) SessionManager(app.insti.SessionManager) ServiceGenerator(app.insti.api.ServiceGenerator) List(java.util.List) 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