diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 231a5d1..376eca5 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,7 +11,7 @@ android { defaultConfig { applicationId = "com.example.quiz" - minSdk = 29 + minSdk = 16 targetSdk = 34 versionCode = 1 versionName = "1.0" @@ -29,8 +29,8 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } buildFeatures { viewBinding = true diff --git a/app/libs/TSPL_V1.21.jar b/app/libs/TSPL_V1.21.jar deleted file mode 100644 index 4b8c151..0000000 Binary files a/app/libs/TSPL_V1.21.jar and /dev/null differ diff --git a/app/src/main/java/com/example/quiz/BetValidation.java b/app/src/main/java/com/example/quiz/BetValidation.java index 2dbe7a0..9306707 100644 --- a/app/src/main/java/com/example/quiz/BetValidation.java +++ b/app/src/main/java/com/example/quiz/BetValidation.java @@ -1,9 +1,12 @@ package com.example.quiz; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LiveData; @@ -25,16 +28,20 @@ import com.example.quiz.data.model.Course; import com.example.quiz.data.model.Pari; import com.example.quiz.data.model.Reunion; import com.example.quiz.data.model.TypeOfBet; +import com.example.quiz.data.model.dtos.PariCourseDto; import com.example.quiz.data.model.enums.PariStatut; import com.example.quiz.databinding.FragmentBetValidationBinding; import com.example.quiz.utils.HPRTPrinterUtil; import com.example.quiz.utils.Result; import com.example.quiz.viewModel.PariViewModel; import com.example.quiz.viewModel.SharedViewModel; +import com.google.android.material.appbar.MaterialToolbar; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import dagger.hilt.android.AndroidEntryPoint; @@ -55,7 +62,7 @@ public class BetValidation extends Fragment { private HPRTPrinterUtil printer; - private String typeOfBet; + private TypeOfBet typeOfBet; private Reunion reunion; @@ -101,7 +108,7 @@ public class BetValidation extends Fragment { int columns = 7; grid.setColumnCount(columns); if(shared.selectedCourse.getValue() != null){ - for (int i = 1; i <= shared.selectedCourse.getValue().getNombreChevauxInscrits(); i++) { + for (int i = 1; i <= shared.selectedCourse.getValue().getPartants(); i++) { createNumberItem(String.valueOf(i)); grid.addView(createNumberItem(String.valueOf(i))); } @@ -151,15 +158,14 @@ public class BetValidation extends Fragment { super.onViewCreated(view, savedInstanceState); shared = new ViewModelProvider(requireActivity()).get(SharedViewModel.class); pariViewModel = new ViewModelProvider(this).get(PariViewModel.class); - /*viewModel = new ViewModelProvider(this).get(BetViewModel.class); - viewModel.getBetNameById(shared.betId.getValue() - 1); - viewModel.betName.observe(getViewLifecycleOwner(), name ->{ - binding.horseName.setText(name); - }); - viewModel.loadHorses(shared.betId.getValue() - 1); - if(viewModel.partant.getValue() != null){ - this.totalHorses = viewModel.partant.getValue(); - }*/ + AppCompatActivity activity = (AppCompatActivity) getActivity(); + if(activity != null){ + MaterialToolbar toolbar = activity.findViewById(R.id.toolbar); + activity.setSupportActionBar(toolbar); + if(activity.getSupportActionBar() != null){ + activity.getSupportActionBar().setTitle("Pari "+shared.selectedCourse.getValue().getNom()); + } + } setupNumberGrid(binding.gridNumbers); binding.paymentType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @@ -183,13 +189,13 @@ public class BetValidation extends Fragment { binding.order.setOnCheckedChangeListener((buttonView, isChecked) -> { order = isChecked; - calculateMise(selectedHorses.getValue().size(), shared.typeOfBet.getValue()); + calculateMise(selectedHorses.getValue().size(), shared.typeOfBet.getValue().getLabel()); }); selectedHorses.observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(List horses) { - calculateMise(horses.size(), shared.typeOfBet.getValue()); + calculateMise(horses.size(), shared.typeOfBet.getValue().getLabel()); binding.mise.setText(String.valueOf(mise+" CFA")); } }); @@ -207,53 +213,27 @@ public class BetValidation extends Fragment { reunion = shared.selectedReunion.getValue(); course = shared.selectedCourse.getValue(); - int required = 0; - if(typeOfBet.toLowerCase().contains("couple")){ - required = 2; - } - if(typeOfBet.toLowerCase().contains("tierce")){ - required = 3; - } - if(typeOfBet.toLowerCase().contains("quarte")){ - required = 4; - } - if(typeOfBet.toLowerCase().contains("quinte")){ - required = 5; - } + int required = typeOfBet.getNumberOfHorse(); - if(required == 0){ - Toast.makeText(getContext(), "Erreur de type de pari", Toast.LENGTH_SHORT).show(); - return; - } if(selectedHorses.getValue().size() < required){ Toast.makeText(getContext(), "Veuillez sélectionner au moins"+required+" chevaux", Toast.LENGTH_SHORT).show(); return; } + Pari pari = new Pari( generate12Digits(), - shared.typeOfBet.getValue(), - "QUARTE_PLUS", + shared.typeOfBet.getValue().getName(), + "GAGNANT", mise, - "07/11/2025 05:08:00", - shared.selectedCourse.getValue().getId(), - "123456789", - "John Doe", - 1, - 5, - 6, - 4, - 11, - 5, - 10, - order?selectedHorses.getValue().stream().map(Integer::parseInt).collect(Collectors.toList()):List.of(), - selectedHorses.getValue().stream().map(Integer::parseInt).collect(Collectors.toList()), - order?selectedHorses.getValue().stream().map(Integer::parseInt).collect(Collectors.toList()):List.of(), + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss").format(LocalDateTime.now()), + true, + true, + new PariCourseDto(shared.selectedCourse.getValue().getId()), + selectedHorses.getValue(), + order?selectedHorses.getValue():new ArrayList(), order, - shared.typeOfBet.getValue(), - PariStatut.PERDANT, - false, - false + "MULTI_4" ); pariViewModel.createPari(pari).observe(getViewLifecycleOwner(), new Observer>() { @Override @@ -288,6 +268,7 @@ public class BetValidation extends Fragment { printer = new HPRTPrinterUtil(getContext()); boolean ok = printer.autoConnectBluetoothByName(); if(ok){ + Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pmu_logo); StringBuilder tspl = new StringBuilder(); tspl.append("PARIS HIPPIQUE (PMU MALI)\n"); @@ -307,7 +288,7 @@ public class BetValidation extends Fragment { tspl.append("----------------------------\n"); tspl.append("Bonne chance !\n\n\n"); - printer.printText(tspl); + printer.printText(bitmap, tspl); } selectedHorses.setValue(List.of()); binding.combination.setText(getString(R.string.combination,"")); diff --git a/app/src/main/java/com/example/quiz/ListOFBets.java b/app/src/main/java/com/example/quiz/ListOFBets.java index 10440f3..f3c30f8 100644 --- a/app/src/main/java/com/example/quiz/ListOFBets.java +++ b/app/src/main/java/com/example/quiz/ListOFBets.java @@ -80,11 +80,12 @@ public class ListOFBets extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentListOFBettingBinding.inflate(inflater, container, false); - adapter = new BetsAdapter(); + + shared = new ViewModelProvider(requireActivity()).get(SharedViewModel.class); + adapter = new BetsAdapter(shared); binding.recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2)); binding.recyclerView.setAdapter(adapter); viewModel = new ViewModelProvider(this).get(CourseViewModel.class); - shared = new ViewModelProvider(requireActivity()).get(SharedViewModel.class); @@ -107,7 +108,7 @@ public class ListOFBets extends Fragment { } public void observe(){ - viewModel.getCourses().observe(getViewLifecycleOwner(), new Observer>>() { + viewModel.getCourses(String.valueOf(shared.selectedReunion.getValue().getId())).observe(getViewLifecycleOwner(), new Observer>>() { @Override public void onChanged(Result> result) { switch (result.status){ diff --git a/app/src/main/java/com/example/quiz/ListOfTypeOfBets.java b/app/src/main/java/com/example/quiz/ListOfTypeOfBets.java index 3cd090f..c3cb4e2 100644 --- a/app/src/main/java/com/example/quiz/ListOfTypeOfBets.java +++ b/app/src/main/java/com/example/quiz/ListOfTypeOfBets.java @@ -19,6 +19,7 @@ import android.widget.Button; import android.widget.Toast; import com.example.quiz.data.adapter.TypeOfBetAdapter; +import com.example.quiz.data.model.TypeOfBet; import com.example.quiz.databinding.FragmentListOfTypeOfBetsBinding; import com.example.quiz.viewModel.SharedViewModel; import com.google.android.material.appbar.MaterialToolbar; @@ -85,7 +86,43 @@ public class ListOfTypeOfBets extends Fragment { adapter = new TypeOfBetAdapter(new ArrayList<>()); adapter.setOnItemClickListener(type -> shared.setTypeOfBet(type)); binding.typeOfBetRecyclerView.setAdapter(adapter); - List types = List.of("Couple Gagnant", "Couple Place", "Tierce", "Quinte"); + List types = List.of( + new TypeOfBet( + "Simple", + "SIMPLE", + 1 + ), + new TypeOfBet( + "Jumellé placé", + "JUMELLE_PLACE", + 2 + ), + new TypeOfBet( + "Jumellé gagnant", + "JUMELLE_GAGNANT", + 2 + ), + new TypeOfBet( + "Couple gagnant", + "COUPLE_GAGNANT", + 2 + ), + new TypeOfBet( + "Tierce", + "TRIPLET", + 3 + ), + new TypeOfBet( + "Quarte +", + "QUARTE_PLUS", + 4 + ), + new TypeOfBet( + "Quinte +", + "QUINTE_PLUS", + 5 + ) + ); // Observer les résultats /*viewModel.types.observe(getViewLifecycleOwner(), type -> { diff --git a/app/src/main/java/com/example/quiz/data/adapter/BetsAdapter.java b/app/src/main/java/com/example/quiz/data/adapter/BetsAdapter.java index 8f5252c..626ae41 100644 --- a/app/src/main/java/com/example/quiz/data/adapter/BetsAdapter.java +++ b/app/src/main/java/com/example/quiz/data/adapter/BetsAdapter.java @@ -17,9 +17,14 @@ import com.example.quiz.viewModel.SharedViewModel; import java.util.ArrayList; import java.util.List; public class BetsAdapter extends RecyclerView.Adapter { + private List 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 this.listener = listener; } - - public void setBets(List bets){ this.bets = bets; notifyDataSetChanged(); @@ -39,26 +42,27 @@ public class BetsAdapter extends RecyclerView.Adapter @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 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); } - } - } diff --git a/app/src/main/java/com/example/quiz/data/adapter/TypeOfBetAdapter.java b/app/src/main/java/com/example/quiz/data/adapter/TypeOfBetAdapter.java index e3cc766..2aa9d3f 100644 --- a/app/src/main/java/com/example/quiz/data/adapter/TypeOfBetAdapter.java +++ b/app/src/main/java/com/example/quiz/data/adapter/TypeOfBetAdapter.java @@ -14,24 +14,24 @@ import com.example.quiz.data.model.TypeOfBet; import java.util.List; public class TypeOfBetAdapter extends RecyclerView.Adapter { - private List types; + private List 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 types){ + public TypeOfBetAdapter(List types){ this.types = types; } - public void setTypes(List types){ + public void setTypes(List types){ this.types = types; notifyDataSetChanged(); } @@ -46,8 +46,8 @@ public class TypeOfBetAdapter extends RecyclerView.Adapter chevaux; - - public Course(int id, String numero, String nom, String lieu, LocalDateTime dateDepartCourse, String reunion, int nombreChevauxInscrits, List 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 getChevaux() { - return chevaux; - } - - public void setChevaux(List chevaux) { - this.chevaux = chevaux; - } } diff --git a/app/src/main/java/com/example/quiz/data/model/Pari.java b/app/src/main/java/com/example/quiz/data/model/Pari.java index 8e08071..e191aa9 100644 --- a/app/src/main/java/com/example/quiz/data/model/Pari.java +++ b/app/src/main/java/com/example/quiz/data/model/Pari.java @@ -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 chevauxOrdre; - private List chevauxSelectionnes; - private List ordrePredit; - private boolean validationOrdreExact; - private String typeMulti; - private PariStatut status; private boolean estPaye; private boolean estRembourse; + private PariCourseDto course; + private List chevauxSelectionnes; + private List 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 chevauxOrdre, - List chevauxSelectionnes, - List 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 chevauxSelectionnes, List 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 getChevauxOrdre() { - return chevauxOrdre; - } - - public void setChevauxOrdre(List chevauxOrdre) { - this.chevauxOrdre = chevauxOrdre; - } - - public List getChevauxSelectionnes() { + public List getChevauxSelectionnes() { return chevauxSelectionnes; } - public void setChevauxSelectionnes(List chevauxSelectionnes) { + public void setChevauxSelectionnes(List chevauxSelectionnes) { this.chevauxSelectionnes = chevauxSelectionnes; } - public List getOrdrePredit() { + public List getOrdrePredit() { return ordrePredit; } - public void setOrdrePredit(List ordrePredit) { + public void setOrdrePredit(List 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; - } } diff --git a/app/src/main/java/com/example/quiz/data/model/Reunion.java b/app/src/main/java/com/example/quiz/data/model/Reunion.java index b5eff14..16fd2c8 100644 --- a/app/src/main/java/com/example/quiz/data/model/Reunion.java +++ b/app/src/main/java/com/example/quiz/data/model/Reunion.java @@ -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; } diff --git a/app/src/main/java/com/example/quiz/data/model/TypeOfBet.java b/app/src/main/java/com/example/quiz/data/model/TypeOfBet.java index f11794e..ebc8311 100644 --- a/app/src/main/java/com/example/quiz/data/model/TypeOfBet.java +++ b/app/src/main/java/com/example/quiz/data/model/TypeOfBet.java @@ -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; } } diff --git a/app/src/main/java/com/example/quiz/data/model/dtos/PariCourseDto.java b/app/src/main/java/com/example/quiz/data/model/dtos/PariCourseDto.java new file mode 100644 index 0000000..8086a9e --- /dev/null +++ b/app/src/main/java/com/example/quiz/data/model/dtos/PariCourseDto.java @@ -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; + } +} diff --git a/app/src/main/java/com/example/quiz/data/remote/ApiClient.java b/app/src/main/java/com/example/quiz/data/remote/ApiClient.java index 2931aed..2f10f8f 100644 --- a/app/src/main/java/com/example/quiz/data/remote/ApiClient.java +++ b/app/src/main/java/com/example/quiz/data/remote/ApiClient.java @@ -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 diff --git a/app/src/main/java/com/example/quiz/data/remote/ApiService.java b/app/src/main/java/com/example/quiz/data/remote/ApiService.java index 9355dc9..9c429a3 100644 --- a/app/src/main/java/com/example/quiz/data/remote/ApiService.java +++ b/app/src/main/java/com/example/quiz/data/remote/ApiService.java @@ -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> getReunions(); - @GET("course/avenir") - Call> getCourses(); + @GET("courses/reunion/{reunionId}") + Call> getCourses(@Path("reunionId") String reunionId); - @POST("/pari") + @POST("pari") Call createPari(@Body Pari pari); } diff --git a/app/src/main/java/com/example/quiz/data/repository/CourseRepository.java b/app/src/main/java/com/example/quiz/data/repository/CourseRepository.java index 807411d..ce0c08c 100644 --- a/app/src/main/java/com/example/quiz/data/repository/CourseRepository.java +++ b/app/src/main/java/com/example/quiz/data/repository/CourseRepository.java @@ -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>> getCourses() { + public LiveData>> getCourses(String reunionId) { MutableLiveData>> liveCourses = new MutableLiveData>>(); liveCourses.setValue(Result.loading()); - apiService.getCourses().enqueue(new Callback>() { + apiService.getCourses(reunionId).enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { if(response.isSuccessful()){ diff --git a/app/src/main/java/com/example/quiz/data/repository/PariRepository.java b/app/src/main/java/com/example/quiz/data/repository/PariRepository.java index 8881203..41763eb 100644 --- a/app/src/main/java/com/example/quiz/data/repository/PariRepository.java +++ b/app/src/main/java/com/example/quiz/data/repository/PariRepository.java @@ -25,24 +25,37 @@ public class PariRepository { } public LiveData> createPari(Pari pari) { - MutableLiveData> pariResponse = new MutableLiveData>(); + MutableLiveData> pariResponse = new MutableLiveData<>(); pariResponse.setValue(Result.loading()); + apiService.createPari(pari).enqueue(new Callback() { @Override public void onResponse(Call call, Response 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 call, Throwable throwable) { - pariResponse.postValue(Result.error(throwable.getMessage())); + public void onFailure(Call call, Throwable t) { + pariResponse.postValue(Result.error(t.getMessage())); } }); + return pariResponse; } + } diff --git a/app/src/main/java/com/example/quiz/utils/HPRTPrinterUtil.java b/app/src/main/java/com/example/quiz/utils/HPRTPrinterUtil.java index 2a18cf0..d890d2c 100644 --- a/app/src/main/java/com/example/quiz/utils/HPRTPrinterUtil.java +++ b/app/src/main/java/com/example/quiz/utils/HPRTPrinterUtil.java @@ -6,9 +6,15 @@ import android.bluetooth.BluetoothDevice; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.os.Environment; import android.util.Log; import android.widget.Toast; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.util.Set; @@ -87,18 +93,25 @@ public class HPRTPrinterUtil { } } - public void printText(StringBuilder text) { + public void printText(Bitmap logo, StringBuilder text) { try { if (!HPRTPrinterHelper.IsOpened()) { Toast.makeText(context, "Imprimante non connectée", Toast.LENGTH_SHORT).show(); return; } + + + Bitmap resized = resizeForPrinter(logo, 384); + + HPRTPrinterHelper.printImage("0", "0", resized, false); - // TSPL pur pour texte simple String tspl = ""+ text + "\r\n"; + + + // Envoi à l'imprimante - HPRTPrinterHelper.PrintData(tspl); + //HPRTPrinterHelper.PrintData(tspl); Log.d(TAG, "Texte imprimé sur ticket"); // on log seulement le succès @@ -110,6 +123,7 @@ public class HPRTPrinterUtil { + public void printTSPLTemplate(String tsplTemplate) { try { if (!HPRTPrinterHelper.IsOpened()) { @@ -125,6 +139,121 @@ public class HPRTPrinterUtil { } } + public static Bitmap toMonochrome(Bitmap src) { + int width = src.getWidth(); + int height = src.getHeight(); + + // Bitmap de sortie en ARGB_8888 + Bitmap bw = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int pixel = src.getPixel(x, y); + + // Calcul de la luminance (grayscale) + int gray = (Color.red(pixel) + Color.green(pixel) + Color.blue(pixel)) / 3; + + // Seuil pour décider noir ou blanc + if (gray < 128) { + bw.setPixel(x, y, Color.BLACK); + } else { + bw.setPixel(x, y, Color.WHITE); + } + } + } + + return bw; + } + + + public static byte[] bitmapToEscPos(Bitmap bitmap) throws IOException { + bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false); + + int width = bitmap.getWidth(); + int height = bitmap.getHeight(); + + int bytesPerRow = (width + 7) / 8; + byte[] imageBytes = new byte[bytesPerRow * height]; + + int index = 0; + + for (int y = 0; y < height; y++) { + int bitIndex = 0; + byte currentByte = 0; + + for (int x = 0; x < width; x++) { + int color = bitmap.getPixel(x, y); + int gray = (Color.red(color) + Color.green(color) + Color.blue(color)) / 3; + + currentByte <<= 1; + if (gray < 128) currentByte |= 1; + + bitIndex++; + + if (bitIndex == 8) { + imageBytes[index++] = currentByte; + currentByte = 0; + bitIndex = 0; + } + } + + if (bitIndex > 0) { + currentByte <<= (8 - bitIndex); + imageBytes[index++] = currentByte; + } + } + + // Préfixe ESC/POS GS v 0 + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + baos.write(0x1D); + baos.write('v'); + baos.write('0'); + baos.write(0); // Normal mode + baos.write(bytesPerRow & 0xFF); + baos.write((bytesPerRow >> 8) & 0xFF); + baos.write(height & 0xFF); + baos.write((height >> 8) & 0xFF); + baos.write(imageBytes); + + return baos.toByteArray(); + } + + + public static Bitmap resizeForPrinter(Bitmap bmp, int maxWidth){ + if(bmp.getWidth() <= maxWidth) return bmp; + int newHeight = bmp.getHeight() * maxWidth / bmp.getWidth(); + return Bitmap.createScaledBitmap(bmp, maxWidth, newHeight, false); + } + + // 2. Convertir le bitmap monochrome en flux binaire TSPL + public static byte[] bitmapToTsplBinary(Bitmap bmp){ + int width = bmp.getWidth(); + int height = bmp.getHeight(); + int bytesPerRow = (width + 7) / 8; + byte[] data = new byte[bytesPerRow*height]; + int index = 0; + for(int y=0;y>> getCourses(){ + public LiveData>> getCourses(String reunionId){ if(courses == null){ - courses = courseRepository.getCourses(); + courses = courseRepository.getCourses(reunionId); } return courses; } diff --git a/app/src/main/java/com/example/quiz/viewModel/SharedViewModel.java b/app/src/main/java/com/example/quiz/viewModel/SharedViewModel.java index 20a7809..f1e3cf5 100644 --- a/app/src/main/java/com/example/quiz/viewModel/SharedViewModel.java +++ b/app/src/main/java/com/example/quiz/viewModel/SharedViewModel.java @@ -16,7 +16,7 @@ public class SharedViewModel extends ViewModel { public MutableLiveData selectedReunion = new MutableLiveData(); public MutableLiveData selectedCourse = new MutableLiveData(); - public MutableLiveData typeOfBet = new MutableLiveData(); + public MutableLiveData typeOfBet = new MutableLiveData(); public void setSelectedReunion(Reunion reunion){ @@ -26,7 +26,7 @@ public class SharedViewModel extends ViewModel { public void setSelectedCourse(Course course){ selectedCourse.setValue(course); } - public void setTypeOfBet(String type){ + public void setTypeOfBet(TypeOfBet type){ typeOfBet.setValue(type); } } diff --git a/app/src/main/res/drawable/circle_primary.xml b/app/src/main/res/drawable/circle_primary.xml index 13ad651..8fb0b69 100644 --- a/app/src/main/res/drawable/circle_primary.xml +++ b/app/src/main/res/drawable/circle_primary.xml @@ -1,4 +1,3 @@ - - + diff --git a/app/src/main/res/drawable/ic_right_arrow.xml b/app/src/main/res/drawable/ic_right_arrow.xml new file mode 100644 index 0000000..d25191c --- /dev/null +++ b/app/src/main/res/drawable/ic_right_arrow.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/item_gradient_bg.xml b/app/src/main/res/drawable/item_gradient_bg.xml index ce31cc0..cc67f2d 100644 --- a/app/src/main/res/drawable/item_gradient_bg.xml +++ b/app/src/main/res/drawable/item_gradient_bg.xml @@ -1,8 +1,7 @@ - - + diff --git a/app/src/main/res/drawable/item_gradient_bg_selected.xml b/app/src/main/res/drawable/item_gradient_bg_selected.xml index 9176411..dd78ff9 100644 --- a/app/src/main/res/drawable/item_gradient_bg_selected.xml +++ b/app/src/main/res/drawable/item_gradient_bg_selected.xml @@ -4,8 +4,8 @@ diff --git a/app/src/main/res/layout/fragment_list_of_type_of_bets.xml b/app/src/main/res/layout/fragment_list_of_type_of_bets.xml index 2ab508a..e1eede4 100644 --- a/app/src/main/res/layout/fragment_list_of_type_of_bets.xml +++ b/app/src/main/res/layout/fragment_list_of_type_of_bets.xml @@ -1,19 +1,17 @@ - + android:background="@color/text_hint_color"> + + android:paddingTop="10dp"> - + - + - + android:layout_height="0dp" + android:layout_weight="1" + android:clipToPadding="false" + android:paddingVertical="10dp" + android:scrollbars="vertical" /> + diff --git a/app/src/main/res/layout/type_of_bet_item.xml b/app/src/main/res/layout/type_of_bet_item.xml index 5c615de..1fd7e60 100644 --- a/app/src/main/res/layout/type_of_bet_item.xml +++ b/app/src/main/res/layout/type_of_bet_item.xml @@ -1,31 +1,27 @@ - + android:layout_marginVertical="3dp" + android:layout_marginHorizontal="12dp" + card_view:cardCornerRadius="20dp" + card_view:cardElevation="8dp" + android:foreground="?attr/selectableItemBackground"> + android:clipToPadding="false"> - + + android:background="@drawable/circle_primary" /> + android:singleLine="true" /> - + + android:src="@drawable/ic_right_arrow" + card_view:tint="@android:color/white" /> - \ No newline at end of file +