print successfully integrated!
This commit is contained in:
@@ -55,6 +55,8 @@ dependencies {
|
||||
implementation(libs.recyclerview.v7)
|
||||
implementation(libs.appcompat)
|
||||
implementation(libs.material)
|
||||
implementation(libs.google.core)
|
||||
implementation(libs.zxing.android.embedded)
|
||||
implementation(libs.constraintlayout)
|
||||
implementation(libs.navigation.fragment)
|
||||
implementation(libs.navigation.ui)
|
||||
|
||||
@@ -19,6 +19,8 @@ import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -42,6 +44,10 @@ 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 com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -65,6 +71,7 @@ public class BetValidation extends Fragment {
|
||||
SharedViewModel shared;
|
||||
|
||||
|
||||
private boolean order;
|
||||
|
||||
|
||||
private TypeOfBet typeOfBet;
|
||||
@@ -73,6 +80,8 @@ public class BetValidation extends Fragment {
|
||||
|
||||
private Course course;
|
||||
|
||||
private int coeff;
|
||||
|
||||
private int mise;
|
||||
|
||||
private ActivityResultLauncher<Intent> enableBluetoothLauncher;
|
||||
@@ -83,9 +92,6 @@ public class BetValidation extends Fragment {
|
||||
PariViewModel pariViewModel;
|
||||
|
||||
|
||||
boolean order = false;
|
||||
|
||||
|
||||
|
||||
public BetValidation() {
|
||||
// Required empty public constructor
|
||||
@@ -107,7 +113,34 @@ public class BetValidation extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
binding = FragmentBetValidationBinding.inflate(inflater, container, false);
|
||||
binding.combination.setText(getString(R.string.combination,""));
|
||||
binding.coeff.setText(String.valueOf(1));
|
||||
coeff = Integer.parseInt(binding.coeff.getText().toString());
|
||||
binding.coeff.addTextChangedListener(new TextWatcher(){
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
if(charSequence.toString().isEmpty()){
|
||||
binding.coeff.setError("Le coefficient est obligatoire");
|
||||
return;
|
||||
}
|
||||
if(Integer.parseInt(charSequence.toString())<1){
|
||||
binding.coeff.setError("Le coefficient doit être supérieur ou égal à 1 ");
|
||||
return;
|
||||
}
|
||||
coeff = Integer.parseInt(charSequence.toString());
|
||||
calculateMise(selectedHorses.getValue().size());
|
||||
binding.mise.setText(String.valueOf(mise+" CFA"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
|
||||
}
|
||||
});
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@@ -154,7 +187,7 @@ public class BetValidation extends Fragment {
|
||||
String combinationText = selectedHorses.getValue().stream()
|
||||
.map(h -> h)
|
||||
.collect(Collectors.joining("-"));
|
||||
binding.combination.setText(getString(R.string.combination, combinationText));
|
||||
binding.combination.setText( combinationText);
|
||||
});
|
||||
|
||||
|
||||
@@ -166,6 +199,9 @@ public class BetValidation extends Fragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
shared = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
|
||||
pariViewModel = new ViewModelProvider(this).get(PariViewModel.class);
|
||||
typeOfBet = shared.typeOfBet.getValue();
|
||||
reunion = shared.selectedReunion.getValue();
|
||||
course = shared.selectedCourse.getValue();
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
if(activity != null){
|
||||
MaterialToolbar toolbar = activity.findViewById(R.id.toolbar);
|
||||
@@ -195,17 +231,22 @@ public class BetValidation extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
binding.order.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
order = isChecked;
|
||||
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().getLabel());
|
||||
calculateMise(horses.size());
|
||||
binding.mise.setText(String.valueOf(mise+" CFA"));
|
||||
if(shared.typeOfBet.getValue().getNumberOfHorse() > 2 && horses.size() >= shared.typeOfBet.getValue().getNumberOfHorse()){
|
||||
binding.order.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
binding.order.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
binding.order.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
order = isChecked;
|
||||
calculateMise(selectedHorses.getValue().size());
|
||||
binding.mise.setText(String.valueOf(mise+" CFA"));
|
||||
});
|
||||
|
||||
binding.betValidateBtn.setOnClickListener(v->{
|
||||
@@ -217,12 +258,9 @@ public class BetValidation extends Fragment {
|
||||
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 = typeOfBet.getNumberOfHorse();
|
||||
|
||||
if(selectedHorses.getValue().size() < required){
|
||||
Toast.makeText(getContext(), "Veuillez sélectionner au moins"+required+" chevaux", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
@@ -239,11 +277,11 @@ public class BetValidation extends Fragment {
|
||||
true,
|
||||
new PariCourseDto(shared.selectedCourse.getValue().getId()),
|
||||
selectedHorses.getValue(),
|
||||
order?selectedHorses.getValue():new ArrayList<String>(),
|
||||
order?new ArrayList<String>(): selectedHorses.getValue(),
|
||||
order,
|
||||
"MULTI_4"
|
||||
);
|
||||
pariViewModel.createPari(pari).observe(getViewLifecycleOwner(), new Observer<Result<Pari>>() {
|
||||
pariViewModel.createPari(pari).observe(getViewLifecycleOwner(),new Observer<Result<Pari>>() {
|
||||
@Override
|
||||
public void onChanged(Result<Pari> pariResult) {
|
||||
switch (pariResult.status){
|
||||
@@ -254,7 +292,11 @@ public class BetValidation extends Fragment {
|
||||
Toast.makeText(getContext(), "En cours", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case SUCCESS:
|
||||
printPari();
|
||||
try {
|
||||
printPari(pariResult.data);
|
||||
} catch (WriterException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -266,32 +308,37 @@ public class BetValidation extends Fragment {
|
||||
});
|
||||
|
||||
binding.deleteBtn.setOnClickListener(v->{
|
||||
selectedHorses.setValue(List.of());
|
||||
binding.combination.setText(getString(R.string.combination,""));
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
_initializeToZero();
|
||||
});
|
||||
}
|
||||
|
||||
public void printPari(){
|
||||
public void printPari(Pari pari) throws WriterException {
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.pmu_logo);
|
||||
Bitmap barcode = generateBarcodeBitmap(pari.getNumeroTicket(), 384, 100);
|
||||
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");
|
||||
tspl.append("Bamako").append("\n");
|
||||
tspl.append(shared.selectedCourse.getValue().getNom()).append("\n");
|
||||
|
||||
LocalDateTime dateTime = LocalDateTime.parse(shared.selectedCourse.getValue().getDateDepartCourse());
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
|
||||
String formattedDate = dateTime.format(formatter);
|
||||
tspl.append(formattedDate).append("\n");
|
||||
tspl.append("Course ").append(String.valueOf(shared.selectedCourse.getValue().getId())).append("\n");
|
||||
tspl.append(shared.selectedCourse.getValue().getType()).append("\n");
|
||||
tspl.append("--------------------------------\n");
|
||||
boolean isElargie = selectedHorses.getValue().size()>shared.typeOfBet.getValue().getNumberOfHorse();
|
||||
tspl.append(isElargie?pari.getTypePari()+"/Elargie":pari.getTypePari()).append("\n");
|
||||
String combinationText = selectedHorses.getValue().stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining("-"));
|
||||
|
||||
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");
|
||||
tspl.append(combinationText).append("\n");
|
||||
tspl.append("COEF: "+String.valueOf(coeff)).append(".0").append("\n");
|
||||
tspl.append("--------------------------------\n");
|
||||
tspl.append("MONTANT: ").append(mise).append(" XOF\n");
|
||||
tspl.append("-------------------------------\n");
|
||||
tspl.append("AGENT: ").append(" 3332\n");
|
||||
tspl.append("DATE: ").append(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss").format(LocalDateTime.now())).append("\n");
|
||||
if (BluetoothUtils.needsBluetoothPermissions()) {
|
||||
if (!BluetoothUtils.hasBluetoothPermission(requireContext())) {
|
||||
// Demande la permission si non accordée
|
||||
@@ -302,37 +349,43 @@ public class BetValidation extends Fragment {
|
||||
|
||||
// 2️⃣ Permission OK, on peut afficher la liste
|
||||
try {
|
||||
Printama.with(getContext()).pintTextBuilder(tspl);
|
||||
Printama.with(getContext()).printTextBuilder(tspl, bitmap, pari.getNumeroTicket(), barcode);
|
||||
_initializeToZero();
|
||||
} catch (SecurityException e) {
|
||||
Toast.makeText(requireContext(),
|
||||
"Permission Bluetooth non accordée", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _initializeToZero(){
|
||||
mise = 0;
|
||||
binding.mise.setText(String.valueOf(mise+" CFA"));
|
||||
selectedHorses.setValue(List.of());
|
||||
binding.combination.setText(getString(R.string.combination,""));
|
||||
binding.combination.setText("");
|
||||
binding.order.setChecked(false);
|
||||
order = false;
|
||||
binding.order.setVisibility(View.GONE);
|
||||
binding.coeff.setText("1");
|
||||
coeff = Integer.parseInt(binding.coeff.getText().toString());
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
}
|
||||
|
||||
|
||||
public void calculateMise(int nombreChevauxSelectionnes, String typeOfBet){
|
||||
if(typeOfBet.toString().toLowerCase().contains("couple")){
|
||||
if(nombreChevauxSelectionnes == 2){
|
||||
public void calculateMise(int nombreChevauxSelectionnes){
|
||||
if(typeOfBet.getNumberOfHorse() == 1){
|
||||
if(nombreChevauxSelectionnes==1){
|
||||
mise = 300;
|
||||
}
|
||||
if(nombreChevauxSelectionnes > 2){
|
||||
mise = 300 + (nombreChevauxSelectionnes - 3)*300;
|
||||
}
|
||||
}
|
||||
if(typeOfBet.toString().toLowerCase().contains("tierce")){
|
||||
if(nombreChevauxSelectionnes == 3){
|
||||
if(typeOfBet.getNumberOfHorse() == 2){
|
||||
if(nombreChevauxSelectionnes == 2){
|
||||
mise = 400;
|
||||
}
|
||||
if(nombreChevauxSelectionnes > 3){
|
||||
mise = 400 + (nombreChevauxSelectionnes - 3)*400;
|
||||
if(nombreChevauxSelectionnes > 2){
|
||||
mise = 400 + (nombreChevauxSelectionnes - 2)*300;
|
||||
}
|
||||
}
|
||||
if(typeOfBet.toString().toLowerCase().contains("quarte")){
|
||||
if(typeOfBet.getNumberOfHorse() == 3){
|
||||
if(nombreChevauxSelectionnes == 3){
|
||||
mise = 500;
|
||||
}
|
||||
@@ -340,16 +393,47 @@ public class BetValidation extends Fragment {
|
||||
mise = 500 + (nombreChevauxSelectionnes - 3)*500;
|
||||
}
|
||||
}
|
||||
if(typeOfBet.toString().toLowerCase().contains("quinte")){
|
||||
if(nombreChevauxSelectionnes == 3){
|
||||
mise = 1000;
|
||||
if(typeOfBet.getNumberOfHorse() == 4){
|
||||
if(nombreChevauxSelectionnes == 4){
|
||||
mise = 600;
|
||||
}
|
||||
if(nombreChevauxSelectionnes > 3){
|
||||
mise = 1000 + (nombreChevauxSelectionnes - 3)*1000;
|
||||
if(nombreChevauxSelectionnes > 4){
|
||||
mise = 600 + (nombreChevauxSelectionnes - 4)*600;
|
||||
}
|
||||
}
|
||||
if(typeOfBet.getNumberOfHorse() == 5){
|
||||
if(nombreChevauxSelectionnes == 5){
|
||||
mise = 1200;
|
||||
}
|
||||
if(nombreChevauxSelectionnes > 5){
|
||||
mise = 1200 + (nombreChevauxSelectionnes - 5)*1200;
|
||||
}
|
||||
}
|
||||
mise = order?mise * coeff * _calculateFactorial(shared.typeOfBet.getValue().getNumberOfHorse()):mise * coeff;
|
||||
}
|
||||
|
||||
Integer _calculateFactorial(int n){
|
||||
int f = 1;
|
||||
if(n == 0){
|
||||
return f;
|
||||
}
|
||||
for(int i = 1; i <=n; i++){
|
||||
f *= i;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
public Bitmap generateBarcodeBitmap(String contents, int width, int height) throws WriterException {
|
||||
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.CODE_128, width, height);
|
||||
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
bmp.setPixel(x, y, bitMatrix.get(x, y) ? android.graphics.Color.BLACK : android.graphics.Color.WHITE);
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
public static String generate12Digits() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
|
||||
@@ -66,14 +66,6 @@ public class ListOFBets extends Fragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
if(activity != null){
|
||||
MaterialToolbar toolbar = activity.findViewById(R.id.toolbar);
|
||||
activity.setSupportActionBar(toolbar);
|
||||
if(activity.getSupportActionBar() != null){
|
||||
activity.getSupportActionBar().setTitle("Liste des courses");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,4 +162,17 @@ public class ListOFBets extends Fragment {
|
||||
}
|
||||
}, getViewLifecycleOwner(), Lifecycle.State.RESUMED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
if(activity != null){
|
||||
MaterialToolbar toolbar = activity.findViewById(R.id.toolbar);
|
||||
activity.setSupportActionBar(toolbar);
|
||||
if(activity.getSupportActionBar() != null){
|
||||
activity.getSupportActionBar().setTitle("Liste des courses");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,11 @@ public class ListOfReunions extends Fragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
if (activity != null) {
|
||||
MaterialToolbar toolbar = activity.findViewById(R.id.toolbar);
|
||||
@@ -126,10 +130,8 @@ public class ListOfReunions extends Fragment {
|
||||
activity.getSupportActionBar().show();
|
||||
activity.getSupportActionBar().setTitle("Liste des réunions");
|
||||
}
|
||||
|
||||
toolbar.setBackgroundColor(getResources().getColor(R.color.primary_green, null));
|
||||
toolbar.setTitleTextColor(getResources().getColor(R.color.white, null));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import com.google.android.material.appbar.MaterialToolbar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
|
||||
@@ -57,14 +58,6 @@ public class ListOfTypeOfBets extends Fragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
if(activity != null){
|
||||
MaterialToolbar toolbar = activity.findViewById(R.id.toolbar);
|
||||
activity.setSupportActionBar(toolbar);
|
||||
if(activity.getSupportActionBar() != null){
|
||||
activity.getSupportActionBar().setTitle("Liste des jeux");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,18 +81,8 @@ public class ListOfTypeOfBets extends Fragment {
|
||||
binding.typeOfBetRecyclerView.setAdapter(adapter);
|
||||
List<TypeOfBet> types = List.of(
|
||||
new TypeOfBet(
|
||||
"Simple",
|
||||
"SIMPLE",
|
||||
1
|
||||
),
|
||||
new TypeOfBet(
|
||||
"Jumellé placé",
|
||||
"JUMELLE_PLACE",
|
||||
2
|
||||
),
|
||||
new TypeOfBet(
|
||||
"Jumellé gagnant",
|
||||
"JUMELLE_GAGNANT",
|
||||
"Couple placé",
|
||||
"COUPLE_PLACE",
|
||||
2
|
||||
),
|
||||
new TypeOfBet(
|
||||
@@ -123,25 +106,24 @@ public class ListOfTypeOfBets extends Fragment {
|
||||
5
|
||||
)
|
||||
);
|
||||
|
||||
// Observer les résultats
|
||||
/*viewModel.types.observe(getViewLifecycleOwner(), type -> {
|
||||
List<String> types = List.of();
|
||||
if(type == null){
|
||||
return;
|
||||
String betType = shared.selectedCourse.getValue().getType();
|
||||
Log.d("BET_TYPE", betType);
|
||||
List<TypeOfBet> useList = new ArrayList<>();
|
||||
if(betType.toLowerCase().startsWith("quinte")){
|
||||
useList = types.stream()
|
||||
.filter(bet -> !bet.getName().toLowerCase().contains("quarte"))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
switch (type){
|
||||
case TIERCE:
|
||||
types = List.of("Couple Gagnant", "Couple Place", "Tierce");
|
||||
case QUARTE:
|
||||
types = List.of("Couple Gagnant", "Couple Place", "Tierce", "Quarte");
|
||||
case QUINTE:
|
||||
types = List.of("Couple Gagnant", "Couple Place", "Tierce", "Quinte");
|
||||
break;
|
||||
if(betType.toLowerCase().startsWith("quarte")){
|
||||
useList = types.subList(0, 4);
|
||||
}
|
||||
adapter.setTypes(types);
|
||||
});*/
|
||||
adapter.setTypes(types);
|
||||
if(betType.toLowerCase().startsWith("tierce")){
|
||||
useList = types.subList(0, 3);
|
||||
}
|
||||
if(betType.toLowerCase().contains("couple")){
|
||||
useList = types.subList(0, 2);
|
||||
}
|
||||
adapter.setTypes(useList);
|
||||
adapter.setOnItemClickListener(type -> {
|
||||
shared.setTypeOfBet(type);
|
||||
});
|
||||
@@ -159,4 +141,17 @@ public class ListOfTypeOfBets extends Fragment {
|
||||
.commit();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
AppCompatActivity activity = (AppCompatActivity) getActivity();
|
||||
if(activity != null){
|
||||
MaterialToolbar toolbar = activity.findViewById(R.id.toolbar);
|
||||
activity.setSupportActionBar(toolbar);
|
||||
if(activity.getSupportActionBar() != null){
|
||||
activity.getSupportActionBar().setTitle("Liste des jeux");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,10 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import android.provider.Settings;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -6,11 +6,13 @@ import android.os.Bundle;
|
||||
import com.anggastudio.printama.Pref;
|
||||
import com.anggastudio.printama.Printama;
|
||||
import com.example.quiz.utils.BluetoothUtils;
|
||||
import com.example.quiz.utils.SessionManager;
|
||||
import com.example.quiz.utils.SharedPrefsHelper;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -27,6 +29,10 @@ import dagger.hilt.android.AndroidEntryPoint;
|
||||
@AndroidEntryPoint
|
||||
public class PageQuiz extends AppCompatActivity {
|
||||
|
||||
private SessionManager sessionManager;
|
||||
private Handler handler = new Handler();
|
||||
private Runnable checkRunnable;
|
||||
|
||||
private AppBarConfiguration appBarConfiguration;
|
||||
private ActivityPageQuizBinding binding;
|
||||
|
||||
@@ -60,6 +66,20 @@ public class PageQuiz extends AppCompatActivity {
|
||||
requestPermission();
|
||||
binding = ActivityPageQuizBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
sessionManager = new SessionManager();
|
||||
|
||||
// Vérification périodique
|
||||
checkRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (sessionManager.isExpired()) {
|
||||
Toast.makeText(getApplicationContext(), "I'm herer", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
handler.postDelayed(this, 60 * 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
handler.postDelayed(checkRunnable, 60 * 1000);
|
||||
setSupportActionBar(binding.toolbar);
|
||||
binding.toolbar.setBackgroundColor(Color.parseColor("#501C5A29"));
|
||||
binding.fab.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
public class Course {
|
||||
private int id;
|
||||
private String stype;
|
||||
private String type;
|
||||
private String numero;
|
||||
private String nom;
|
||||
private String lieu;
|
||||
@@ -20,9 +20,9 @@ public class Course {
|
||||
private String statut;
|
||||
private int nombreChevauxInscrits;
|
||||
|
||||
public Course(int id, String stype, String numero, String nom, String lieu, String dateDepartCourse, int reunionId, String particularite, int partants, String statut, int nombreChevauxInscrits) {
|
||||
public Course(int id, String type, 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.type = type;
|
||||
this.numero = numero;
|
||||
this.nom = nom;
|
||||
this.lieu = lieu;
|
||||
@@ -42,12 +42,12 @@ public class Course {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getStype() {
|
||||
return stype;
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setStype(String stype) {
|
||||
this.stype = stype;
|
||||
public void setType(String stype) {
|
||||
this.type = stype;
|
||||
}
|
||||
|
||||
public String getNumero() {
|
||||
|
||||
@@ -20,7 +20,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
||||
@Module
|
||||
@InstallIn(SingletonComponent.class)
|
||||
public class ApiClient {
|
||||
private static final String BASE_URL = "https://e3a593a96788.ngrok-free.app/api/v1/";
|
||||
private static final String BASE_URL = "https://performances-leeds-operations-continued.trycloudflare.com/api/v1/";
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
||||
25
app/src/main/java/com/example/quiz/utils/SessionManager.java
Normal file
25
app/src/main/java/com/example/quiz/utils/SessionManager.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.example.quiz.utils;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class SessionManager {
|
||||
// 10 minutes en millisecondes
|
||||
private static final long sessionExpiredTime = 60 * 1000;
|
||||
|
||||
private LocalDateTime lastExpiredDate;
|
||||
|
||||
public SessionManager() {
|
||||
updateLastExpiredDate();
|
||||
}
|
||||
|
||||
public void updateLastExpiredDate() {
|
||||
lastExpiredDate = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
// Vérifie si le temps écoulé depuis lastExpiredDate > sessionExpiredTime
|
||||
Duration elapsed = Duration.between(lastExpiredDate, LocalDateTime.now());
|
||||
return elapsed.toMillis() > sessionExpiredTime;
|
||||
}
|
||||
}
|
||||
4
app/src/main/res/drawable/combination_text_input.xml
Normal file
4
app/src/main/res/drawable/combination_text_input.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<solid android:color="@color/gray"/>
|
||||
</shape>
|
||||
@@ -2,138 +2,185 @@
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingHorizontal="15dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/gray"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="5dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="15dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="15dp"
|
||||
tools:ignore="UselessParent">
|
||||
<TextView
|
||||
android:text="@string/hors_choice"
|
||||
android:textStyle="bold"
|
||||
android:textSize="25sp"
|
||||
android:layout_marginTop="35dp"
|
||||
android:textColor="@color/text_color"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/horseName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="17sp"
|
||||
android:textColor="@color/primary_green"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginBottom="25dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:textColor="@color/primary_green"
|
||||
android:textFontWeight="300"
|
||||
>
|
||||
android:textSize="17sp">
|
||||
|
||||
</TextView>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingVertical="8dp"
|
||||
android:gravity="start"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="start">
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/combination"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40sp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:background="@drawable/edittext_border"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="10sp"
|
||||
android:text=""
|
||||
android:textColor="@color/primary_green"
|
||||
android:textFontWeight="800"
|
||||
android:textSize="18sp"
|
||||
android:text="@string/combination"
|
||||
android:textColor="@color/primary_green">
|
||||
</TextView>
|
||||
tools:ignore="RtlSymmetry"></TextView>
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:id="@+id/divider3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="13dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_horizontal"
|
||||
>
|
||||
android:orientation="horizontal">
|
||||
|
||||
<GridLayout
|
||||
android:id="@+id/grid_numbers"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:useDefaultMargins="true"/>
|
||||
android:useDefaultMargins="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<!-- Bloc coefficient + checkbox -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:background="@android:color/white"
|
||||
android:elevation="4dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/coefficient"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="#444444" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="12dp">
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/mise"
|
||||
<!-- EditText -->
|
||||
<EditText
|
||||
android:id="@+id/coeff"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="22sp"
|
||||
android:textColor="@color/primary_green"
|
||||
android:textStyle="bold"
|
||||
android:text="0" />
|
||||
|
||||
android:layout_marginEnd="12dp"
|
||||
android:inputType="number"
|
||||
android:textSize="20sp"
|
||||
android:padding="8dp"
|
||||
android:text="1"
|
||||
android:background="@drawable/edittext_border" />
|
||||
<CheckBox
|
||||
android:id="@+id/order"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="12dp"
|
||||
android:text="Ordre" />
|
||||
android:text="@string/tout_ordre"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Mise -->
|
||||
<TextView
|
||||
android:id="@+id/mise"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1"
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/primary_green"
|
||||
android:gravity="center"
|
||||
android:padding="12dp"
|
||||
android:background="@android:color/white"
|
||||
android:elevation="4dp"
|
||||
android:clipToPadding="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/paymentType"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@drawable/edittext_border"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="15dp"
|
||||
android:scrollbarSize="10dp"
|
||||
android:background="@drawable/edittext_border"
|
||||
android:defaultFocusHighlightEnabled="true"
|
||||
android:entries="@array/paymentType">
|
||||
</Spinner>
|
||||
android:entries="@array/paymentType"
|
||||
android:padding="15dp"
|
||||
android:scrollbarSize="10dp"></Spinner>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/phoneNumber"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="15dp"
|
||||
android:drawableStart="@android:drawable/stat_sys_vp_phone_call"
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/edittext_border"
|
||||
android:drawableStart="@android:drawable/stat_sys_vp_phone_call"
|
||||
android:inputType="phone"
|
||||
android:visibility="gone"
|
||||
>
|
||||
</EditText>
|
||||
android:padding="10dp"
|
||||
android:visibility="gone"></EditText>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dp"
|
||||
android:weightSum="3">
|
||||
|
||||
@@ -142,39 +189,36 @@
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:padding="10dp"
|
||||
android:backgroundTint="@color/primary_red"
|
||||
android:text="@string/cancel"
|
||||
android:textColor="@color/white"
|
||||
android:layout_margin="4dp"
|
||||
/>
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@color/primary_red"
|
||||
android:padding="10dp"
|
||||
android:text="@string/cancel"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/deleteBtn"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:padding="10dp"
|
||||
android:backgroundTint="@android:color/holo_blue_dark"
|
||||
android:text="@string/delete"
|
||||
android:textColor="@color/white"
|
||||
android:layout_margin="4dp"
|
||||
/>
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@android:color/holo_blue_dark"
|
||||
android:padding="10dp"
|
||||
android:text="@string/delete"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/betValidateBtn"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:padding="10dp"
|
||||
android:backgroundTint="@color/primary_green"
|
||||
android:text="@string/validate"
|
||||
android:textColor="@color/white"
|
||||
android:layout_margin="4dp"
|
||||
/>
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@color/primary_green"
|
||||
android:padding="10dp"
|
||||
android:text="@string/validate"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="10dp"
|
||||
android:background="@color/text_hint_color">
|
||||
android:background="@color/white">
|
||||
|
||||
<!-- Header -->
|
||||
<LinearLayout
|
||||
|
||||
@@ -69,4 +69,6 @@
|
||||
</string>
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
<string name="coefficient">Coefficient</string>
|
||||
<string name="tout_ordre">Tout ordre</string>
|
||||
</resources>
|
||||
@@ -1,5 +1,6 @@
|
||||
[versions]
|
||||
agp = "8.7.3"
|
||||
googleCore = "3.5.1"
|
||||
hiltAndroid = "2.51"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.3.0"
|
||||
@@ -30,9 +31,11 @@ powermockModuleJunit4 = "2.0.9"
|
||||
preference = "1.1.1"
|
||||
robolectric = "4.11.1"
|
||||
runner = "1.5.2"
|
||||
zxingAndroidEmbedded = "4.3.0"
|
||||
|
||||
[libraries]
|
||||
converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" }
|
||||
google-core = { module = "com.google.zxing:core", version.ref = "googleCore" }
|
||||
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hiltAndroid" }
|
||||
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hiltAndroid" }
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
@@ -65,6 +68,7 @@ preference = { group = "androidx.preference", name = "preference", version.ref =
|
||||
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
|
||||
rules = { module = "androidx.test:rules", version.ref = "core" }
|
||||
runner = { module = "androidx.test:runner", version.ref = "runner" }
|
||||
zxing-android-embedded = { module = "com.journeyapps:zxing-android-embedded", version.ref = "zxingAndroidEmbedded" }
|
||||
|
||||
|
||||
[plugins]
|
||||
|
||||
@@ -351,11 +351,19 @@ public class Printama {
|
||||
});
|
||||
}
|
||||
|
||||
public void pintTextBuilder(StringBuilder text){
|
||||
public void printTextBuilder(StringBuilder text, Bitmap bitmap, String numeroTicket,Bitmap barCode){
|
||||
_printama.connect(printama -> {
|
||||
printama.printImage(bitmap);
|
||||
printama.printText("\n\n--------------------------------\n");
|
||||
printama.printImage(barCode);
|
||||
printama.printText("\n"+numeroTicket+"\n",PA.CENTER);
|
||||
printama.printText("\n--------------------------------\n");
|
||||
printama.setNormalText();
|
||||
_util.setAlign(PA.CENTER);
|
||||
_util.setAlign(PA.LEFT);
|
||||
printTextBuilder(text);
|
||||
printama.printText("--------------------------------\n");
|
||||
printama.printText("Powered by PMU-MALI", PA.CENTER);
|
||||
printama.printText("\n--------------------------------\n \n \n");
|
||||
printama.feedPaper();
|
||||
printama.close();
|
||||
});
|
||||
@@ -554,7 +562,7 @@ public class Printama {
|
||||
}
|
||||
|
||||
private void printTextBuilder(StringBuilder text){
|
||||
text.append("\n \n \n");
|
||||
text.append("\n");
|
||||
_util.printTextBuilder(text);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user