new printer integration!
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package com.example.quiz;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
@@ -24,6 +29,7 @@ import android.widget.GridLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.anggastudio.printama.Printama;
|
||||
import com.example.quiz.data.model.Course;
|
||||
import com.example.quiz.data.model.Pari;
|
||||
import com.example.quiz.data.model.Reunion;
|
||||
@@ -31,7 +37,7 @@ 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.BluetoothUtils;
|
||||
import com.example.quiz.utils.Result;
|
||||
import com.example.quiz.viewModel.PariViewModel;
|
||||
import com.example.quiz.viewModel.SharedViewModel;
|
||||
@@ -60,7 +66,6 @@ public class BetValidation extends Fragment {
|
||||
|
||||
|
||||
|
||||
private HPRTPrinterUtil printer;
|
||||
|
||||
private TypeOfBet typeOfBet;
|
||||
|
||||
@@ -70,6 +75,9 @@ public class BetValidation extends Fragment {
|
||||
|
||||
private int mise;
|
||||
|
||||
private ActivityResultLauncher<Intent> enableBluetoothLauncher;
|
||||
|
||||
|
||||
private final MutableLiveData<List<String>> selectedHorses = new MutableLiveData<>(List.of());
|
||||
|
||||
PariViewModel pariViewModel;
|
||||
@@ -265,36 +273,48 @@ public class BetValidation extends Fragment {
|
||||
}
|
||||
|
||||
public void printPari(){
|
||||
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");
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pmu_logo);
|
||||
StringBuilder tspl = new StringBuilder();
|
||||
tspl.append("PARIS HIPPIQUE (PMU MALI)\n");
|
||||
|
||||
tspl.append(typeOfBet).append("\n");
|
||||
tspl.append("Tel: 555-1234\n");
|
||||
tspl.append("----------------------------\n");
|
||||
tspl.append(reunion.getNom()).append("/").append(course.getLieu());
|
||||
tspl.append("----------------------------\n");
|
||||
String combinationText = selectedHorses.getValue().stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining("-"));
|
||||
tspl.append(typeOfBet).append("\n");
|
||||
tspl.append("Tel: 555-1234\n");
|
||||
tspl.append("----------------------------\n");
|
||||
tspl.append(reunion.getNom()).append("/").append(course.getLieu());
|
||||
tspl.append("----------------------------\n");
|
||||
String combinationText = selectedHorses.getValue().stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining("-"));
|
||||
|
||||
tspl.append("COMBINAISON : ").append(combinationText);
|
||||
tspl.append("COMBINAISON : ").append(combinationText);
|
||||
|
||||
tspl.append("\n----------------------------\n");
|
||||
tspl.append("TOTAL MISE: ").append(mise).append(" Fcfa\n");
|
||||
tspl.append("----------------------------\n");
|
||||
tspl.append("Bonne chance !\n\n\n");
|
||||
|
||||
printer.printText(bitmap, tspl);
|
||||
tspl.append("\n----------------------------\n");
|
||||
tspl.append("TOTAL MISE: ").append(mise).append(" Fcfa\n");
|
||||
tspl.append("----------------------------\n");
|
||||
tspl.append("Bonne chance !\n\n\n");
|
||||
if (BluetoothUtils.needsBluetoothPermissions()) {
|
||||
if (!BluetoothUtils.hasBluetoothPermission(requireContext())) {
|
||||
// Demande la permission si non accordée
|
||||
BluetoothUtils.requestBluetoothPermission(requireActivity());
|
||||
return; // arrête ici, la popup va apparaître
|
||||
}
|
||||
}
|
||||
|
||||
// 2️⃣ Permission OK, on peut afficher la liste
|
||||
try {
|
||||
Printama.with(getContext()).pintTextBuilder(tspl);
|
||||
} catch (SecurityException e) {
|
||||
Toast.makeText(requireContext(),
|
||||
"Permission Bluetooth non accordée", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
selectedHorses.setValue(List.of());
|
||||
binding.combination.setText(getString(R.string.combination,""));
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
}
|
||||
|
||||
|
||||
public void calculateMise(int nombreChevauxSelectionnes, String typeOfBet){
|
||||
if(typeOfBet.toString().toLowerCase().contains("couple")){
|
||||
if(nombreChevauxSelectionnes == 2){
|
||||
|
||||
Reference in New Issue
Block a user