70% of features done!
This commit is contained in:
@@ -14,6 +14,8 @@ import com.example.quiz.data.model.Course;
|
||||
import com.example.quiz.viewModel.SharedViewModel;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder> {
|
||||
@@ -51,7 +53,12 @@ public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder>
|
||||
public void onBindViewHolder(@NonNull BetViewHolder holder, int position) {
|
||||
Course bet = bets.get(position);
|
||||
|
||||
holder.tvDate.setText(String.valueOf(bet.getDateDepartCourse()));
|
||||
holder.tvDate.setText(LocalDateTime.parse(
|
||||
bet.getDateDepartCourse(),
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
|
||||
).format(
|
||||
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")
|
||||
));
|
||||
holder.tvName.setText(bet.getNom());
|
||||
|
||||
if (shared != null && shared.selectedReunion.getValue() != null) {
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.example.quiz.data.adapter;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.example.quiz.R;
|
||||
import com.example.quiz.data.model.Pari;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LastBetsAdapter extends RecyclerView.Adapter<LastBetsAdapter.LastBetsViewHolder> {
|
||||
|
||||
private List<Pari> listeParis = new ArrayList<>(); // évite les NPE
|
||||
private OnBetClick onBetClick; // peut être null si tu veux
|
||||
|
||||
public interface OnBetClick {
|
||||
void onItemClick(Pari pari);
|
||||
}
|
||||
|
||||
public LastBetsAdapter(List<Pari> listeParis, OnBetClick onBetClick) {
|
||||
if (listeParis != null) this.listeParis = listeParis;
|
||||
this.onBetClick = onBetClick;
|
||||
}
|
||||
|
||||
// Constructeur vide utile si tu veux créer puis setData ensuite
|
||||
public LastBetsAdapter(OnBetClick onBetClick) {
|
||||
this.onBetClick = onBetClick;
|
||||
}
|
||||
|
||||
public void setData(List<Pari> newList) {
|
||||
if (newList == null) {
|
||||
this.listeParis = new ArrayList<>();
|
||||
} else {
|
||||
this.listeParis = newList;
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addItem(Pari pari) {
|
||||
if (pari == null) return;
|
||||
this.listeParis.add(pari);
|
||||
notifyItemInserted(listeParis.size() - 1);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.listeParis.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public LastBetsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.last_bets_item, parent, false);
|
||||
return new LastBetsViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull LastBetsViewHolder holder, int position) {
|
||||
Pari pari = listeParis.get(position);
|
||||
if (pari == null) return;
|
||||
|
||||
holder.typeOfCourse.setText(pari.getCourse().getType());
|
||||
holder.refenceTicket.setText(pari.getNumeroTicket());
|
||||
|
||||
// Type (défensif : vérifie null)
|
||||
holder.betType.setText(pari.getTypePari() != null ? pari.getTypePari() : "-");
|
||||
|
||||
// Course (défensif : course peut être null)
|
||||
if (pari.getCourse() != null) {
|
||||
holder.course.setText("Course: " + pari.getCourse().getId());
|
||||
} else {
|
||||
holder.course.setText("Course: -");
|
||||
}
|
||||
|
||||
// Chevaux : join en toute sécurité (gère Integer list ou String list)
|
||||
List<?> chevaux = pari.getChevauxSelectionnes();
|
||||
if (chevaux != null && !chevaux.isEmpty()) {
|
||||
// convertir en strings
|
||||
List<String> str = new ArrayList<>(chevaux.size());
|
||||
for (Object o : chevaux) {
|
||||
str.add(String.valueOf(o));
|
||||
}
|
||||
// TextUtils.join est compatible avec tous les niveaux API
|
||||
holder.horses.setText("Chevaux : " + TextUtils.join("-", str));
|
||||
} else {
|
||||
holder.horses.setText("Chevaux : -");
|
||||
}
|
||||
|
||||
// Mise (défensif)
|
||||
holder.mise.setText("Mise: " + pari.getMise() + " CFA");
|
||||
|
||||
// click listener défensif
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (onBetClick != null) onBetClick.onItemClick(pari);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return (listeParis != null) ? listeParis.size() : 0;
|
||||
}
|
||||
|
||||
public static class LastBetsViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView betType, horses, course, mise, refenceTicket, typeOfCourse;
|
||||
|
||||
public LastBetsViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
betType = itemView.findViewById(R.id.last_bet_type);
|
||||
course = itemView.findViewById(R.id.last_bet_course);
|
||||
horses = itemView.findViewById(R.id.last_bet_horses);
|
||||
mise = itemView.findViewById(R.id.last_bet_mise);
|
||||
refenceTicket = itemView.findViewById(R.id.reference_ticket);
|
||||
typeOfCourse = itemView.findViewById(R.id.type_of_course);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import java.util.Map;
|
||||
public class Pari {
|
||||
private String numeroTicket;
|
||||
private String typePari;
|
||||
private String typeFormule;
|
||||
private double mise;
|
||||
private String datePari;
|
||||
private boolean estPaye;
|
||||
@@ -18,10 +17,11 @@ public class Pari {
|
||||
private boolean validationOrdreExact;
|
||||
private String typeMulti;
|
||||
|
||||
public Pari(String numeroTicket, String typePari, String typeFormule, double mise, String datePari, boolean estPaye, boolean estRembourse, PariCourseDto course, List<String> chevauxSelectionnes, List<String> ordrePredit, boolean validationOrdreExact, String typeMulti) {
|
||||
private String createdBy;
|
||||
|
||||
public Pari(String numeroTicket, String typePari, double mise, String datePari, boolean estPaye, boolean estRembourse, PariCourseDto course, List<String> chevauxSelectionnes, List<String> ordrePredit, boolean validationOrdreExact, String typeMulti, String createdBy) {
|
||||
this.numeroTicket = numeroTicket;
|
||||
this.typePari = typePari;
|
||||
this.typeFormule = typeFormule;
|
||||
this.mise = mise;
|
||||
this.datePari = datePari;
|
||||
this.estPaye = estPaye;
|
||||
@@ -31,6 +31,7 @@ public class Pari {
|
||||
this.ordrePredit = ordrePredit;
|
||||
this.validationOrdreExact = validationOrdreExact;
|
||||
this.typeMulti = typeMulti;
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
|
||||
public String getNumeroTicket() {
|
||||
@@ -49,14 +50,6 @@ public class Pari {
|
||||
this.typePari = typePari;
|
||||
}
|
||||
|
||||
public String getTypeFormule() {
|
||||
return typeFormule;
|
||||
}
|
||||
|
||||
public void setTypeFormule(String typeFormule) {
|
||||
this.typeFormule = typeFormule;
|
||||
}
|
||||
|
||||
public double getMise() {
|
||||
return mise;
|
||||
}
|
||||
@@ -128,4 +121,12 @@ public class Pari {
|
||||
public void setTypeMulti(String typeMulti) {
|
||||
this.typeMulti = typeMulti;
|
||||
}
|
||||
|
||||
public String getCreatedBy() {
|
||||
return createdBy;
|
||||
}
|
||||
|
||||
public void setCreatedBy(String createdBy) {
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,43 @@ package com.example.quiz.data.model.dtos;
|
||||
public class PariCourseDto {
|
||||
private int id;
|
||||
|
||||
private String nom;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private String type;
|
||||
|
||||
|
||||
|
||||
public PariCourseDto(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public PariCourseDto(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
|
||||
public PariCourseDto(int id, String nom, String type) {
|
||||
this.id = id;
|
||||
this.nom = nom;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
|
||||
@Module
|
||||
@InstallIn(SingletonComponent.class)
|
||||
public class ApiClient {
|
||||
private static final String BASE_URL = "https://970b6b1c025c.ngrok-free.app/api/v1/";
|
||||
private static final String BASE_URL = "https://boxer-adapting-bluegill.ngrok-free.app/api/v1/";
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
||||
@@ -12,7 +12,9 @@ import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface ApiService {
|
||||
@GET("reunions")
|
||||
@@ -26,4 +28,17 @@ public interface ApiService {
|
||||
|
||||
@POST("auth/agent/login")
|
||||
Call<LoginResponse> login(@Body LoginPayload loginPayload);
|
||||
|
||||
@GET("pari/created-by/{created-by}/today")
|
||||
Call<List<Pari>> derniersParis(@Path("created-by") String createdBy);
|
||||
|
||||
@PUT("pari/annuler/{numeroTicket}")
|
||||
Call<Pari> annulerPari(@Path("numeroTicket") String numeroTicket);
|
||||
|
||||
@GET("pari/solde/{createdBy}/course/{courseId}")
|
||||
Call<Double> getSoldeByCourse(@Path("createdBy") String createdBy, @Path("courseId") String courseId);
|
||||
|
||||
@GET("pari/solde/{createdBy}")
|
||||
Call<Double> getSoldeByDay(@Path("createdBy") String createdBy, @Query("date") String day);
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.example.quiz.data.model.Pari;
|
||||
import com.example.quiz.data.remote.ApiService;
|
||||
import com.example.quiz.utils.Result;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import retrofit2.Call;
|
||||
@@ -57,5 +59,111 @@ public class PariRepository {
|
||||
return pariResponse;
|
||||
}
|
||||
|
||||
public LiveData<Result<List<Pari>>> derniersParis(String createdBy){
|
||||
MutableLiveData<Result<List<Pari>>> derniersParis = new MutableLiveData<>();
|
||||
derniersParis.setValue(Result.loading());
|
||||
apiService.derniersParis(createdBy).enqueue(new Callback<List<Pari>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<Pari>> call, Response<List<Pari>> response) {
|
||||
if(response.isSuccessful() && response.body() != null){
|
||||
derniersParis.postValue(Result.success(response.body()));
|
||||
}else{
|
||||
try{
|
||||
String errorBody = response.errorBody() != null ?
|
||||
response.errorBody().string() : "Erreur inconnue";
|
||||
|
||||
derniersParis.postValue(Result.error(errorBody));
|
||||
}catch (Exception e){
|
||||
derniersParis.postValue(Result.error(e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<Pari>> call, Throwable throwable) {
|
||||
derniersParis.postValue(Result.error(throwable.getMessage()));
|
||||
}
|
||||
});
|
||||
|
||||
return derniersParis;
|
||||
}
|
||||
|
||||
public LiveData<Result<Pari>> annulerPari(String numeroTicket){
|
||||
MutableLiveData<Result<Pari>> pariResponse = new MutableLiveData<>();
|
||||
pariResponse.setValue(Result.loading());
|
||||
apiService.annulerPari(numeroTicket).enqueue(new Callback<Pari>(){
|
||||
@Override
|
||||
public void onResponse(Call<Pari> call, Response<Pari> response) {
|
||||
if(response.isSuccessful()){
|
||||
pariResponse.postValue(Result.success(response.body()));
|
||||
}else{
|
||||
try{
|
||||
String errorBody = response.errorBody() != null ?
|
||||
response.errorBody().string() : "Erreur inconnue";
|
||||
|
||||
pariResponse.postValue(Result.error(errorBody));
|
||||
}catch (Exception e){
|
||||
pariResponse.postValue(Result.error(e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Pari> call, Throwable throwable) {
|
||||
pariResponse.postValue(Result.error(throwable.getMessage()));
|
||||
}
|
||||
});
|
||||
return pariResponse;
|
||||
}
|
||||
|
||||
public LiveData<Result<Double>> getSoldeByCourse(String createdBy, String courseId){
|
||||
MutableLiveData<Result<Double>> solde = new MutableLiveData<>();
|
||||
solde.setValue(Result.loading());
|
||||
apiService.getSoldeByCourse(createdBy, courseId).enqueue(new Callback<Double>() {
|
||||
@Override
|
||||
public void onResponse(Call<Double> call, Response<Double> response) {
|
||||
if(response.isSuccessful()){
|
||||
solde.postValue(Result.success(response.body()));
|
||||
}else{
|
||||
try{
|
||||
solde.postValue(Result.error(response.errorBody().string()));
|
||||
}catch (Exception e){
|
||||
solde.postValue(Result.error(e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Double> call, Throwable throwable) {
|
||||
solde.postValue(Result.error(throwable.getMessage()));
|
||||
}
|
||||
});
|
||||
return solde;
|
||||
}
|
||||
|
||||
public LiveData<Result<Double>> getSoldeByDay(String createdBy, String day){
|
||||
MutableLiveData<Result<Double>> solde = new MutableLiveData<>();
|
||||
solde.setValue(Result.loading());
|
||||
apiService.getSoldeByDay(createdBy, day).enqueue(new Callback<Double>() {
|
||||
@Override
|
||||
public void onResponse(Call<Double> call, Response<Double> response) {
|
||||
if(response.isSuccessful()){
|
||||
solde.postValue(Result.success(response.body()));
|
||||
}else{
|
||||
try {
|
||||
solde.postValue(Result.error(response.errorBody().string()));
|
||||
}catch (Exception e){
|
||||
solde.postValue(Result.error(e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<Double> call, Throwable throwable) {
|
||||
solde.postValue(Result.error(throwable.getMessage()));
|
||||
}
|
||||
});
|
||||
return solde;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user