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);
}
}
Aggregations