type of game step done!

This commit is contained in:
OnlyPapy98
2025-10-31 16:17:15 +01:00
parent bd3d8a3d3f
commit 159837bd6f
30 changed files with 789 additions and 172 deletions

View File

@@ -2,6 +2,8 @@ package com.example.quiz.data;
import com.example.quiz.data.model.Bet;
import com.example.quiz.data.model.Horse;
import com.example.quiz.data.model.Reunion;
import com.example.quiz.data.model.TypeOfBet;
import java.time.LocalDate;
import java.util.Arrays;
@@ -13,6 +15,16 @@ public class BetsBank {
new Bet(
1,
"Course de chevaux",
new Reunion(1,
"Réunion ",
LocalDate.of(2025,10,1),
"Hippodrome Verssaille"
),
Arrays.asList(
new TypeOfBet(1, "Couplet", "2"),
new TypeOfBet(2, "Tierce", "3"),
new TypeOfBet(3, "Place", "1")
),
LocalDate.of(2025,10,1),
Arrays.asList(
new Horse(1),
@@ -21,20 +33,45 @@ public class BetsBank {
new Horse(4)
)
),
new Bet(
2,
"Course de chevaux 2",
new Reunion(2,
"Réunion 2",
LocalDate.of(2025,10,1),
"Hippodrome Bordeaux"
),
Arrays.asList(
new TypeOfBet(1, "Quarte", "4"),
new TypeOfBet(2, "Quinte", "5"),
new TypeOfBet(3, "Placé", "1")
),
LocalDate.of(2025,10,1),
Arrays.asList(
new Horse(4),
new Horse(5),
new Horse(7),
new Horse(6)
new Horse(6),
new Horse(8),
new Horse(9),
new Horse(10),
new Horse(11)
)
),
new Bet(
3,
"Course de chevaux 3",
new Reunion(2,
"Réunion 2",
LocalDate.of(2025,10,1),
"Hippodrome Bordeaux"
),
Arrays.asList(
new TypeOfBet(1, "Quarte", "4"),
new TypeOfBet(2, "Quinte", "5"),
new TypeOfBet(3, "Placé", "1")
),
LocalDate.of(2025,10,1),
Arrays.asList(
new Horse(10),
@@ -46,6 +83,16 @@ public class BetsBank {
new Bet(
4,
"Course de chevaux 4",
new Reunion(2,
"Réunion 2",
LocalDate.of(2025,10,1),
"Hippodrome Bordeaux"
),
Arrays.asList(
new TypeOfBet(1, "Couple", "2"),
new TypeOfBet(2, "Tierce", "3"),
new TypeOfBet(3, "Quarte", "4")
),
LocalDate.of(2025,10,1),
Arrays.asList(
new Horse(5),

View File

@@ -0,0 +1,80 @@
package com.example.quiz.data.adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.quiz.R;
import com.example.quiz.data.model.TypeOfBet;
import java.util.List;
public class TypeOfBetAdapter extends RecyclerView.Adapter<TypeOfBetAdapter.TypeOfBetViewHolder> {
private List<TypeOfBet> types;
private onItemClickListener listener;
private int selectedPosition = -1;
public interface onItemClickListener{
void onItemClick(TypeOfBet type);
}
public void setOnItemClickListener(TypeOfBetAdapter.onItemClickListener listener){
this.listener = listener;
}
public TypeOfBetAdapter(List<TypeOfBet> types){
this.types = types;
}
public void setTypes(List<TypeOfBet> types){
this.types = types;
notifyDataSetChanged();
}
@NonNull
@Override
public TypeOfBetViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_of_bet_item, parent, false);
return new TypeOfBetViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull TypeOfBetViewHolder holder, int position) {
TypeOfBet type = types.get(position);
holder.type_of_bet_name.setText(type.getName());
if(selectedPosition != position){
holder.itemView.setBackgroundResource(R.drawable.item_gradient_bg);
}else{
holder.itemView.setBackgroundResource(R.drawable.item_gradient_bg_selected);
}
holder.itemView.setOnClickListener(v->{
if(listener != null){
listener.onItemClick(type);
}
int previousPosition = selectedPosition;
selectedPosition = holder.getAdapterPosition();
notifyItemChanged(previousPosition);
notifyItemChanged(selectedPosition);
});
}
@Override
public int getItemCount() {
return types.size();
}
public class TypeOfBetViewHolder extends RecyclerView.ViewHolder {
TextView type_of_bet_name;
public TypeOfBetViewHolder(@NonNull View itemView) {
super(itemView);
type_of_bet_name = itemView.findViewById(R.id.type_of_bet_name);
}
}
}

View File

@@ -8,8 +8,28 @@ public class Bet {
private String name;
private LocalDate date;
private Reunion reunion;
List<TypeOfBet> types;
private List<Horse> horses;
public Reunion getReunion() {
return reunion;
}
public void setReunion(Reunion reunion) {
this.reunion = reunion;
}
public List<TypeOfBet> getTypes() {
return types;
}
public void setTypes(List<TypeOfBet> types) {
this.types = types;
}
public List<Horse> getHorses() {
return horses;
}
@@ -43,9 +63,11 @@ public class Bet {
}
public Bet(int id, String name, LocalDate date, List<Horse> horses) {
public Bet(int id, String name, Reunion reunion, List<TypeOfBet> types, LocalDate date, List<Horse> horses) {
this.id = id;
this.name = name;
this.reunion = reunion;
this.types = types;
this.date = date;
this.horses = horses;
}

View File

@@ -0,0 +1,50 @@
package com.example.quiz.data.model;
import java.time.LocalDate;
public class Reunion {
private int id;
private String name;
private LocalDate date;
private String address;
public Reunion(int id, String name,LocalDate date, String address) {
this.id = id;
this.name = name;
this.date = date;
this.address = address;
}
public void setId(int id) {
this.id = id;
}
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}

View File

@@ -0,0 +1,37 @@
package com.example.quiz.data.model;
public class TypeOfBet {
private int id;
private String name;
private String numberOfHorse;
public TypeOfBet(int id, String name, String numberOfHorse) {
this.id = id;
this.name = name;
this.numberOfHorse = numberOfHorse;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumberOfHorse() {
return numberOfHorse;
}
public void setNumberOfHorse(String numberOfHorse) {
this.numberOfHorse = numberOfHorse;
}
}

View File

@@ -3,6 +3,8 @@ package com.example.quiz.data.repository;
import com.example.quiz.data.BetsBank;
import com.example.quiz.data.model.Bet;
import com.example.quiz.data.model.Horse;
import com.example.quiz.data.model.Reunion;
import com.example.quiz.data.model.TypeOfBet;
import java.util.List;
@@ -43,4 +45,11 @@ public class BetRepository {
return getBetById(id).getName();
}
public List<TypeOfBet> getTypeOfBetByBetId(int id){
return getBetById(id).getTypes();
}
public Reunion getReunionByHorseId(int id){
return getBetById(id).getReunion();
}
}