Search in sources :

Example 1 with ItemClickListener

use of in.ac.iitb.gymkhana.iitbapp.ItemClickListener 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 2 with ItemClickListener

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

the class FeedFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    appDatabase = AppDatabase.getAppDatabase(getContext());
    final List<Event> events = appDatabase.dbDao().getAllEvents();
    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()));
    // }
    updateFeed();
    feedSwipeRefreshLayout = (SwipeRefreshLayout) getActivity().findViewById(R.id.feed_swipe_refresh_layout);
    feedSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            updateFeed();
        }
    });
}
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) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) Event(in.ac.iitb.gymkhana.iitbapp.data.Event)

Example 3 with ItemClickListener

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

the class NotificationsFragment method showNotifications.

private void showNotifications(NotificationsResponse notificationsResponse) {
    List<AppNotification> notifications = notificationsResponse.getNotifications();
    NotificationsAdapter notificationsAdapter = new NotificationsAdapter(notifications, new ItemClickListener() {

        @Override
        public void onItemClick(View v, int position) {
        // TODO: What to do?
        }
    });
    notificationsRecyclerView = (RecyclerView) getActivity().findViewById(R.id.notifications_recycler_view);
    notificationsRecyclerView.setAdapter(notificationsAdapter);
    notificationsRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
Also used : NotificationsAdapter(in.ac.iitb.gymkhana.iitbapp.adapter.NotificationsAdapter) ItemClickListener(in.ac.iitb.gymkhana.iitbapp.ItemClickListener) AppNotification(in.ac.iitb.gymkhana.iitbapp.api.model.AppNotification) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 ItemClickListener (in.ac.iitb.gymkhana.iitbapp.ItemClickListener)3 Bundle (android.os.Bundle)2 FragmentManager (android.support.v4.app.FragmentManager)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 Gson (com.google.gson.Gson)2 FeedAdapter (in.ac.iitb.gymkhana.iitbapp.adapter.FeedAdapter)2 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 NotificationsAdapter (in.ac.iitb.gymkhana.iitbapp.adapter.NotificationsAdapter)1 RetrofitInterface (in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface)1 AppNotification (in.ac.iitb.gymkhana.iitbapp.api.model.AppNotification)1 NewsFeedResponse (in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse)1 Event (in.ac.iitb.gymkhana.iitbapp.data.Event)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1