type of game step done!
This commit is contained in:
@@ -12,19 +12,27 @@ import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
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.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;
|
||||
@@ -47,9 +55,9 @@ public class BetValidation extends Fragment {
|
||||
|
||||
private HPRTPrinterUtil printer;
|
||||
|
||||
private Integer id;
|
||||
private TypeOfBet typeOfBet;
|
||||
|
||||
private String typeOfBet;
|
||||
private Reunion reunion;
|
||||
|
||||
private List<Horse> selectedHorses = new ArrayList<Horse>();
|
||||
|
||||
@@ -83,7 +91,7 @@ public class BetValidation extends Fragment {
|
||||
}
|
||||
|
||||
private void setupNumberGrid(GridLayout grid) {
|
||||
|
||||
binding.gridNumbers.removeAllViews();
|
||||
int columns = 4;
|
||||
|
||||
grid.setColumnCount(columns);
|
||||
@@ -133,28 +141,92 @@ public class BetValidation extends Fragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
shared = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
|
||||
viewModel = new ViewModelProvider(this).get(BetViewModel.class);
|
||||
shared.betId.observe(getViewLifecycleOwner(), id ->{
|
||||
this.id = id;
|
||||
viewModel.getBetNameById(id - 1);
|
||||
viewModel.betName.observe(getViewLifecycleOwner(), name ->{
|
||||
binding.horseName.setText(name);
|
||||
});
|
||||
viewModel.loadHorses(id - 1);
|
||||
viewModel.horses.observe(getViewLifecycleOwner(), h->{
|
||||
this.totalHorses = h;
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
});
|
||||
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;
|
||||
});
|
||||
binding.btnValidate.setOnClickListener(v->{
|
||||
//Toast.makeText(getContext(), "L'id de bet: "+this.id+" et le type est: "+this.typeOfBet, Toast.LENGTH_SHORT).show();
|
||||
printer = new HPRTPrinterUtil(getContext());
|
||||
boolean ok = printer.connectBluetooth("02:03:00:00:00:00");
|
||||
if (ok) {
|
||||
printer.printText("Bonjour");
|
||||
viewModel.loadReunionById(shared.betId.getValue() - 1);
|
||||
reunion = viewModel.reunion.getValue();
|
||||
binding.paymentType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
String selected = binding.paymentType.getSelectedItem().toString();
|
||||
|
||||
if (selected.equals("Orange Money")) {
|
||||
binding.phoneNumber.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
binding.phoneNumber.setVisibility(View.GONE); // ou GONE
|
||||
binding.phoneNumber.setText(""); // vider le champ si non utilisé
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
binding.phoneNumber.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
binding.betValidateBtn.setOnClickListener(v->{
|
||||
if(binding.paymentType.getSelectedItem().toString().equals("Orange Money") && binding.phoneNumber.getText().toString().isEmpty()){
|
||||
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){
|
||||
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();
|
||||
return;
|
||||
}
|
||||
printer = new HPRTPrinterUtil(getContext());
|
||||
boolean ok = printer.autoConnectBluetoothByName();
|
||||
if(ok){
|
||||
StringBuilder tspl = new StringBuilder();
|
||||
tspl.append("PARIS HIPPIQUE (PMU MALI)\n");
|
||||
|
||||
tspl.append(typeOfBet.getName()+"\n");
|
||||
tspl.append("Tel: 555-1234\n");
|
||||
tspl.append("----------------------------\n");
|
||||
tspl.append(reunion.getName()+"/"+reunion.getAddress());
|
||||
tspl.append("----------------------------\n");
|
||||
String combinationText = selectedHorses.stream()
|
||||
.map(h -> String.valueOf(h.getNumber()))
|
||||
.collect(Collectors.joining("-"));
|
||||
|
||||
tspl.append("COMBINAISON : "+combinationText);
|
||||
|
||||
tspl.append("\n----------------------------\n");
|
||||
|
||||
int mise = 300;
|
||||
int total = mise * selectedHorses.size();
|
||||
tspl.append("TOTAL MISE: ").append(total).append(" Fcfa\n");
|
||||
tspl.append("----------------------------\n");
|
||||
tspl.append("Bonne chance !\n\n\n");
|
||||
|
||||
printer.printText(tspl);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
binding.backBtn.setOnClickListener(v->{
|
||||
getActivity().onBackPressed();
|
||||
});
|
||||
|
||||
binding.deleteBtn.setOnClickListener(v->{
|
||||
selectedHorses.clear();
|
||||
binding.combination.setText(getString(R.string.combination,""));
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user