break for printer!

This commit is contained in:
OnlyPapy98
2025-11-27 11:54:52 +01:00
parent 8f80492287
commit 1031307b3a
25 changed files with 420 additions and 341 deletions

View File

@@ -17,9 +17,14 @@ import com.example.quiz.viewModel.SharedViewModel;
import java.util.ArrayList;
import java.util.List;
public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder> {
private List<Course> bets = new ArrayList<>();
private onItemClickListener listener;
private SharedViewModel shared;
public BetsAdapter(SharedViewModel shared) {
this.shared = shared;
}
public interface onItemClickListener {
void onItemClick(Course bet);
@@ -29,8 +34,6 @@ public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder>
this.listener = listener;
}
public void setBets(List<Course> bets){
this.bets = bets;
notifyDataSetChanged();
@@ -39,26 +42,27 @@ public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder>
@NonNull
@Override
public BetViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_bet, parent, false);
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_bet, parent, false);
return new BetViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull BetViewHolder holder, int position) {
Course bet = bets.get(position);
holder.tvDate.setText(String.valueOf(bet.getDateDepartCourse()));
holder.tvName.setText(String.valueOf(bet.getLieu()));
holder.tvReunion.setText("Nom de la réunion");
holder.itemView.setOnClickListener(v->{
if(listener != null){
listener.onItemClick(bet);
}
holder.tvName.setText(bet.getNom());
if (shared != null && shared.selectedReunion.getValue() != null) {
holder.tvReunion.setText(shared.selectedReunion.getValue().getNom());
}
holder.itemView.setOnClickListener(v -> {
if (listener != null) listener.onItemClick(bet);
});
}
@Override
public int getItemCount(){
return bets.size();
@@ -66,13 +70,12 @@ public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder>
static class BetViewHolder extends RecyclerView.ViewHolder{
TextView tvName, tvDate, tvReunion;
public BetViewHolder(@NonNull View itemView) {
super(itemView);
tvName = itemView.findViewById(R.id.tvName);
tvDate = itemView.findViewById(R.id.tvDate);
tvReunion = itemView.findViewById(R.id.tvReunion);
}
}
}

View File

@@ -14,24 +14,24 @@ import com.example.quiz.data.model.TypeOfBet;
import java.util.List;
public class TypeOfBetAdapter extends RecyclerView.Adapter<TypeOfBetAdapter.TypeOfBetViewHolder> {
private List<String> types;
private List<TypeOfBet> types;
private onItemClickListener listener;
private int selectedPosition = -1;
public interface onItemClickListener{
void onItemClick(String type);
void onItemClick(TypeOfBet type);
}
public void setOnItemClickListener(TypeOfBetAdapter.onItemClickListener listener){
this.listener = listener;
}
public TypeOfBetAdapter(List<String> types){
public TypeOfBetAdapter(List<TypeOfBet> types){
this.types = types;
}
public void setTypes(List<String> types){
public void setTypes(List<TypeOfBet> types){
this.types = types;
notifyDataSetChanged();
}
@@ -46,8 +46,8 @@ public class TypeOfBetAdapter extends RecyclerView.Adapter<TypeOfBetAdapter.Type
@Override
public void onBindViewHolder(@NonNull TypeOfBetViewHolder holder, int position) {
String type = types.get(position);
holder.type_of_bet_name.setText(type);
TypeOfBet type = types.get(position);
holder.type_of_bet_name.setText(type.getLabel());
if(selectedPosition != position){
holder.itemView.setBackgroundResource(R.drawable.item_gradient_bg);
}else{

View File

@@ -9,24 +9,29 @@ import java.util.List;
public class Course {
private int id;
private String stype;
private String numero;
private String nom;
private String lieu;
private LocalDateTime dateDepartCourse;
private String reunion;
private String dateDepartCourse;
private int reunionId;
private String particularite;
private int partants;
private String statut;
private int nombreChevauxInscrits;
private List<Cheval> chevaux;
public Course(int id, String numero, String nom, String lieu, LocalDateTime dateDepartCourse, String reunion, int nombreChevauxInscrits, List<Cheval> chevaux) {
public Course(int id, String stype, String numero, String nom, String lieu, String dateDepartCourse, int reunionId, String particularite, int partants, String statut, int nombreChevauxInscrits) {
this.id = id;
this.stype = stype;
this.numero = numero;
this.nom = nom;
this.lieu = lieu;
this.dateDepartCourse = dateDepartCourse;
this.reunion = reunion;
this.reunionId = reunionId;
this.particularite = particularite;
this.partants = partants;
this.statut = statut;
this.nombreChevauxInscrits = nombreChevauxInscrits;
this.chevaux = chevaux;
}
public int getId() {
@@ -37,6 +42,14 @@ public class Course {
this.id = id;
}
public String getStype() {
return stype;
}
public void setStype(String stype) {
this.stype = stype;
}
public String getNumero() {
return numero;
}
@@ -61,20 +74,44 @@ public class Course {
this.lieu = lieu;
}
public LocalDateTime getDateDepartCourse() {
public String getDateDepartCourse() {
return dateDepartCourse;
}
public void setDateDepartCourse(LocalDateTime dateDepartCourse) {
public void setDateDepartCourse(String dateDepartCourse) {
this.dateDepartCourse = dateDepartCourse;
}
public String getReunion() {
return reunion;
public int getReunionId() {
return reunionId;
}
public void setReunion(String reunion) {
this.reunion = reunion;
public void setReunionId(int reunionId) {
this.reunionId = reunionId;
}
public String getParticularite() {
return particularite;
}
public void setParticularite(String particularite) {
this.particularite = particularite;
}
public int getPartants() {
return partants;
}
public void setPartants(int partants) {
this.partants = partants;
}
public String getStatut() {
return statut;
}
public void setStatut(String statut) {
this.statut = statut;
}
public int getNombreChevauxInscrits() {
@@ -84,12 +121,4 @@ public class Course {
public void setNombreChevauxInscrits(int nombreChevauxInscrits) {
this.nombreChevauxInscrits = nombreChevauxInscrits;
}
public List<Cheval> getChevaux() {
return chevaux;
}
public void setChevaux(List<Cheval> chevaux) {
this.chevaux = chevaux;
}
}

View File

@@ -1,83 +1,36 @@
package com.example.quiz.data.model;
import com.example.quiz.data.model.enums.CourseType;
import com.example.quiz.data.model.dtos.PariCourseDto;
import com.example.quiz.data.model.enums.PariStatut;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
public class Pari {
private String numeroTicket;
private String typePari;
private String typeFormule;
private int mise;
private double mise;
private String datePari;
private int courseId;
private String idParieur;
private String nomParieur;
private int cheval;
private int cheval1;
private int cheval2;
private int cheval3;
private int premier;
private int deuxieme;
private int troisieme;
private List<Integer> chevauxOrdre;
private List<Integer> chevauxSelectionnes;
private List<Integer> ordrePredit;
private boolean validationOrdreExact;
private String typeMulti;
private PariStatut status;
private boolean estPaye;
private boolean estRembourse;
private PariCourseDto course;
private List<String> chevauxSelectionnes;
private List<String> ordrePredit;
private boolean validationOrdreExact;
private String typeMulti;
public Pari(
String numeroTicket,
String typePari,
String typeFormule,
int mise,
String datePari,
int courseId,
String idParieur,
String nomParieur,
int cheval,
int cheval1,
int cheval2,
int cheval3,
int premier,
int deuxieme,
int troisieme,
List<Integer> chevauxOrdre,
List<Integer> chevauxSelectionnes,
List<Integer> ordrePredit,
boolean validationOrdreExact,
String typeMulti,
PariStatut status,
boolean estPaye,
boolean estRembourse) {
public Pari(String numeroTicket, String typePari, String typeFormule, double mise, String datePari, boolean estPaye, boolean estRembourse, PariCourseDto course, List<String> chevauxSelectionnes, List<String> ordrePredit, boolean validationOrdreExact, String typeMulti) {
this.numeroTicket = numeroTicket;
this.typePari = typePari;
this.typeFormule = typeFormule;
this.mise = mise;
this.datePari = datePari;
this.courseId = courseId;
this.idParieur = idParieur;
this.nomParieur = nomParieur;
this.cheval = cheval;
this.cheval1 = cheval1;
this.cheval2 = cheval2;
this.cheval3 = cheval3;
this.premier = premier;
this.deuxieme = deuxieme;
this.troisieme = troisieme;
this.chevauxOrdre = chevauxOrdre;
this.estPaye = estPaye;
this.estRembourse = estRembourse;
this.course = course;
this.chevauxSelectionnes = chevauxSelectionnes;
this.ordrePredit = ordrePredit;
this.validationOrdreExact = validationOrdreExact;
this.typeMulti = typeMulti;
this.status = status;
this.estPaye = estPaye;
this.estRembourse = estRembourse;
}
public String getNumeroTicket() {
@@ -104,11 +57,11 @@ public class Pari {
this.typeFormule = typeFormule;
}
public int getMise() {
public double getMise() {
return mise;
}
public void setMise(int mise) {
public void setMise(double mise) {
this.mise = mise;
}
@@ -120,107 +73,43 @@ public class Pari {
this.datePari = datePari;
}
public int getCourseId() {
return courseId;
public boolean isEstPaye() {
return estPaye;
}
public void setCourseId(int courseId) {
this.courseId = courseId;
public void setEstPaye(boolean estPaye) {
this.estPaye = estPaye;
}
public String getIdParieur() {
return idParieur;
public boolean isEstRembourse() {
return estRembourse;
}
public void setIdParieur(String idParieur) {
this.idParieur = idParieur;
public void setEstRembourse(boolean estRembourse) {
this.estRembourse = estRembourse;
}
public String getNomParieur() {
return nomParieur;
public PariCourseDto getCourse() {
return course;
}
public void setNomParieur(String nomParieur) {
this.nomParieur = nomParieur;
public void setCourse(PariCourseDto course) {
this.course = course;
}
public int getCheval() {
return cheval;
}
public void setCheval(int cheval) {
this.cheval = cheval;
}
public int getCheval1() {
return cheval1;
}
public void setCheval1(int cheval1) {
this.cheval1 = cheval1;
}
public int getCheval2() {
return cheval2;
}
public void setCheval2(int cheval2) {
this.cheval2 = cheval2;
}
public int getCheval3() {
return cheval3;
}
public void setCheval3(int cheval3) {
this.cheval3 = cheval3;
}
public int getPremier() {
return premier;
}
public void setPremier(int premier) {
this.premier = premier;
}
public int getDeuxieme() {
return deuxieme;
}
public void setDeuxieme(int deuxieme) {
this.deuxieme = deuxieme;
}
public int getTroisieme() {
return troisieme;
}
public void setTroisieme(int troisieme) {
this.troisieme = troisieme;
}
public List<Integer> getChevauxOrdre() {
return chevauxOrdre;
}
public void setChevauxOrdre(List<Integer> chevauxOrdre) {
this.chevauxOrdre = chevauxOrdre;
}
public List<Integer> getChevauxSelectionnes() {
public List<String> getChevauxSelectionnes() {
return chevauxSelectionnes;
}
public void setChevauxSelectionnes(List<Integer> chevauxSelectionnes) {
public void setChevauxSelectionnes(List<String> chevauxSelectionnes) {
this.chevauxSelectionnes = chevauxSelectionnes;
}
public List<Integer> getOrdrePredit() {
public List<String> getOrdrePredit() {
return ordrePredit;
}
public void setOrdrePredit(List<Integer> ordrePredit) {
public void setOrdrePredit(List<String> ordrePredit) {
this.ordrePredit = ordrePredit;
}
@@ -239,28 +128,4 @@ public class Pari {
public void setTypeMulti(String typeMulti) {
this.typeMulti = typeMulti;
}
public PariStatut getStatus() {
return status;
}
public void setStatus(PariStatut status) {
this.status = status;
}
public boolean isEstPaye() {
return estPaye;
}
public void setEstPaye(boolean estPaye) {
this.estPaye = estPaye;
}
public boolean isEstRembourse() {
return estRembourse;
}
public void setEstRembourse(boolean estRembourse) {
this.estRembourse = estRembourse;
}
}

View File

@@ -6,12 +6,12 @@ public class Reunion {
private int id;
private String code;
private String nom;
private LocalDate date;
private String date;
private int numero;
private Hippodrome hippodrome;
private int totalCourses;
public Reunion(int id, String code, String nom, LocalDate date, int numero, Hippodrome hippodrome, int totalCourses) {
public Reunion(int id, String code, String nom, String date, int numero, Hippodrome hippodrome, int totalCourses) {
this.id = id;
this.code = code;
this.nom = nom;
@@ -45,11 +45,11 @@ public class Reunion {
this.nom = nom;
}
public LocalDate getDate() {
public String getDate() {
return date;
}
public void setDate(LocalDate date) {
public void setDate(String date) {
this.date = date;
}

View File

@@ -1,22 +1,23 @@
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;
private String label;
private String name;
private int numberOfHorse;
public TypeOfBet(String label, String name, int numberOfHorse) {
this.label = label;
this.name = name;
this.numberOfHorse = numberOfHorse;
}
public int getId() {
return id;
public String getLabel() {
return label;
}
public void setId(int id) {
this.id = id;
public void setLabel(String label) {
this.label = label;
}
public String getName() {
@@ -27,11 +28,11 @@ public class TypeOfBet {
this.name = name;
}
public String getNumberOfHorse() {
public int getNumberOfHorse() {
return numberOfHorse;
}
public void setNumberOfHorse(String numberOfHorse) {
public void setNumberOfHorse(int numberOfHorse) {
this.numberOfHorse = numberOfHorse;
}
}

View File

@@ -0,0 +1,17 @@
package com.example.quiz.data.model.dtos;
public class PariCourseDto {
private int id;
public PariCourseDto(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

View File

@@ -20,7 +20,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
@Module
@InstallIn(SingletonComponent.class)
public class ApiClient {
private static final String BASE_URL = "https://api.pmu.ml/api/v1/";
private static final String BASE_URL = "https://b440a25a7658.ngrok-free.app/api/v1/";
@Provides
@Singleton

View File

@@ -10,14 +10,15 @@ import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
public interface ApiService {
@GET("reunions")
Call<List<Reunion>> getReunions();
@GET("course/avenir")
Call<List<Course>> getCourses();
@GET("courses/reunion/{reunionId}")
Call<List<Course>> getCourses(@Path("reunionId") String reunionId);
@POST("/pari")
@POST("pari")
Call<Pari> createPari(@Body Pari pari);
}

View File

@@ -1,5 +1,7 @@
package com.example.quiz.data.repository;
import android.util.Log;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
@@ -23,10 +25,10 @@ public class CourseRepository {
this.apiService = apiService;
}
public LiveData<Result<List<Course>>> getCourses() {
public LiveData<Result<List<Course>>> getCourses(String reunionId) {
MutableLiveData<Result<List<Course>>> liveCourses = new MutableLiveData<Result<List<Course>>>();
liveCourses.setValue(Result.loading());
apiService.getCourses().enqueue(new Callback<List<Course>>() {
apiService.getCourses(reunionId).enqueue(new Callback<List<Course>>() {
@Override
public void onResponse(Call<List<Course>> call, Response<List<Course>> response) {
if(response.isSuccessful()){

View File

@@ -25,24 +25,37 @@ public class PariRepository {
}
public LiveData<Result<Pari>> createPari(Pari pari) {
MutableLiveData<Result<Pari>> pariResponse = new MutableLiveData<Result<Pari>>();
MutableLiveData<Result<Pari>> pariResponse = new MutableLiveData<>();
pariResponse.setValue(Result.loading());
apiService.createPari(pari).enqueue(new Callback<Pari>() {
@Override
public void onResponse(Call<Pari> call, Response<Pari> response) {
if(response.isSuccessful()){
if (response.isSuccessful() && response.body() != null) {
pariResponse.postValue(Result.success(response.body()));
}else {
pariResponse.postValue(Result.error(response.message()));
} else {
// On récupère l'erreur exacte envoyée par le backend
try {
String errorBody = response.errorBody() != null ?
response.errorBody().string() : "Erreur inconnue";
pariResponse.postValue(Result.error(errorBody));
} catch (Exception e) {
pariResponse.postValue(Result.error("Erreur serveur"));
}
}
}
@Override
public void onFailure(Call<Pari> call, Throwable throwable) {
pariResponse.postValue(Result.error(throwable.getMessage()));
public void onFailure(Call<Pari> call, Throwable t) {
pariResponse.postValue(Result.error(t.getMessage()));
}
});
return pariResponse;
}
}