Search in sources :

Example 6 with DBHandler

use of com.pankaj.maukascholars.database.DBHandler 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

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