http request call done
This commit is contained in:
@@ -17,24 +17,14 @@ import android.widget.GridLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.quiz.data.model.Horse;
|
||||
import com.example.quiz.data.model.Course;
|
||||
import com.example.quiz.data.model.Reunion;
|
||||
import com.example.quiz.data.model.TypeOfBet;
|
||||
import com.example.quiz.databinding.FragmentBetValidationBinding;
|
||||
|
||||
import com.example.quiz.utils.HPRTPrinterUtil;
|
||||
import com.example.quiz.viewModel.BetViewModel;
|
||||
import com.example.quiz.viewModel.SharedViewModel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
|
||||
/**
|
||||
@@ -50,18 +40,18 @@ public class BetValidation extends Fragment {
|
||||
|
||||
SharedViewModel shared;
|
||||
|
||||
BetViewModel viewModel;
|
||||
|
||||
|
||||
private HPRTPrinterUtil printer;
|
||||
|
||||
private TypeOfBet typeOfBet;
|
||||
private String typeOfBet;
|
||||
|
||||
private Reunion reunion;
|
||||
|
||||
private List<Horse> selectedHorses = new ArrayList<Horse>();
|
||||
private Course course;
|
||||
|
||||
private List<String> selectedHorses = new ArrayList<String>();
|
||||
|
||||
private List<Horse> totalHorses;
|
||||
|
||||
|
||||
|
||||
@@ -92,27 +82,28 @@ public class BetValidation extends Fragment {
|
||||
|
||||
private void setupNumberGrid(GridLayout grid) {
|
||||
binding.gridNumbers.removeAllViews();
|
||||
int columns = 4;
|
||||
|
||||
int columns = 7;
|
||||
grid.setColumnCount(columns);
|
||||
|
||||
if(totalHorses != null){
|
||||
totalHorses.stream()
|
||||
.map(this::createNumberItem)
|
||||
.forEach(grid::addView);
|
||||
if(shared.selectedCourse.getValue() != null){
|
||||
for (int i = 1; i <= shared.selectedCourse.getValue().getNombreChevauxInscrits(); i++) {
|
||||
createNumberItem(String.valueOf(i));
|
||||
grid.addView(createNumberItem(String.valueOf(i)));
|
||||
}
|
||||
}
|
||||
createNumberItem("X");
|
||||
grid.addView(createNumberItem("X"));
|
||||
}
|
||||
|
||||
private TextView createNumberItem(Horse horse) {
|
||||
private TextView createNumberItem(String horse) {
|
||||
TextView textView = new TextView(requireContext());
|
||||
textView.setText(String.valueOf(horse.getNumber()));
|
||||
textView.setText(horse);
|
||||
textView.setTextColor(getResources().getColor(R.color.white));
|
||||
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
|
||||
params.setMargins(10, 10, 10, 10);
|
||||
params.setMargins(1, 1, 1, 1);
|
||||
textView.setLayoutParams(params);
|
||||
textView.setTextSize(21);
|
||||
textView.setWidth(130);
|
||||
textView.setHeight(130);
|
||||
textView.setTextSize(10);
|
||||
textView.setWidth(80);
|
||||
textView.setHeight(100);
|
||||
textView.setGravity(Gravity.CENTER);
|
||||
textView.setBackgroundResource(R.drawable.number_background);
|
||||
textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
@@ -128,7 +119,7 @@ public class BetValidation extends Fragment {
|
||||
v.setBackgroundResource(R.drawable.number_selected_background);
|
||||
}
|
||||
String combinationText = selectedHorses.stream()
|
||||
.map(h -> String.valueOf(h.getNumber()))
|
||||
.map(h -> h)
|
||||
.collect(Collectors.joining("-"));
|
||||
binding.combination.setText(getString(R.string.combination, combinationText));
|
||||
});
|
||||
@@ -140,21 +131,17 @@ public class BetValidation extends Fragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
shared = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
|
||||
viewModel = new ViewModelProvider(this).get(BetViewModel.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);
|
||||
viewModel.horses.observe(getViewLifecycleOwner(), h->{
|
||||
this.totalHorses = h;
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
});
|
||||
shared.typeOfBet.observe(getViewLifecycleOwner(), type ->{
|
||||
this.typeOfBet = type;
|
||||
});
|
||||
viewModel.loadReunionById(shared.betId.getValue() - 1);
|
||||
reunion = viewModel.reunion.getValue();
|
||||
if(viewModel.partant.getValue() != null){
|
||||
this.totalHorses = viewModel.partant.getValue();
|
||||
}*/
|
||||
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
binding.paymentType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
@@ -180,13 +167,34 @@ public class BetValidation extends Fragment {
|
||||
Toast.makeText(getContext(), "Veuillez entrer un numéro de téléphone", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
Integer required = Integer.parseInt(typeOfBet.getNumberOfHorse());
|
||||
if(required == null){
|
||||
|
||||
if(shared.typeOfBet == null || shared.selectedReunion.getValue() == null || shared.selectedCourse == null){
|
||||
return;
|
||||
}
|
||||
typeOfBet = shared.typeOfBet.getValue();
|
||||
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;
|
||||
}
|
||||
|
||||
if(required == 0){
|
||||
Toast.makeText(getContext(), "Erreur de type de pari", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if(selectedHorses.size() != required){
|
||||
Toast.makeText(getContext(), "Veuillez sélectionner "+required+" chevaux", Toast.LENGTH_SHORT).show();
|
||||
if(selectedHorses.size() < required){
|
||||
Toast.makeText(getContext(), "Veuillez sélectionner au moins"+required+" chevaux", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
printer = new HPRTPrinterUtil(getContext());
|
||||
@@ -195,16 +203,16 @@ public class BetValidation extends Fragment {
|
||||
StringBuilder tspl = new StringBuilder();
|
||||
tspl.append("PARIS HIPPIQUE (PMU MALI)\n");
|
||||
|
||||
tspl.append(typeOfBet.getName()+"\n");
|
||||
tspl.append(typeOfBet).append("\n");
|
||||
tspl.append("Tel: 555-1234\n");
|
||||
tspl.append("----------------------------\n");
|
||||
tspl.append(reunion.getName()+"/"+reunion.getAddress());
|
||||
tspl.append(reunion.getNom()).append("/").append(course.getLieu());
|
||||
tspl.append("----------------------------\n");
|
||||
String combinationText = selectedHorses.stream()
|
||||
.map(h -> String.valueOf(h.getNumber()))
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining("-"));
|
||||
|
||||
tspl.append("COMBINAISON : "+combinationText);
|
||||
tspl.append("COMBINAISON : ").append(combinationText);
|
||||
|
||||
tspl.append("\n----------------------------\n");
|
||||
|
||||
@@ -216,7 +224,9 @@ public class BetValidation extends Fragment {
|
||||
|
||||
printer.printText(tspl);
|
||||
}
|
||||
|
||||
selectedHorses = List.of();
|
||||
binding.combination.setText(getString(R.string.combination,""));
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
});
|
||||
|
||||
binding.backBtn.setOnClickListener(v->{
|
||||
|
||||
Reference in New Issue
Block a user