Search in sources :

Example 1 with StarredEventsAdapter

use of com.pankaj.maukascholars.adapters.StarredEventsAdapter in project Precisely by Pankaj-Baranwal.

the class StarredActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Constants.toolbar_title = "Starred Opportunities";
    setContentView(R.layout.activity_profile);
    toolbar.setTitle("Starred Opportunities");
    RecyclerView recyclerView = findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    DBHandler db = new DBHandler(this);
    mItems = db.getAllStarredEvents();
    if (mItems.size() == 0) {
        RelativeLayout empty_layout = findViewById(R.id.empty_layout);
        empty_layout.setVisibility(View.VISIBLE);
        recyclerView.setVisibility(View.GONE);
    } else {
        final RecyclerView.Adapter adapter = new StarredEventsAdapter(mItems, this);
        recyclerView.setAdapter(adapter);
        SwipeableRecyclerViewTouchListener swipeTouchListener = new SwipeableRecyclerViewTouchListener(recyclerView, new SwipeableRecyclerViewTouchListener.SwipeListener() {

            @Override
            public boolean canSwipeLeft(int position) {
                return true;
            }

            @Override
            public boolean canSwipeRight(int position) {
                return true;
            }

            @Override
            public void onDismissedBySwipeLeft(RecyclerView recyclerView, int[] reverseSortedPositions) {
                for (int position : reverseSortedPositions) {
                    deleteData(position);
                    adapter.notifyItemRemoved(position);
                }
                adapter.notifyDataSetChanged();
                Toast.makeText(StarredActivity.this, "Deleted!", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDismissedBySwipeRight(RecyclerView recyclerView, int[] reverseSortedPositions) {
                for (int position : reverseSortedPositions) {
                    deleteData(position);
                    adapter.notifyItemRemoved(position);
                }
                adapter.notifyDataSetChanged();
                Toast.makeText(StarredActivity.this, "Deleted!", Toast.LENGTH_SHORT).show();
            }
        });
        recyclerView.addOnItemTouchListener(swipeTouchListener);
    }
}
Also used : SwipeableRecyclerViewTouchListener(com.github.brnunes.swipeablerecyclerview.SwipeableRecyclerViewTouchListener) DBHandler(com.pankaj.maukascholars.database.DBHandler) RelativeLayout(android.widget.RelativeLayout) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StarredEventsAdapter(com.pankaj.maukascholars.adapters.StarredEventsAdapter)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 RelativeLayout (android.widget.RelativeLayout)1 SwipeableRecyclerViewTouchListener (com.github.brnunes.swipeablerecyclerview.SwipeableRecyclerViewTouchListener)1 StarredEventsAdapter (com.pankaj.maukascholars.adapters.StarredEventsAdapter)1 DBHandler (com.pankaj.maukascholars.database.DBHandler)1