Search in sources :

Example 1 with FavoriteAdapter

use of flying.grub.tamtime.adapter.FavoriteAdapter in project TamTime by flyingrub.

the class FavoriteStopsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.view_recycler_load, container, false);
    setHasOptionsMenu(true);
    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.progress);
    linearLayout.setVisibility(View.GONE);
    TextView textView = (TextView) view.findViewById(R.id.empty_view);
    textView.setText(getString(R.string.no_favorite_stop));
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    recyclerView.setHasFixedSize(false);
    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setBackgroundColor(getResources().getColor(R.color.windowBackgroundCard));
    favoriteStops = new FavoriteStops(getActivity());
    getActivity().setTitle(getString(R.string.all_stops_favs));
    if (favoriteStops.getFavoriteStop().size() == 0) {
        textView.setVisibility(View.VISIBLE);
        recyclerView.setVisibility(View.GONE);
        return view;
    }
    adapter = new FavoriteAdapter(favoriteStops.getFavoriteStop());
    recyclerView.setAdapter(adapter);
    adapter.SetOnItemClickListener(new FavoriteAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View v, int position) {
            selectitem(position);
        }
    });
    adapter.SetOnMenuClickListener(new FavoriteAdapter.OnMenuClickListener() {

        @Override
        public void onItemClick(View v, final int position) {
            // Creating the instance of PopupMenu
            PopupMenu popup = new PopupMenu(getActivity(), v);
            // Inflating the Popup using xml file
            popup.getMenuInflater().inflate(R.menu.delete_menu, popup.getMenu());
            // registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    favoriteStops.remove(position);
                    recyclerView.swapAdapter(new FavoriteAdapter(favoriteStops.getFavoriteStop()), false);
                    return true;
                }
            });
            // showing popup menu
            popup.show();
        }
    });
    return view;
}
Also used : MenuItem(android.view.MenuItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) TextView(android.widget.TextView) FavoriteStops(flying.grub.tamtime.data.persistence.FavoriteStops) FavoriteAdapter(flying.grub.tamtime.adapter.FavoriteAdapter) LinearLayout(android.widget.LinearLayout) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 PopupMenu (android.support.v7.widget.PopupMenu)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 FavoriteAdapter (flying.grub.tamtime.adapter.FavoriteAdapter)1 FavoriteStops (flying.grub.tamtime.data.persistence.FavoriteStops)1