Skip to content

Commit

Permalink
fix swipe to apply for applicant
Browse files Browse the repository at this point in the history
  • Loading branch information
Yougourta committed Mar 9, 2019
1 parent 88ae5fd commit daac96f
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.List;

import fr.smartrecruit.R;
import fr.smartrecruit.api.SmarRecruitApi;
import fr.smartrecruit.controller.candidat.FavoritesAdapter;
import fr.smartrecruit.controller.candidat.FavoritesController;
import fr.smartrecruit.data.DataConstants;
import fr.smartrecruit.data.JobOffer;
import it.xabaras.android.recyclerview.swipedecorator.RecyclerViewSwipeDecorator;

Expand Down Expand Up @@ -54,24 +56,32 @@ public void initAdapter(){
favoriteOffersRecycler.setLayoutManager(llm);
favoriteOffersRecycler.setItemAnimator(new DefaultItemAnimator());
favoriteOffersRecycler.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}

@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
FavoritesController.getFavoritesController().removeFavorite(favoriteOffers.get(position).getId());
favoriteOffersAdapter.removeItem(position);
if (direction == ItemTouchHelper.LEFT){
int position = viewHolder.getAdapterPosition();
FavoritesController.getFavoritesController().removeFavorite(favoriteOffers.get(position).getId());
favoriteOffersAdapter.removeItem(position);
}else if (direction == ItemTouchHelper.RIGHT){
int position = viewHolder.getAdapterPosition();
new SmarRecruitApi(context).updateStatus(favoriteOffers.get(position).getId(), DataConstants.APP_RDV_ATT);
favoriteOffersAdapter.removeItem(position);
}
}

@Override
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
new RecyclerViewSwipeDecorator.Builder(context, c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
.addSwipeLeftBackgroundColor(ContextCompat.getColor(context, R.color.deleteColor))
.addSwipeLeftActionIcon(R.drawable.ic_favorite_border_white_36dp)
.addSwipeRightBackgroundColor(ContextCompat.getColor(context, R.color.favoriteColor))
.addSwipeRightActionIcon(R.drawable.ic_check_white_36dp)
.create()
.decorate();
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
Expand Down

0 comments on commit daac96f

Please sign in to comment.