|
|
@ -12,13 +12,20 @@ import androidx.appcompat.widget.AppCompatImageButton; |
|
|
|
import androidx.recyclerview.widget.RecyclerView; |
|
|
|
import gr.auth.databases.flavours.R; |
|
|
|
import gr.auth.databases.flavours.model.Diet; |
|
|
|
import gr.auth.databases.flavours.session.SessionManager; |
|
|
|
|
|
|
|
import static gr.auth.databases.flavours.base.BaseActivity.getSessionManager; |
|
|
|
|
|
|
|
public class DietsAdapter extends RecyclerView.Adapter<DietsAdapter.DietViewHolder> { |
|
|
|
private ArrayList<Diet> diets; |
|
|
|
private AcceptDietAdapterInteractionListener acceptDietAdapterInteractionListener; |
|
|
|
private SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener; |
|
|
|
|
|
|
|
DietsAdapter(ArrayList<Diet> diets, SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener) { |
|
|
|
DietsAdapter(ArrayList<Diet> diets, |
|
|
|
AcceptDietAdapterInteractionListener acceptDietAdapterInteractionListener, |
|
|
|
SubscribeDietsAdapterInteractionListener subscribeDietsAdapterInteractionListener) { |
|
|
|
this.diets = diets; |
|
|
|
this.acceptDietAdapterInteractionListener = acceptDietAdapterInteractionListener; |
|
|
|
this.subscribeDietsAdapterInteractionListener = subscribeDietsAdapterInteractionListener; |
|
|
|
} |
|
|
|
|
|
|
@ -41,6 +48,43 @@ public class DietsAdapter extends RecyclerView.Adapter<DietsAdapter.DietViewHold |
|
|
|
holder.addDietButton.setImageResource(R.drawable.ic_add_black_18dp); |
|
|
|
} |
|
|
|
|
|
|
|
if (!diets.get(position).isAccepted() && |
|
|
|
(getSessionManager().getUserType() == SessionManager.UserType.MODERATOR)) { |
|
|
|
holder.acceptDietBtn.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
if (acceptDietAdapterInteractionListener != null) { |
|
|
|
acceptDietAdapterInteractionListener. |
|
|
|
onAcceptDietAdapterInteraction(diets.get(holder.getAdapterPosition())); |
|
|
|
diets.get(holder.getAdapterPosition()).setAccepted(true); |
|
|
|
|
|
|
|
holder.acceptDietBtn.setVisibility(View.GONE); |
|
|
|
holder.addDietButton.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
holder.addDietButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
subscribeDietsAdapterInteractionListener.onSubscribeDietsAdapterInteraction( |
|
|
|
diets.get(holder.getAdapterPosition())); |
|
|
|
|
|
|
|
if ((diets.get(position).isFollowedByUser())) { |
|
|
|
holder.addDietButton.setImageResource(R.drawable.ic_add_black_18dp); |
|
|
|
diets.get(position).setFollowedByUser(!diets.get(position).isFollowedByUser()); |
|
|
|
} else { |
|
|
|
holder.addDietButton.setImageResource(R.drawable.ic_delete_black_18dp); |
|
|
|
diets.get(position).setFollowedByUser(!diets.get(position).isFollowedByUser()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
holder.acceptDietBtn.setVisibility(View.VISIBLE); |
|
|
|
holder.addDietButton.setVisibility(View.GONE); |
|
|
|
} else { |
|
|
|
holder.acceptDietBtn.setVisibility(View.GONE); |
|
|
|
holder.addDietButton.setVisibility(View.VISIBLE); |
|
|
|
|
|
|
|
holder.addDietButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
@ -57,6 +101,7 @@ public class DietsAdapter extends RecyclerView.Adapter<DietsAdapter.DietViewHold |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int getItemCount() { |
|
|
@ -65,16 +110,21 @@ public class DietsAdapter extends RecyclerView.Adapter<DietsAdapter.DietViewHold |
|
|
|
|
|
|
|
static class DietViewHolder extends RecyclerView.ViewHolder { |
|
|
|
TextView name, description; |
|
|
|
AppCompatImageButton addDietButton; |
|
|
|
AppCompatImageButton acceptDietBtn, addDietButton; |
|
|
|
|
|
|
|
DietViewHolder(View v) { |
|
|
|
super(v); |
|
|
|
name = v.findViewById(R.id.diets_diet_name); |
|
|
|
description = v.findViewById(R.id.diets_diet_description); |
|
|
|
acceptDietBtn = v.findViewById(R.id.restaurant_item_row_accept_btn); |
|
|
|
addDietButton = v.findViewById(R.id.diets_diet_subscribe); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public interface AcceptDietAdapterInteractionListener { |
|
|
|
void onAcceptDietAdapterInteraction(Diet diet); |
|
|
|
} |
|
|
|
|
|
|
|
public interface SubscribeDietsAdapterInteractionListener { |
|
|
|
void onSubscribeDietsAdapterInteraction(Diet diet); |
|
|
|
} |
|
|
|