use of com.pankaj.maukascholars.adapters.SavedEventsAdapter in project Precisely by Pankaj-Baranwal.
the class SavedActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Constants.toolbar_title = "Saved Opportunities";
setContentView(R.layout.activity_profile);
RecyclerView recyclerView = findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
DBHandler db = new DBHandler(this);
mItems = db.getAllSavedEvents();
if (mItems.size() == 0) {
RelativeLayout empty_layout = findViewById(R.id.empty_layout);
empty_layout.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
} else {
adapter = new SavedEventsAdapter(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(SavedActivity.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(SavedActivity.this, "Deleted!", Toast.LENGTH_SHORT).show();
}
});
recyclerView.addOnItemTouchListener(swipeTouchListener);
}
}
Aggregations