Search in sources :

Example 1 with RetrofitInterface

use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.

the class LoginActivity method login.

private void login(String authorizationCode, final String redirectURI, String gcmID) {
    RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
    retrofitInterface.login(authorizationCode, redirectURI, gcmID).enqueue(new Callback<LoginResponse>() {

        @Override
        public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
            if (response.isSuccessful()) {
                Log.d(TAG, "Login request successful");
                session.createLoginSession(redirectURI, response.body().getUser(), response.body().getSessionID());
                Intent i = new Intent(mContext, MainActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);
            // Save credentials in AccountManager to keep user logged in
            // Go to MainActivity
            }
        // Server error
        }

        @Override
        public void onFailure(Call<LoginResponse> call, Throwable t) {
        // Network Error
        }
    });
}
Also used : LoginResponse(in.ac.iitb.gymkhana.iitbapp.api.model.LoginResponse) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RetrofitInterface(in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface)

Example 2 with RetrofitInterface

use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.

the class AddEventFragment method sendImage.

private void sendImage() {
    progressDialog.setMessage("Uploading Image");
    ImageUploadRequest imageUploadRequest = new ImageUploadRequest(base64Image);
    RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
    retrofitInterface.uploadImage("sessionid=" + getArguments().getString(SESSION_ID), imageUploadRequest).enqueue(new Callback<ImageUploadResponse>() {

        @Override
        public void onResponse(Call<ImageUploadResponse> call, Response<ImageUploadResponse> response) {
            if (response.isSuccessful()) {
                ImageUploadResponse imageUploadResponse = response.body();
                String imageURL = imageUploadResponse.getPictureURL();
                addEvent(imageURL);
            }
        }

        @Override
        public void onFailure(Call<ImageUploadResponse> call, Throwable t) {
            progressDialog.dismiss();
        }
    });
}
Also used : ImageUploadRequest(in.ac.iitb.gymkhana.iitbapp.api.model.ImageUploadRequest) ImageUploadResponse(in.ac.iitb.gymkhana.iitbapp.api.model.ImageUploadResponse) RetrofitInterface(in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface)

Example 3 with RetrofitInterface

use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.

the class FeedFragment method updateFeed.

private void updateFeed() {
    RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
    retrofitInterface.getNewsFeed("sessionid=" + getArguments().getString(SESSION_ID)).enqueue(new Callback<NewsFeedResponse>() {

        @Override
        public void onResponse(Call<NewsFeedResponse> call, Response<NewsFeedResponse> response) {
            if (response.isSuccessful()) {
                NewsFeedResponse newsFeedResponse = response.body();
                final List<Event> events = newsFeedResponse.getEvents();
                FeedAdapter feedAdapter = new FeedAdapter(events, new ItemClickListener() {

                    @Override
                    public void onItemClick(View v, int position) {
                        String eventJson = new Gson().toJson(events.get(position));
                        Bundle bundle = new Bundle();
                        bundle.putString(Constants.EVENT_JSON, eventJson);
                        EventFragment eventFragment = new EventFragment();
                        eventFragment.setArguments(bundle);
                        FragmentManager manager = getActivity().getSupportFragmentManager();
                        FragmentTransaction transaction = manager.beginTransaction();
                        transaction.replace(R.id.framelayout_for_fragment, eventFragment, eventFragment.getTag());
                        transaction.commit();
                    }
                });
                feedRecyclerView = (RecyclerView) getActivity().findViewById(R.id.feed_recycler_view);
                feedRecyclerView.setAdapter(feedAdapter);
                feedRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
                appDatabase.dbDao().deleteEvents();
                appDatabase.dbDao().insertEvents(events);
                // Server Error
                feedSwipeRefreshLayout.setRefreshing(false);
            }
        }

        @Override
        public void onFailure(Call<NewsFeedResponse> call, Throwable t) {
            // Network Error
            feedSwipeRefreshLayout.setRefreshing(false);
        }
    });
}
Also used : ItemClickListener(in.ac.iitb.gymkhana.iitbapp.ItemClickListener) Bundle(android.os.Bundle) Gson(com.google.gson.Gson) FeedAdapter(in.ac.iitb.gymkhana.iitbapp.adapter.FeedAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) NewsFeedResponse(in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse) ArrayList(java.util.ArrayList) List(java.util.List) RecyclerView(android.support.v7.widget.RecyclerView) RetrofitInterface(in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface)

Example 4 with RetrofitInterface

use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.

the class ProfileFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    Bundle bundle = getArguments();
    String userID = bundle.getString(Constants.USER_ID);
    RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
    retrofitInterface.getUser("sessionid=" + getArguments().getString(SESSION_ID), userID).enqueue(new Callback<User>() {

        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            if (response.isSuccessful()) {
                user = response.body();
                populateViews();
            }
        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
        }
    });
}
Also used : User(in.ac.iitb.gymkhana.iitbapp.data.User) Bundle(android.os.Bundle) RetrofitInterface(in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface)

Example 5 with RetrofitInterface

use of in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface in project IITB-App by wncc.

the class MainActivity method fetchNotifications.

private void fetchNotifications() {
    NotificationsRequest notificationsRequest = new NotificationsRequest(0, 20);
    RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
    retrofitInterface.getNotifications(notificationsRequest).enqueue(new Callback<NotificationsResponse>() {

        @Override
        public void onResponse(Call<NotificationsResponse> call, Response<NotificationsResponse> response) {
            if (response.isSuccessful()) {
                notificationsResponse = response.body();
                if (showNotifications) {
                    showNotifications();
                    showNotifications = false;
                }
            }
        // Server Error
        }

        @Override
        public void onFailure(Call<NotificationsResponse> call, Throwable t) {
        // Network Error
        }
    });
}
Also used : NotificationsResponse(in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsResponse) NotificationsRequest(in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsRequest) RetrofitInterface(in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface)

Aggregations

RetrofitInterface (in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface)6 Bundle (android.os.Bundle)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 FragmentManager (android.support.v4.app.FragmentManager)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 Gson (com.google.gson.Gson)1 ItemClickListener (in.ac.iitb.gymkhana.iitbapp.ItemClickListener)1 FeedAdapter (in.ac.iitb.gymkhana.iitbapp.adapter.FeedAdapter)1 EventCreateRequest (in.ac.iitb.gymkhana.iitbapp.api.model.EventCreateRequest)1 EventCreateResponse (in.ac.iitb.gymkhana.iitbapp.api.model.EventCreateResponse)1 ImageUploadRequest (in.ac.iitb.gymkhana.iitbapp.api.model.ImageUploadRequest)1 ImageUploadResponse (in.ac.iitb.gymkhana.iitbapp.api.model.ImageUploadResponse)1 LoginResponse (in.ac.iitb.gymkhana.iitbapp.api.model.LoginResponse)1 NewsFeedResponse (in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse)1 NotificationsRequest (in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsRequest)1 NotificationsResponse (in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsResponse)1