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

@@ -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<List<String>>() {
@Override
public void onChanged(List<String> 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<String>(),
order,
shared.typeOfBet.getValue(),
PariStatut.PERDANT,
false,
false
"MULTI_4"
);
pariViewModel.createPari(pari).observe(getViewLifecycleOwner(), new Observer<Result<Pari>>() {
@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,""));