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