http request call done
This commit is contained in:
@@ -1,119 +0,0 @@
|
||||
package com.example.quiz.data;
|
||||
|
||||
import com.example.quiz.data.model.Bet;
|
||||
import com.example.quiz.data.model.Horse;
|
||||
import com.example.quiz.data.model.Reunion;
|
||||
import com.example.quiz.data.model.TypeOfBet;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BetsBank {
|
||||
public List<Bet> getBet() {
|
||||
return Arrays.asList(
|
||||
new Bet(
|
||||
1,
|
||||
"Course de chevaux",
|
||||
new Reunion(1,
|
||||
"Réunion ",
|
||||
LocalDate.of(2025,10,1),
|
||||
"Hippodrome Verssaille"
|
||||
),
|
||||
Arrays.asList(
|
||||
new TypeOfBet(1, "Couplet", "2"),
|
||||
new TypeOfBet(2, "Tierce", "3"),
|
||||
new TypeOfBet(3, "Place", "1")
|
||||
),
|
||||
LocalDate.of(2025,10,1),
|
||||
Arrays.asList(
|
||||
new Horse(1),
|
||||
new Horse(2),
|
||||
new Horse(3),
|
||||
new Horse(4)
|
||||
)
|
||||
),
|
||||
|
||||
new Bet(
|
||||
2,
|
||||
"Course de chevaux 2",
|
||||
new Reunion(2,
|
||||
"Réunion 2",
|
||||
LocalDate.of(2025,10,1),
|
||||
"Hippodrome Bordeaux"
|
||||
),
|
||||
Arrays.asList(
|
||||
new TypeOfBet(1, "Quarte", "4"),
|
||||
new TypeOfBet(2, "Quinte", "5"),
|
||||
new TypeOfBet(3, "Placé", "1")
|
||||
),
|
||||
LocalDate.of(2025,10,1),
|
||||
Arrays.asList(
|
||||
new Horse(4),
|
||||
new Horse(5),
|
||||
new Horse(7),
|
||||
new Horse(6),
|
||||
new Horse(8),
|
||||
new Horse(9),
|
||||
new Horse(10),
|
||||
new Horse(11)
|
||||
)
|
||||
),
|
||||
new Bet(
|
||||
3,
|
||||
"Course de chevaux 3",
|
||||
new Reunion(2,
|
||||
"Réunion 2",
|
||||
LocalDate.of(2025,10,1),
|
||||
"Hippodrome Bordeaux"
|
||||
),
|
||||
Arrays.asList(
|
||||
new TypeOfBet(1, "Quarte", "4"),
|
||||
new TypeOfBet(2, "Quinte", "5"),
|
||||
new TypeOfBet(3, "Placé", "1")
|
||||
),
|
||||
LocalDate.of(2025,10,1),
|
||||
Arrays.asList(
|
||||
new Horse(10),
|
||||
new Horse(90),
|
||||
new Horse(45),
|
||||
new Horse(9)
|
||||
)
|
||||
),
|
||||
new Bet(
|
||||
4,
|
||||
"Course de chevaux 4",
|
||||
new Reunion(2,
|
||||
"Réunion 2",
|
||||
LocalDate.of(2025,10,1),
|
||||
"Hippodrome Bordeaux"
|
||||
),
|
||||
Arrays.asList(
|
||||
new TypeOfBet(1, "Couple", "2"),
|
||||
new TypeOfBet(2, "Tierce", "3"),
|
||||
new TypeOfBet(3, "Quarte", "4")
|
||||
),
|
||||
LocalDate.of(2025,10,1),
|
||||
Arrays.asList(
|
||||
new Horse(5),
|
||||
new Horse(33),
|
||||
new Horse(26),
|
||||
new Horse(99),
|
||||
new Horse(100),
|
||||
new Horse(101),
|
||||
new Horse(102),
|
||||
new Horse(103),
|
||||
new Horse(104),
|
||||
new Horse(105)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
public static BetsBank instance;
|
||||
public static BetsBank getInstance(){
|
||||
if(instance == null){
|
||||
instance = new BetsBank();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.example.quiz.data;
|
||||
import com.example.quiz.data.model.Question;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class QuestionsBank {
|
||||
public List<Question> getQuestions() {
|
||||
return Arrays.asList(
|
||||
new Question(
|
||||
"Who is the creator of Android?",
|
||||
Arrays.asList(
|
||||
"Andy Rubin",
|
||||
"Steve Wozniak",
|
||||
"Jake Wharton",
|
||||
"Paul Smith"
|
||||
),
|
||||
0
|
||||
),
|
||||
new Question(
|
||||
"When did the first man land on the moon?",
|
||||
Arrays.asList(
|
||||
"1958",
|
||||
"1962",
|
||||
"1967",
|
||||
"1969"
|
||||
),
|
||||
3
|
||||
),
|
||||
new Question(
|
||||
"What is the house number of The Simpsons?",
|
||||
Arrays.asList(
|
||||
"42",
|
||||
"101",
|
||||
"666",
|
||||
"742"
|
||||
),
|
||||
3
|
||||
),
|
||||
new Question(
|
||||
"Who painteddid the Mona Lisa paint?",
|
||||
Arrays.asList(
|
||||
"Michelangelo",
|
||||
"Leonardo Da Vinci",
|
||||
"Raphael",
|
||||
"Caravaggio"
|
||||
),
|
||||
1
|
||||
),
|
||||
new Question(
|
||||
"What is the country top-level domain of Belgium?",
|
||||
Arrays.asList(
|
||||
".bg",
|
||||
".bm",
|
||||
".bl",
|
||||
".be"
|
||||
),
|
||||
3
|
||||
)
|
||||
);
|
||||
}
|
||||
private static QuestionsBank instance;
|
||||
public static QuestionsBank getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new QuestionsBank();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,19 @@ import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.example.quiz.R;
|
||||
import com.example.quiz.data.model.Bet;
|
||||
import com.example.quiz.data.model.Course;
|
||||
import com.example.quiz.viewModel.SharedViewModel;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder> {
|
||||
private List<Bet> bets = new ArrayList<>();
|
||||
private List<Course> bets = new ArrayList<>();
|
||||
private onItemClickListener listener;
|
||||
|
||||
|
||||
public interface onItemClickListener {
|
||||
void onItemClick(int position);
|
||||
void onItemClick(Course bet);
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(onItemClickListener listener){
|
||||
@@ -30,7 +31,7 @@ public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder>
|
||||
|
||||
|
||||
|
||||
public void setBets(List<Bet> bets){
|
||||
public void setBets(List<Course> bets){
|
||||
this.bets = bets;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
@@ -44,12 +45,13 @@ public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder>
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull BetViewHolder holder, int position) {
|
||||
Bet bet = bets.get(position);
|
||||
holder.tvDate.setText(String.valueOf(bet.getDate()));
|
||||
holder.tvName.setText(String.valueOf(bet.getName()));
|
||||
Course bet = bets.get(position);
|
||||
holder.tvDate.setText(String.valueOf(bet.getDateDepartCourse()));
|
||||
holder.tvName.setText(String.valueOf(bet.getLieu()));
|
||||
holder.tvReunion.setText("Nom de la réunion");
|
||||
holder.itemView.setOnClickListener(v->{
|
||||
if(listener != null){
|
||||
listener.onItemClick(bet.getId());
|
||||
listener.onItemClick(bet);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -63,11 +65,12 @@ public class BetsAdapter extends RecyclerView.Adapter<BetsAdapter.BetViewHolder>
|
||||
}
|
||||
|
||||
static class BetViewHolder extends RecyclerView.ViewHolder{
|
||||
TextView tvName, tvDate;
|
||||
TextView tvName, tvDate, tvReunion;
|
||||
public BetViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
tvName = itemView.findViewById(R.id.tvName);
|
||||
tvDate = itemView.findViewById(R.id.tvDate);
|
||||
tvReunion = itemView.findViewById(R.id.tvReunion);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.example.quiz.data.adapter;
|
||||
|
||||
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.Reunion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ReunionAdapter extends RecyclerView.Adapter<ReunionAdapter.ReunionViewHolder> {
|
||||
|
||||
private List<Reunion> reunions = List.of();
|
||||
|
||||
private onItemClickListener listener;
|
||||
|
||||
public interface onItemClickListener {
|
||||
void onItemClick(Reunion reunion);
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(onItemClickListener listener){
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setReunions(List<Reunion> reunions){
|
||||
this.reunions = reunions;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ReunionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.item_reunion, parent, false);
|
||||
return new ReunionViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReunionViewHolder holder, int position){
|
||||
Reunion reunion = reunions.get(position);
|
||||
|
||||
holder.reunionName.setText(String.valueOf(reunion.getNom()));
|
||||
holder.reunionDate.setText(String.valueOf(reunion.getDate()));
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if(listener != null){
|
||||
listener.onItemClick(reunion);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return reunions.size();
|
||||
}
|
||||
|
||||
static class ReunionViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView reunionName, reunionDate;
|
||||
|
||||
public ReunionViewHolder(View itemView){
|
||||
super(itemView);
|
||||
reunionName = itemView.findViewById(R.id.reunionName);
|
||||
reunionDate = itemView.findViewById(R.id.reunionDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,24 +14,24 @@ import com.example.quiz.data.model.TypeOfBet;
|
||||
import java.util.List;
|
||||
|
||||
public class TypeOfBetAdapter extends RecyclerView.Adapter<TypeOfBetAdapter.TypeOfBetViewHolder> {
|
||||
private List<TypeOfBet> types;
|
||||
private List<String> types;
|
||||
private onItemClickListener listener;
|
||||
|
||||
private int selectedPosition = -1;
|
||||
|
||||
public interface onItemClickListener{
|
||||
void onItemClick(TypeOfBet type);
|
||||
void onItemClick(String type);
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(TypeOfBetAdapter.onItemClickListener listener){
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public TypeOfBetAdapter(List<TypeOfBet> types){
|
||||
public TypeOfBetAdapter(List<String> types){
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public void setTypes(List<TypeOfBet> types){
|
||||
public void setTypes(List<String> types){
|
||||
this.types = types;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
@@ -46,8 +46,8 @@ public class TypeOfBetAdapter extends RecyclerView.Adapter<TypeOfBetAdapter.Type
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull TypeOfBetViewHolder holder, int position) {
|
||||
TypeOfBet type = types.get(position);
|
||||
holder.type_of_bet_name.setText(type.getName());
|
||||
String type = types.get(position);
|
||||
holder.type_of_bet_name.setText(type);
|
||||
if(selectedPosition != position){
|
||||
holder.itemView.setBackgroundResource(R.drawable.item_gradient_bg);
|
||||
}else{
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package com.example.quiz.data.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
public class Bet {
|
||||
private int id;
|
||||
private String name;
|
||||
private LocalDate date;
|
||||
|
||||
private Reunion reunion;
|
||||
|
||||
List<TypeOfBet> types;
|
||||
|
||||
private List<Horse> horses;
|
||||
|
||||
public Reunion getReunion() {
|
||||
return reunion;
|
||||
}
|
||||
|
||||
public void setReunion(Reunion reunion) {
|
||||
this.reunion = reunion;
|
||||
}
|
||||
|
||||
public List<TypeOfBet> getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setTypes(List<TypeOfBet> types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public List<Horse> getHorses() {
|
||||
return horses;
|
||||
}
|
||||
|
||||
public void setHorses(List<Horse> horses) {
|
||||
this.horses = horses;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
|
||||
public Bet(int id, String name, Reunion reunion, List<TypeOfBet> types, LocalDate date, List<Horse> horses) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.reunion = reunion;
|
||||
this.types = types;
|
||||
this.date = date;
|
||||
this.horses = horses;
|
||||
}
|
||||
}
|
||||
57
app/src/main/java/com/example/quiz/data/model/Cheval.java
Normal file
57
app/src/main/java/com/example/quiz/data/model/Cheval.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.example.quiz.data.model;
|
||||
|
||||
public class Cheval {
|
||||
private int number;
|
||||
private String nom;
|
||||
private String numero;
|
||||
private boolean nonPartant;
|
||||
private boolean nonEcurie;
|
||||
|
||||
public Cheval(int number, String nom, String numero, boolean nonPartant, boolean nonEcurie) {
|
||||
this.number = number;
|
||||
this.nom = nom;
|
||||
this.numero = numero;
|
||||
this.nonPartant = nonPartant;
|
||||
this.nonEcurie = nonEcurie;
|
||||
}
|
||||
|
||||
public int getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public String getNumero() {
|
||||
return numero;
|
||||
}
|
||||
|
||||
public void setNumero(String numero) {
|
||||
this.numero = numero;
|
||||
}
|
||||
|
||||
public boolean isNonPartant() {
|
||||
return nonPartant;
|
||||
}
|
||||
|
||||
public void setNonPartant(boolean nonPartant) {
|
||||
this.nonPartant = nonPartant;
|
||||
}
|
||||
|
||||
public boolean isNonEcurie() {
|
||||
return nonEcurie;
|
||||
}
|
||||
|
||||
public void setNonEcurie(boolean nonEcurie) {
|
||||
this.nonEcurie = nonEcurie;
|
||||
}
|
||||
}
|
||||
95
app/src/main/java/com/example/quiz/data/model/Course.java
Normal file
95
app/src/main/java/com/example/quiz/data/model/Course.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package com.example.quiz.data.model;
|
||||
|
||||
import com.example.quiz.data.model.enums.CourseType;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Course {
|
||||
private int id;
|
||||
private String numero;
|
||||
private String nom;
|
||||
private String lieu;
|
||||
private LocalDateTime dateDepartCourse;
|
||||
private String reunion;
|
||||
private int nombreChevauxInscrits;
|
||||
|
||||
private List<Cheval> chevaux;
|
||||
|
||||
public Course(int id, String numero, String nom, String lieu, LocalDateTime dateDepartCourse, String reunion, int nombreChevauxInscrits, List<Cheval> chevaux) {
|
||||
this.id = id;
|
||||
this.numero = numero;
|
||||
this.nom = nom;
|
||||
this.lieu = lieu;
|
||||
this.dateDepartCourse = dateDepartCourse;
|
||||
this.reunion = reunion;
|
||||
this.nombreChevauxInscrits = nombreChevauxInscrits;
|
||||
this.chevaux = chevaux;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNumero() {
|
||||
return numero;
|
||||
}
|
||||
|
||||
public void setNumero(String numero) {
|
||||
this.numero = numero;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public String getLieu() {
|
||||
return lieu;
|
||||
}
|
||||
|
||||
public void setLieu(String lieu) {
|
||||
this.lieu = lieu;
|
||||
}
|
||||
|
||||
public LocalDateTime getDateDepartCourse() {
|
||||
return dateDepartCourse;
|
||||
}
|
||||
|
||||
public void setDateDepartCourse(LocalDateTime dateDepartCourse) {
|
||||
this.dateDepartCourse = dateDepartCourse;
|
||||
}
|
||||
|
||||
public String getReunion() {
|
||||
return reunion;
|
||||
}
|
||||
|
||||
public void setReunion(String reunion) {
|
||||
this.reunion = reunion;
|
||||
}
|
||||
|
||||
public int getNombreChevauxInscrits() {
|
||||
return nombreChevauxInscrits;
|
||||
}
|
||||
|
||||
public void setNombreChevauxInscrits(int nombreChevauxInscrits) {
|
||||
this.nombreChevauxInscrits = nombreChevauxInscrits;
|
||||
}
|
||||
|
||||
public List<Cheval> getChevaux() {
|
||||
return chevaux;
|
||||
}
|
||||
|
||||
public void setChevaux(List<Cheval> chevaux) {
|
||||
this.chevaux = chevaux;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.example.quiz.data.model;
|
||||
|
||||
public class Hippodrome {
|
||||
private int id;
|
||||
private String nom;
|
||||
private String ville;
|
||||
private String pays;
|
||||
private int capacite;
|
||||
private String description;
|
||||
|
||||
public Hippodrome(int id, String nom, String ville, String pays, int capacite, String description) {
|
||||
this.id = id;
|
||||
this.nom = nom;
|
||||
this.ville = ville;
|
||||
this.pays = pays;
|
||||
this.capacite = capacite;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public String getVille() {
|
||||
return ville;
|
||||
}
|
||||
|
||||
public void setVille(String ville) {
|
||||
this.ville = ville;
|
||||
}
|
||||
|
||||
public String getPays() {
|
||||
return pays;
|
||||
}
|
||||
|
||||
public void setPays(String pays) {
|
||||
this.pays = pays;
|
||||
}
|
||||
|
||||
public int getCapacite() {
|
||||
return capacite;
|
||||
}
|
||||
|
||||
public void setCapacite(int capacite) {
|
||||
this.capacite = capacite;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.example.quiz.data.model;
|
||||
|
||||
public class Horse {
|
||||
private Integer number;
|
||||
|
||||
public Horse(Integer number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(Integer number) {
|
||||
this.number = number;
|
||||
}
|
||||
}
|
||||
@@ -4,22 +4,47 @@ import java.time.LocalDate;
|
||||
|
||||
public class Reunion {
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
private String nom;
|
||||
private LocalDate date;
|
||||
private String address;
|
||||
private int numero;
|
||||
private Hippodrome hippodrome;
|
||||
private int totalCourses;
|
||||
|
||||
public Reunion(int id, String name,LocalDate date, String address) {
|
||||
public Reunion(int id, String code, String nom, LocalDate date, int numero, Hippodrome hippodrome, int totalCourses) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.nom = nom;
|
||||
this.date = date;
|
||||
this.address = address;
|
||||
this.numero = numero;
|
||||
this.hippodrome = hippodrome;
|
||||
this.totalCourses = totalCourses;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
@@ -28,23 +53,27 @@ public class Reunion {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
public int getNumero() {
|
||||
return numero;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public void setNumero(int numero) {
|
||||
this.numero = numero;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public Hippodrome getHippodrome() {
|
||||
return hippodrome;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
public void setHippodrome(Hippodrome hippodrome) {
|
||||
this.hippodrome = hippodrome;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
public int getTotalCourses() {
|
||||
return totalCourses;
|
||||
}
|
||||
|
||||
public void setTotalCourses(int totalCourses) {
|
||||
this.totalCourses = totalCourses;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.quiz.data.model.enums;
|
||||
|
||||
public enum CourseType {
|
||||
TIERCE,
|
||||
QUARTE,
|
||||
QUINTE
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.example.quiz.data.remote;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.hilt.InstallIn;
|
||||
import dagger.hilt.components.SingletonComponent;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent.class)
|
||||
public class ApiClient {
|
||||
private static final String BASE_URL = "https://api.pmu.ml/api/v1/";
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public HttpLoggingInterceptor provideLoggingInterceptor(){
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
|
||||
@Override
|
||||
public void log(@NonNull String s) {
|
||||
Log.d("OkHttp", "log: "+s);
|
||||
}
|
||||
});
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
return loggingInterceptor;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public OkHttpClient provideOkHttpClient(HttpLoggingInterceptor loggingInterceptor){
|
||||
return new OkHttpClient.Builder()
|
||||
.addInterceptor(loggingInterceptor)
|
||||
.connectTimeout(240, TimeUnit.SECONDS)
|
||||
.readTimeout(240, TimeUnit.SECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public Retrofit provideRetrofit(OkHttpClient okHttpClient){
|
||||
return new Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.client(okHttpClient)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public ApiService provideApiService(Retrofit retrofit){
|
||||
return retrofit.create(ApiService.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.example.quiz.data.remote;
|
||||
|
||||
import com.example.quiz.data.model.Course;
|
||||
import com.example.quiz.data.model.Reunion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
|
||||
public interface ApiService {
|
||||
@GET("reunions")
|
||||
Call<List<Reunion>> getReunions();
|
||||
|
||||
@GET("course/avenir")
|
||||
Call<List<Course>> getCourses();
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.example.quiz.data.repository;
|
||||
|
||||
import com.example.quiz.data.BetsBank;
|
||||
import com.example.quiz.data.model.Bet;
|
||||
import com.example.quiz.data.model.Horse;
|
||||
import com.example.quiz.data.model.Reunion;
|
||||
import com.example.quiz.data.model.TypeOfBet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class BetRepository {
|
||||
private BetsBank betsBank;
|
||||
|
||||
@Inject
|
||||
public BetRepository(BetsBank betsBank){
|
||||
this.betsBank = betsBank;
|
||||
}
|
||||
|
||||
|
||||
public BetRepository(){
|
||||
this.betsBank = BetsBank.getInstance();
|
||||
}
|
||||
|
||||
public List<Bet> getAllBets(){
|
||||
return betsBank.getBet();
|
||||
}
|
||||
|
||||
public Bet getBetById(int id){
|
||||
return betsBank.getBet().get(id);
|
||||
}
|
||||
|
||||
public List<Horse> getHorsesById(int id){
|
||||
return getBetById(id).getHorses();
|
||||
}
|
||||
|
||||
public BetRepository getInstance(){
|
||||
return new BetRepository();
|
||||
}
|
||||
|
||||
public String getBetNameById(int id){
|
||||
return getBetById(id).getName();
|
||||
}
|
||||
|
||||
public List<TypeOfBet> getTypeOfBetByBetId(int id){
|
||||
return getBetById(id).getTypes();
|
||||
}
|
||||
|
||||
public Reunion getReunionByHorseId(int id){
|
||||
return getBetById(id).getReunion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.example.quiz.data.repository;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.example.quiz.data.model.Course;
|
||||
import com.example.quiz.data.remote.ApiService;
|
||||
import com.example.quiz.utils.Result;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class CourseRepository {
|
||||
private ApiService apiService;
|
||||
|
||||
@Inject
|
||||
public CourseRepository(ApiService apiService) {
|
||||
this.apiService = apiService;
|
||||
}
|
||||
|
||||
public LiveData<Result<List<Course>>> getCourses() {
|
||||
MutableLiveData<Result<List<Course>>> liveCourses = new MutableLiveData<Result<List<Course>>>();
|
||||
liveCourses.setValue(Result.loading());
|
||||
apiService.getCourses().enqueue(new Callback<List<Course>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<Course>> call, Response<List<Course>> response) {
|
||||
if(response.isSuccessful()){
|
||||
liveCourses.postValue(Result.success(response.body()));
|
||||
}else{
|
||||
liveCourses.postValue(Result.error(response.message()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<Course>> call, Throwable throwable) {
|
||||
liveCourses.postValue(Result.error(throwable.getMessage()));
|
||||
}
|
||||
});
|
||||
return liveCourses;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.example.quiz.data.repository;
|
||||
|
||||
import com.example.quiz.data.QuestionsBank;
|
||||
import com.example.quiz.data.model.Question;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class QuestionRepository {
|
||||
private QuestionsBank questionsBank;
|
||||
|
||||
public QuestionRepository(){
|
||||
this.questionsBank = QuestionsBank.getInstance();
|
||||
}
|
||||
|
||||
public List<Question> getQuestions(){
|
||||
return questionsBank.getQuestions();
|
||||
}
|
||||
|
||||
public Object updateQuestionById(int id, Question question){
|
||||
Question myQuestion = questionsBank.getQuestions().get(id);
|
||||
if(question == null) return Map.of("error", "Cette question n'existe pas!");
|
||||
myQuestion.setQuestion(question.getQuestion()!=null?question.getQuestion():myQuestion.getQuestion());
|
||||
myQuestion.setAnswers(!question.getAnswers().isEmpty()?question.getAnswers():myQuestion.getAnswers());
|
||||
myQuestion.setIndexAnswer(question.getIndexAnswer() > 3?question.getIndexAnswer():myQuestion.getIndexAnswer());
|
||||
return Map.of("success", true);
|
||||
}
|
||||
public QuestionRepository getInstance(){
|
||||
return new QuestionRepository();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.example.quiz.data.repository;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.example.quiz.data.model.Reunion;
|
||||
import com.example.quiz.data.remote.ApiClient;
|
||||
import com.example.quiz.data.remote.ApiService;
|
||||
import com.example.quiz.utils.Result;
|
||||
import com.google.android.gms.common.api.Api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class ReunionRepository {
|
||||
private ApiService apiService;
|
||||
|
||||
@Inject
|
||||
public ReunionRepository(ApiService apiService) {
|
||||
this.apiService = apiService;
|
||||
}
|
||||
|
||||
public LiveData<Result<List<Reunion>>> getReunions(){
|
||||
MutableLiveData<Result<List<Reunion>>> liveReunionsData = new MutableLiveData<>();
|
||||
liveReunionsData.setValue(Result.loading());
|
||||
apiService.getReunions().enqueue(new Callback<List<Reunion>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<Reunion>> call, Response<List<Reunion>> response) {
|
||||
if(response.isSuccessful()){
|
||||
liveReunionsData.postValue(Result.success(response.body()));
|
||||
}else{
|
||||
liveReunionsData.postValue(Result.error(response.message()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<Reunion>> call, Throwable throwable) {
|
||||
liveReunionsData.postValue(Result.error(throwable.getMessage()));
|
||||
}
|
||||
});
|
||||
return liveReunionsData;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.example.quiz.data.repository.module;
|
||||
|
||||
|
||||
import com.example.quiz.data.remote.ApiService;
|
||||
import com.example.quiz.data.repository.CourseRepository;
|
||||
import com.example.quiz.data.repository.ReunionRepository;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.hilt.InstallIn;
|
||||
import dagger.hilt.components.SingletonComponent;
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent.class)
|
||||
public class RepositoryModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
public ReunionRepository provideReunionRepository(ApiService apiService){
|
||||
return new ReunionRepository(apiService);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public CourseRepository provideCourseRepository(ApiService apiService){
|
||||
return new CourseRepository(apiService);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user