Skip to content
Snippets Groups Projects
Commit e653d3c9 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Projet terminé (il reste de nombreux bugs :eyes: )

parent 7509fc07
No related branches found
No related tags found
No related merge requests found
......@@ -2,13 +2,9 @@ package com.slprojects.pizzeria;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import java.util.ArrayList;
public class FragCustomPizza extends Fragment {
......@@ -17,7 +13,8 @@ public class FragCustomPizza extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_pizza_custom_vertical, container, false);
//((MainActivity)getActivity()).registerCustomPizzaBtn();
// Ici on appelle les arraylist de l'activité principale car on ne peut pas directement appeler de fonction suite à la déclaration du fragment
// Custom pizza fragment
((MainActivity)getActivity()).boutons.add(view.findViewById(R.id.mozzarella));
((MainActivity)getActivity()).boutons.add(view.findViewById(R.id.gorgonzola));
......
package com.slprojects.pizzeria;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
// On défini les variables
ArrayList<Button> boutons;
ArrayList<Integer> idIndexes;
private ArrayList<Integer> numCommands;
ArrayList<String> nomBoutons;
private int numTable;
private backTasks tacheDeFond;
private FragVerticalLayout frag;
private Bundle savedInstanceState;
private String actualFragment;
......@@ -33,6 +34,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
this.savedInstanceState = savedInstanceState;
setContentView(R.layout.activity_main);
// On créé le fragment
frag = new FragVerticalLayout();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.fragment_vertical_layout, frag);
......@@ -40,14 +42,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
actualFragment = "main";
Log.i("onCreate", "MainActivity");
Intent intent = getIntent();
Intent intent = getIntent(); // récupère l'intent qui a lancé l'activité
// On récupère le num de la table
numTable = intent.getIntExtra(NumTable.numTable, 1);
TextView textView = findViewById(R.id.textNumTable);
TextView textView = findViewById(R.id.textNumTable); // On récupère le TextView
String numTableText = textView.getText().toString() + numTable;
textView.setText(numTableText);
textView.setText(numTableText); // On lui donne le num de la table
Log.i("Numéro de la table", String.valueOf(numTable));
// Fin avec le num de la table
}
......@@ -55,12 +57,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
protected void onStart() {
super.onStart();
// On créé les ArrayList qui vont contenir les boutons
boutons = new ArrayList<>();
idIndexes = new ArrayList<>();
numCommands = new ArrayList<>();
nomBoutons = new ArrayList<>();
// Main fragment
// On récupère les boutons du fragment principal
boutons.add(frag.getView().findViewById(R.id.napolitaine));
boutons.add(frag.getView().findViewById(R.id.royale));
boutons.add(frag.getView().findViewById(R.id.quatreFromages));
......@@ -95,70 +98,77 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putIntegerArrayList("numCommands", numCommands);
outState.putIntegerArrayList("numCommands", numCommands); // On enregistre le num de commande
}
public void onClick(View v) {
try{
Log.i("Bouton clické", String.valueOf(v.getId()));
if(actualFragment == "main"){
if(v.getId() == R.id.pizzaperso){
// On vide la vue du fragment
//FrameLayout fl= findViewById(R.id.fragment_vertical_layout);
//fl.removeAllViews();
if(actualFragment == "main"){ // Si on est sur le fragment principal
if(v.getId() == R.id.pizzaperso){ // Si on clique sur le bouton pizza perso
// On va afficher le fragment de la piza perso
FragCustomPizza customPizzaFrag = new FragCustomPizza();
FragCustomPizza customPizzaFrag = new FragCustomPizza(); // On créé le fragment de la pizza perso
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_vertical_layout, customPizzaFrag);
transaction.replace(R.id.fragment_vertical_layout, customPizzaFrag); // On remplace le fragment principal par le fragment de la pizza perso
transaction.commit();
actualFragment = "customPizza";
} else {
Button bouton = boutons.get(idIndexes.indexOf(v.getId()));
numCommands.set(idIndexes.indexOf(v.getId()), numCommands.get(idIndexes.indexOf(v.getId()))+1);
setButtonText(bouton);
Button bouton = boutons.get(idIndexes.indexOf(v.getId())); // On récupère le bouton cliqué
numCommands.set(idIndexes.indexOf(v.getId()), numCommands.get(idIndexes.indexOf(v.getId()))+1); // On incrémente le num de commande
setButtonText(bouton); // On met à jour le nom du bouton
String message = numTable+nomBoutons.get(idIndexes.indexOf(v.getId()));
String message = numTable+nomBoutons.get(idIndexes.indexOf(v.getId())); // On créé le message à envoyer
// Envoie de la commande
tacheDeFond = new backTasks();
tacheDeFond.execute(message);
backTasks tacheDeFond = new backTasks(this);
tacheDeFond.executeOnExecutor(backTasks.THREAD_POOL_EXECUTOR, message); // On envoie le message
}
}else if(actualFragment == "customPizza"){
if(v.getId() == R.id.btnValiderPizzaCustom) {
}else if(actualFragment == "customPizza"){ // Si on est sur le fragment de la pizza perso
if(v.getId() == R.id.btnValiderPizzaCustom) { // Si on clique sur le bouton valider
// Envoie de la commande
tacheDeFond = new backTasks();
tacheDeFond.execute(compoPizzaPerso);
// On vide la vue du fragment
//FrameLayout fl= findViewById(R.id.fragment_vertical_layout);
//fl.removeAllViews();
backTasks tacheDeFond = new backTasks(this);
tacheDeFond.executeOnExecutor(backTasks.THREAD_POOL_EXECUTOR, compoPizzaPerso); // On envoie le message
// On affiche le fragment principal
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_vertical_layout, frag);
transaction.commit();
}else{
if(compoPizzaPerso != null){
compoPizzaPerso = compoPizzaPerso + " + " + nomBoutons.get(idIndexes.indexOf(v.getId()));
if(compoPizzaPerso != null){ // Si on a déjà composée une pizza
compoPizzaPerso = compoPizzaPerso + " + " + nomBoutons.get(idIndexes.indexOf(v.getId())); // On ajoute le nom du nouvel ingredient
}else{
compoPizzaPerso = String.valueOf(numTable);
compoPizzaPerso = compoPizzaPerso + nomBoutons.get(idIndexes.indexOf(v.getId()));
compoPizzaPerso = compoPizzaPerso + nomBoutons.get(idIndexes.indexOf(v.getId())); // On ajoute le nom du premier ingredient
}
}
}
}catch ( Exception e ){
Log.e("Erreur", e.getMessage());
}
}
public void setButtonText(Button bouton){
if(numCommands.get(idIndexes.indexOf(bouton.getId())) == 0){
// Ici on change le texte des boutons en fonction du nombre de commandes
if(numCommands.get(idIndexes.indexOf(bouton.getId())) == 0){ // Si on a jamais commndé cette pizza
bouton.setText(nomBoutons.get(idIndexes.indexOf(bouton.getId())));
}else{
}else{ // Si on a déjà commandé cette pizza
String titre = nomBoutons.get(idIndexes.indexOf(bouton.getId())) + " : " + numCommands.get(idIndexes.indexOf(bouton.getId()));
bouton.setText(titre);
}
}
public void createAlertMessage(String message, String title){
// Ici on créé un message d'alerte
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
// On ajoute le bouton de fermeture
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show(); // On affiche le message
}
}
\ No newline at end of file
......@@ -6,13 +6,17 @@ import android.util.Log;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
public class backTasks extends AsyncTask<String, Void, Void> {
private Socket socket;
private PrintWriter output;
private BufferedReader input;
private MainActivity activity;
public backTasks (MainActivity activity){
this.activity = activity;
}
@Override
protected Void doInBackground(String... message) {
......@@ -20,7 +24,6 @@ public class backTasks extends AsyncTask<String, Void, Void> {
String address = "chadok.info";
try {
//InetAddress ipAddress = InetAddress.getByName(address);
Log.i("backTasks:", "Connecting to " + address + ":"+ serverPort + "...");
socket = new Socket(address, serverPort);
Log.i("backTasks:", "Connected");
......@@ -30,15 +33,21 @@ public class backTasks extends AsyncTask<String, Void, Void> {
registerCommand(message[0]);
/*
while(true){
String message = input.readLine();
if (message != null){
Log.i("backTasks", "received message: " + message);
// Ici on va tout simplement lire les messages du serveur
// Et arrêter la boucle avec un flag
String receviedMsg = "";
Integer receivedFlag = 0;
while(receivedFlag < 2){
receviedMsg = input.readLine();
if (receviedMsg != null){ // Si le message n'est pas null
Log.i("backTasks", "received message: " + receviedMsg);
receivedFlag++; // On incrémente le flag
}
}
*/
String finalReceviedMsg = receviedMsg; // On stocke le message dans une variable final
activity.runOnUiThread(() -> { // On lance le code sur l'UI Thread
activity.createAlertMessage(finalReceviedMsg, "Message de la cuisine"); // On affiche le message reçu
});
} catch (Exception x) {
x.printStackTrace();
}
......
......@@ -11,4 +11,5 @@
<string name="pannacotta">Panna Cotta</string>
<string name="tiramisu">Tiramisu</string>
<string name="pizzaperso">Pizza Personnalisé</string>
<string name="ok">D\'accord</string>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">Lasri Del Arte</string>
<string name="choose">Choisir</string>
<string name="choose">Choose</string>
<string name="napolitaine">Napolitaine</string>
<string name="royale">Royale</string>
<string name="quatrefromages">Quatre Fromages</string>
<string name="montagnarde">Montagnarde</string>
<string name="royale">King\'s pizza</string>
<string name="quatrefromages">Four cheese</string>
<string name="montagnarde">Pizza moutain</string>
<string name="raclette">Raclette</string>
<string name="hawaii">Hawaii</string>
<string name="pannacotta">Panna Cotta</string>
<string name="tiramisu">Tiramisu</string>
<string name="pizzaperso">Pizza Personnalisé</string>
<string name="pizzaperso">Pimp My Pizza</string>
<string name="ok">It\'s ok</string>
</resources>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment