create pari
This commit is contained in:
@@ -5,6 +5,10 @@ import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import android.util.Log;
|
||||
@@ -18,10 +22,17 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
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.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 java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -50,9 +61,14 @@ public class BetValidation extends Fragment {
|
||||
|
||||
private Course course;
|
||||
|
||||
private List<String> selectedHorses = new ArrayList<String>();
|
||||
private int mise;
|
||||
|
||||
private final MutableLiveData<List<String>> selectedHorses = new MutableLiveData<>(List.of());
|
||||
|
||||
PariViewModel pariViewModel;
|
||||
|
||||
|
||||
boolean order = false;
|
||||
|
||||
|
||||
|
||||
@@ -107,22 +123,25 @@ public class BetValidation extends Fragment {
|
||||
textView.setGravity(Gravity.CENTER);
|
||||
textView.setBackgroundResource(R.drawable.number_background);
|
||||
textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
|
||||
textView.setOnClickListener(v -> {
|
||||
if (selectedHorses.contains(horse)) {
|
||||
selectedHorses.remove(horse);
|
||||
v.setSelected(false);
|
||||
v.setBackgroundResource(R.drawable.number_background);
|
||||
} else {
|
||||
selectedHorses.add(horse);
|
||||
v.setSelected(true);
|
||||
v.setBackgroundResource(R.drawable.number_selected_background);
|
||||
}
|
||||
String combinationText = selectedHorses.stream()
|
||||
.map(h -> h)
|
||||
.collect(Collectors.joining("-"));
|
||||
binding.combination.setText(getString(R.string.combination, combinationText));
|
||||
});
|
||||
final List<String> horses = new ArrayList<>(selectedHorses.getValue());
|
||||
if (horses.contains(horse)) {
|
||||
horses.remove(horse);
|
||||
selectedHorses.setValue(horses);
|
||||
v.setSelected(false);
|
||||
v.setBackgroundResource(R.drawable.number_background);
|
||||
} else {
|
||||
horses.add(horse);
|
||||
selectedHorses.setValue(horses);
|
||||
v.setSelected(true);
|
||||
v.setBackgroundResource(R.drawable.number_selected_background);
|
||||
}
|
||||
String combinationText = selectedHorses.getValue().stream()
|
||||
.map(h -> h)
|
||||
.collect(Collectors.joining("-"));
|
||||
binding.combination.setText(getString(R.string.combination, combinationText));
|
||||
});
|
||||
|
||||
|
||||
return textView;
|
||||
}
|
||||
@@ -131,6 +150,7 @@ 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);
|
||||
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 ->{
|
||||
@@ -161,6 +181,18 @@ public class BetValidation extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
binding.order.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
order = isChecked;
|
||||
calculateMise(selectedHorses.getValue().size(), shared.typeOfBet.getValue());
|
||||
});
|
||||
|
||||
selectedHorses.observe(getViewLifecycleOwner(), new Observer<List<String>>() {
|
||||
@Override
|
||||
public void onChanged(List<String> horses) {
|
||||
calculateMise(horses.size(), shared.typeOfBet.getValue());
|
||||
binding.mise.setText(String.valueOf(mise+" CFA"));
|
||||
}
|
||||
});
|
||||
|
||||
binding.betValidateBtn.setOnClickListener(v->{
|
||||
if(binding.paymentType.getSelectedItem().toString().equals("Orange Money") && binding.phoneNumber.getText().toString().isEmpty()){
|
||||
@@ -193,40 +225,52 @@ public class BetValidation extends Fragment {
|
||||
Toast.makeText(getContext(), "Erreur de type de pari", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if(selectedHorses.size() < required){
|
||||
if(selectedHorses.getValue().size() < required){
|
||||
Toast.makeText(getContext(), "Veuillez sélectionner au moins"+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).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.stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining("-"));
|
||||
|
||||
tspl.append("COMBINAISON : ").append(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);
|
||||
}
|
||||
selectedHorses = List.of();
|
||||
binding.combination.setText(getString(R.string.combination,""));
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
Pari pari = new Pari(
|
||||
generate12Digits(),
|
||||
shared.typeOfBet.getValue(),
|
||||
"QUARTE_PLUS",
|
||||
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(),
|
||||
order,
|
||||
shared.typeOfBet.getValue(),
|
||||
PariStatut.PERDANT,
|
||||
false,
|
||||
false
|
||||
);
|
||||
pariViewModel.createPari(pari).observe(getViewLifecycleOwner(), new Observer<Result<Pari>>() {
|
||||
@Override
|
||||
public void onChanged(Result<Pari> pariResult) {
|
||||
switch (pariResult.status){
|
||||
case ERROR:
|
||||
Toast.makeText(getContext(), pariResult.message, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case LOADING:
|
||||
Toast.makeText(getContext(), "En cours", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case SUCCESS:
|
||||
printPari();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
binding.backBtn.setOnClickListener(v->{
|
||||
@@ -234,12 +278,87 @@ public class BetValidation extends Fragment {
|
||||
});
|
||||
|
||||
binding.deleteBtn.setOnClickListener(v->{
|
||||
selectedHorses.clear();
|
||||
selectedHorses.setValue(List.of());
|
||||
binding.combination.setText(getString(R.string.combination,""));
|
||||
setupNumberGrid(binding.gridNumbers);
|
||||
});
|
||||
}
|
||||
|
||||
public void printPari(){
|
||||
printer = new HPRTPrinterUtil(getContext());
|
||||
boolean ok = printer.autoConnectBluetoothByName();
|
||||
if(ok){
|
||||
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("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(tspl);
|
||||
}
|
||||
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){
|
||||
mise = 300;
|
||||
}
|
||||
if(nombreChevauxSelectionnes > 2){
|
||||
mise = 300 + (nombreChevauxSelectionnes - 3)*300;
|
||||
}
|
||||
}
|
||||
if(typeOfBet.toString().toLowerCase().contains("tierce")){
|
||||
if(nombreChevauxSelectionnes == 3){
|
||||
mise = 400;
|
||||
}
|
||||
if(nombreChevauxSelectionnes > 3){
|
||||
mise = 400 + (nombreChevauxSelectionnes - 3)*400;
|
||||
}
|
||||
}
|
||||
if(typeOfBet.toString().toLowerCase().contains("quarte")){
|
||||
if(nombreChevauxSelectionnes == 3){
|
||||
mise = 500;
|
||||
}
|
||||
if(nombreChevauxSelectionnes > 3){
|
||||
mise = 500 + (nombreChevauxSelectionnes - 3)*500;
|
||||
}
|
||||
}
|
||||
if(typeOfBet.toString().toLowerCase().contains("quinte")){
|
||||
if(nombreChevauxSelectionnes == 3){
|
||||
mise = 1000;
|
||||
}
|
||||
if(nombreChevauxSelectionnes > 3){
|
||||
mise = 1000 + (nombreChevauxSelectionnes - 3)*1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String generate12Digits() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int digit = (int) (Math.random() * 10); // 0 à 9
|
||||
sb.append(digit);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
@@ -6,14 +6,20 @@ import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.view.MenuHost;
|
||||
import androidx.core.view.MenuProvider;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
@@ -130,5 +136,37 @@ public class ListOFBets extends Fragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
MenuHost menuHost = requireActivity();
|
||||
|
||||
// 🔹 On enlève d'abord les anciens menu providers si ce fragment est recréé
|
||||
menuHost.invalidateMenu();
|
||||
|
||||
// 🔹 Ajout du menu spécifique à ce fragment
|
||||
menuHost.addMenuProvider(new MenuProvider() {
|
||||
@Override
|
||||
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
|
||||
// Nettoyer avant d'inflater
|
||||
menu.clear();
|
||||
menuInflater.inflate(R.menu.menu_main, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
|
||||
int id = menuItem.getItemId();
|
||||
|
||||
if (id == R.id.action_sold) {
|
||||
FragmentManager fragmentManager = getParentFragmentManager();
|
||||
Sold sold = Sold.newInstance();
|
||||
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.nav_host_fragment_content_main, sold)
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}, getViewLifecycleOwner(), Lifecycle.State.RESUMED);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.view.MenuHost;
|
||||
import androidx.core.view.MenuProvider;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.Observer;
|
||||
@@ -13,6 +15,9 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
@@ -73,6 +78,10 @@ public class ListOfReunions extends Fragment {
|
||||
binding.reunionsList.setAdapter(adapter);
|
||||
reunionViewModel = new ViewModelProvider(this).get(ReunionViewModel.class);
|
||||
shared = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
|
||||
binding.reunionsLayout.setOnRefreshListener(()->{
|
||||
observeReunions();
|
||||
binding.reunionsLayout.setRefreshing(false);
|
||||
});
|
||||
observeReunions();
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
105
app/src/main/java/com/example/quiz/Sold.java
Normal file
105
app/src/main/java/com/example/quiz/Sold.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package com.example.quiz;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.quiz.databinding.FragmentSoldBinding;
|
||||
import com.google.android.material.appbar.MaterialToolbar;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link Sold#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class Sold extends Fragment {
|
||||
|
||||
FragmentSoldBinding binding;
|
||||
|
||||
public Sold() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static Sold newInstance() {
|
||||
Sold fragment = new Sold();
|
||||
Bundle args = new Bundle();
|
||||
fragment.setArguments(args);
|
||||
return 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("Soldes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentSoldBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
binding.btnByCourse.setOnClickListener(v -> {
|
||||
FragmentManager fragmentManager = getParentFragmentManager();
|
||||
SoldByCourse soldByCourse = SoldByCourse.newInstance();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.nav_host_fragment_content_main, soldByCourse)
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
});
|
||||
|
||||
binding.btnByDay.setOnClickListener(v->{
|
||||
_showCalendar();
|
||||
});
|
||||
}
|
||||
|
||||
void _showCalendar(){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
||||
DatePickerDialog datePickerDialog = new DatePickerDialog(
|
||||
getContext(),
|
||||
(view, year, month, dayOfMonth) -> {
|
||||
String date = dayOfMonth + "/" + (month + 1) + "/" + year;
|
||||
//Toast.makeText(getContext(), date, Toast.LENGTH_SHORT).show();
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle("Solde")
|
||||
.setMessage("Solde la course 3000CFA")
|
||||
.setPositiveButton("Ok", (dialog, which)->{
|
||||
dialog.dismiss();
|
||||
}).show();
|
||||
},
|
||||
calendar.get(Calendar.YEAR),
|
||||
calendar.get(Calendar.MONTH),
|
||||
calendar.get(Calendar.DAY_OF_MONTH)
|
||||
);
|
||||
|
||||
datePickerDialog.show();
|
||||
}
|
||||
}
|
||||
70
app/src/main/java/com/example/quiz/SoldByCourse.java
Normal file
70
app/src/main/java/com/example/quiz/SoldByCourse.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package com.example.quiz;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.example.quiz.databinding.FragmentSoldByCourseBinding;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link SoldByCourse#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class SoldByCourse extends Fragment {
|
||||
|
||||
FragmentSoldByCourseBinding binding;
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
|
||||
public static SoldByCourse newInstance() {
|
||||
SoldByCourse fragment = new SoldByCourse();
|
||||
Bundle args = new Bundle();
|
||||
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
binding = FragmentSoldByCourseBinding.inflate(inflater, container, false);
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
binding.btnCheckBalance.setOnClickListener(v -> {
|
||||
if(binding.etRaceNumber.getText().toString().isEmpty()){
|
||||
binding.etRaceNumber.setError("Veuillez entrer un numéro de course");
|
||||
return;
|
||||
}
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle("Solde")
|
||||
.setMessage("Solde la course 3000CFA")
|
||||
.setPositiveButton("Ok", (dialog, which) -> {
|
||||
binding.etRaceNumber.setText("");
|
||||
dialog.dismiss();
|
||||
})
|
||||
.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
266
app/src/main/java/com/example/quiz/data/model/Pari.java
Normal file
266
app/src/main/java/com/example/quiz/data/model/Pari.java
Normal file
@@ -0,0 +1,266 @@
|
||||
package com.example.quiz.data.model;
|
||||
|
||||
import com.example.quiz.data.model.enums.CourseType;
|
||||
import com.example.quiz.data.model.enums.PariStatut;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public class Pari {
|
||||
private String numeroTicket;
|
||||
private String typePari;
|
||||
private String typeFormule;
|
||||
private int mise;
|
||||
private String datePari;
|
||||
private int courseId;
|
||||
private String idParieur;
|
||||
private String nomParieur;
|
||||
private int cheval;
|
||||
private int cheval1;
|
||||
private int cheval2;
|
||||
private int cheval3;
|
||||
private int premier;
|
||||
private int deuxieme;
|
||||
private int troisieme;
|
||||
private List<Integer> chevauxOrdre;
|
||||
private List<Integer> chevauxSelectionnes;
|
||||
private List<Integer> ordrePredit;
|
||||
private boolean validationOrdreExact;
|
||||
private String typeMulti;
|
||||
private PariStatut status;
|
||||
private boolean estPaye;
|
||||
private boolean estRembourse;
|
||||
|
||||
public Pari(
|
||||
String numeroTicket,
|
||||
String typePari,
|
||||
String typeFormule,
|
||||
int mise,
|
||||
String datePari,
|
||||
int courseId,
|
||||
String idParieur,
|
||||
String nomParieur,
|
||||
int cheval,
|
||||
int cheval1,
|
||||
int cheval2,
|
||||
int cheval3,
|
||||
int premier,
|
||||
int deuxieme,
|
||||
int troisieme,
|
||||
List<Integer> chevauxOrdre,
|
||||
List<Integer> chevauxSelectionnes,
|
||||
List<Integer> ordrePredit,
|
||||
boolean validationOrdreExact,
|
||||
String typeMulti,
|
||||
PariStatut status,
|
||||
boolean estPaye,
|
||||
boolean estRembourse) {
|
||||
this.numeroTicket = numeroTicket;
|
||||
this.typePari = typePari;
|
||||
this.typeFormule = typeFormule;
|
||||
this.mise = mise;
|
||||
this.datePari = datePari;
|
||||
this.courseId = courseId;
|
||||
this.idParieur = idParieur;
|
||||
this.nomParieur = nomParieur;
|
||||
this.cheval = cheval;
|
||||
this.cheval1 = cheval1;
|
||||
this.cheval2 = cheval2;
|
||||
this.cheval3 = cheval3;
|
||||
this.premier = premier;
|
||||
this.deuxieme = deuxieme;
|
||||
this.troisieme = troisieme;
|
||||
this.chevauxOrdre = chevauxOrdre;
|
||||
this.chevauxSelectionnes = chevauxSelectionnes;
|
||||
this.ordrePredit = ordrePredit;
|
||||
this.validationOrdreExact = validationOrdreExact;
|
||||
this.typeMulti = typeMulti;
|
||||
this.status = status;
|
||||
this.estPaye = estPaye;
|
||||
this.estRembourse = estRembourse;
|
||||
}
|
||||
|
||||
public String getNumeroTicket() {
|
||||
return numeroTicket;
|
||||
}
|
||||
|
||||
public void setNumeroTicket(String numeroTicket) {
|
||||
this.numeroTicket = numeroTicket;
|
||||
}
|
||||
|
||||
public String getTypePari() {
|
||||
return typePari;
|
||||
}
|
||||
|
||||
public void setTypePari(String typePari) {
|
||||
this.typePari = typePari;
|
||||
}
|
||||
|
||||
public String getTypeFormule() {
|
||||
return typeFormule;
|
||||
}
|
||||
|
||||
public void setTypeFormule(String typeFormule) {
|
||||
this.typeFormule = typeFormule;
|
||||
}
|
||||
|
||||
public int getMise() {
|
||||
return mise;
|
||||
}
|
||||
|
||||
public void setMise(int mise) {
|
||||
this.mise = mise;
|
||||
}
|
||||
|
||||
public String getDatePari() {
|
||||
return datePari;
|
||||
}
|
||||
|
||||
public void setDatePari(String datePari) {
|
||||
this.datePari = datePari;
|
||||
}
|
||||
|
||||
public int getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setCourseId(int courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public String getIdParieur() {
|
||||
return idParieur;
|
||||
}
|
||||
|
||||
public void setIdParieur(String idParieur) {
|
||||
this.idParieur = idParieur;
|
||||
}
|
||||
|
||||
public String getNomParieur() {
|
||||
return nomParieur;
|
||||
}
|
||||
|
||||
public void setNomParieur(String nomParieur) {
|
||||
this.nomParieur = nomParieur;
|
||||
}
|
||||
|
||||
public int getCheval() {
|
||||
return cheval;
|
||||
}
|
||||
|
||||
public void setCheval(int cheval) {
|
||||
this.cheval = cheval;
|
||||
}
|
||||
|
||||
public int getCheval1() {
|
||||
return cheval1;
|
||||
}
|
||||
|
||||
public void setCheval1(int cheval1) {
|
||||
this.cheval1 = cheval1;
|
||||
}
|
||||
|
||||
public int getCheval2() {
|
||||
return cheval2;
|
||||
}
|
||||
|
||||
public void setCheval2(int cheval2) {
|
||||
this.cheval2 = cheval2;
|
||||
}
|
||||
|
||||
public int getCheval3() {
|
||||
return cheval3;
|
||||
}
|
||||
|
||||
public void setCheval3(int cheval3) {
|
||||
this.cheval3 = cheval3;
|
||||
}
|
||||
|
||||
public int getPremier() {
|
||||
return premier;
|
||||
}
|
||||
|
||||
public void setPremier(int premier) {
|
||||
this.premier = premier;
|
||||
}
|
||||
|
||||
public int getDeuxieme() {
|
||||
return deuxieme;
|
||||
}
|
||||
|
||||
public void setDeuxieme(int deuxieme) {
|
||||
this.deuxieme = deuxieme;
|
||||
}
|
||||
|
||||
public int getTroisieme() {
|
||||
return troisieme;
|
||||
}
|
||||
|
||||
public void setTroisieme(int troisieme) {
|
||||
this.troisieme = troisieme;
|
||||
}
|
||||
|
||||
public List<Integer> getChevauxOrdre() {
|
||||
return chevauxOrdre;
|
||||
}
|
||||
|
||||
public void setChevauxOrdre(List<Integer> chevauxOrdre) {
|
||||
this.chevauxOrdre = chevauxOrdre;
|
||||
}
|
||||
|
||||
public List<Integer> getChevauxSelectionnes() {
|
||||
return chevauxSelectionnes;
|
||||
}
|
||||
|
||||
public void setChevauxSelectionnes(List<Integer> chevauxSelectionnes) {
|
||||
this.chevauxSelectionnes = chevauxSelectionnes;
|
||||
}
|
||||
|
||||
public List<Integer> getOrdrePredit() {
|
||||
return ordrePredit;
|
||||
}
|
||||
|
||||
public void setOrdrePredit(List<Integer> ordrePredit) {
|
||||
this.ordrePredit = ordrePredit;
|
||||
}
|
||||
|
||||
public boolean isValidationOrdreExact() {
|
||||
return validationOrdreExact;
|
||||
}
|
||||
|
||||
public void setValidationOrdreExact(boolean validationOrdreExact) {
|
||||
this.validationOrdreExact = validationOrdreExact;
|
||||
}
|
||||
|
||||
public String getTypeMulti() {
|
||||
return typeMulti;
|
||||
}
|
||||
|
||||
public void setTypeMulti(String typeMulti) {
|
||||
this.typeMulti = typeMulti;
|
||||
}
|
||||
|
||||
public PariStatut getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(PariStatut status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public boolean isEstPaye() {
|
||||
return estPaye;
|
||||
}
|
||||
|
||||
public void setEstPaye(boolean estPaye) {
|
||||
this.estPaye = estPaye;
|
||||
}
|
||||
|
||||
public boolean isEstRembourse() {
|
||||
return estRembourse;
|
||||
}
|
||||
|
||||
public void setEstRembourse(boolean estRembourse) {
|
||||
this.estRembourse = estRembourse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.quiz.data.model.enums;
|
||||
|
||||
public enum PariStatut {
|
||||
EN_ATTENTE,
|
||||
PERDANT,
|
||||
VALIDEE
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.example.quiz.data.remote;
|
||||
|
||||
import com.example.quiz.data.model.Course;
|
||||
import com.example.quiz.data.model.Pari;
|
||||
import com.example.quiz.data.model.Reunion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface ApiService {
|
||||
@GET("reunions")
|
||||
@@ -14,4 +17,7 @@ public interface ApiService {
|
||||
|
||||
@GET("course/avenir")
|
||||
Call<List<Course>> getCourses();
|
||||
|
||||
@POST("/pari")
|
||||
Call<Pari> createPari(@Body Pari pari);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.example.quiz.data.repository;
|
||||
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.example.quiz.data.model.Pari;
|
||||
import com.example.quiz.data.remote.ApiService;
|
||||
import com.example.quiz.utils.Result;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class PariRepository {
|
||||
private ApiService apiService;
|
||||
|
||||
@Inject
|
||||
public PariRepository(ApiService apiService) {
|
||||
this.apiService = apiService;
|
||||
}
|
||||
|
||||
public LiveData<Result<Pari>> createPari(Pari pari) {
|
||||
MutableLiveData<Result<Pari>> pariResponse = new MutableLiveData<Result<Pari>>();
|
||||
pariResponse.setValue(Result.loading());
|
||||
apiService.createPari(pari).enqueue(new Callback<Pari>() {
|
||||
@Override
|
||||
public void onResponse(Call<Pari> call, Response<Pari> response) {
|
||||
if(response.isSuccessful()){
|
||||
pariResponse.postValue(Result.success(response.body()));
|
||||
}else {
|
||||
pariResponse.postValue(Result.error(response.message()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Pari> call, Throwable throwable) {
|
||||
pariResponse.postValue(Result.error(throwable.getMessage()));
|
||||
}
|
||||
});
|
||||
return pariResponse;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.example.quiz.viewModel;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.example.quiz.data.model.Pari;
|
||||
import com.example.quiz.data.repository.PariRepository;
|
||||
import com.example.quiz.utils.Result;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel;
|
||||
|
||||
@HiltViewModel
|
||||
public class PariViewModel extends ViewModel {
|
||||
private final PariRepository pariRepository;
|
||||
private LiveData<Result<Pari>> pari;
|
||||
|
||||
@Inject
|
||||
public PariViewModel(PariRepository repository){
|
||||
this.pariRepository = repository;
|
||||
}
|
||||
|
||||
public LiveData<Result<Pari>> createPari(Pari pari){
|
||||
if(this.pari == null){
|
||||
this.pari = pariRepository.createPari(pari);
|
||||
}
|
||||
return this.pari;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user