Skip to content
Snippets Groups Projects
Commit e42c5997 authored by MAUGEZ Emeline's avatar MAUGEZ Emeline
Browse files

Delete Ingredients

parent c5e6b71f
No related branches found
No related tags found
No related merge requests found
......@@ -79,6 +79,7 @@
</activity>
<activity android:name=".control.AdminAddCocktail" />
<activity android:name=".control.AdminDeleteCocktail" />
<activity android:name=".control.AdminDeleteIngredient" />
<activity
android:name=".control.AdminMajQuantityActivity"
......
......@@ -75,6 +75,7 @@ public class DeviceControl {
public BluetoothGattCharacteristic AjouterIngredientCharacteristic;
public BluetoothGattCharacteristic AddCocktailCharacteristic;
public BluetoothGattCharacteristic DeleteCocktailCharacteristic;
public BluetoothGattCharacteristic DeleteIngredientCharacteristic;
DeviceControl(Context c, String deviceName, String deviceAddress) {
......@@ -215,6 +216,17 @@ public class DeviceControl {
}
}
public void writeOnDeleteIngredient(String data){
if (DeleteIngredientCharacteristic!=null){
DeleteIngredientCharacteristic.setValue(data);
mBluetoothLeService.writeCharacteristic(DeleteIngredientCharacteristic);
}
else{
Log.d("Characteristic", "DeleteIngredientCharacteristic is nuuuuuuuuuuuuull");
onError();
}
}
public void writeOnMajIngredientsCharacteristic(String data){
if (MajIngredientsCharacteristic !=null){
MajIngredientsCharacteristic.setValue(data);
......@@ -340,7 +352,7 @@ public class DeviceControl {
CommanderCocktailCharacterisitic = gattCharacteristic;
Log.d("verif", "ouiiiiiiiiiiiiiii");
}
else if (uuid.equals(SampleGattAttributes.BD_RECETTES_CHARACTERISTIC)){
else if (uuid.equals(SampleGattAttributes.BD_RECETTES_CHARACTERISTIC) && BDRecettesCharacterisitic==null){
BDRecettesCharacterisitic = gattCharacteristic;
listenToBDRecettesCharacteristic();
}
......@@ -359,6 +371,9 @@ public class DeviceControl {
if(uuid.equals(SampleGattAttributes.DELETE_COCKTAIL_CHARACTERISTIC)){
DeleteCocktailCharacteristic = gattCharacteristic;
}
if(uuid.equals(SampleGattAttributes.DELETE_INGREDIENT_CHARACTERISTIC)){
DeleteIngredientCharacteristic = gattCharacteristic;
}
currentCharaData.put(
LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString));
currentCharaData.put(LIST_UUID, uuid);
......
......@@ -34,6 +34,7 @@ public class SampleGattAttributes {
public static String MAJ_INGREDIENT_CHARACTERISTIC ="6e4a0010-b5a3-f393-e0a9-e50e24dcca9e";
public static String ADD_COCKTAIL_CHARACTERISTIC = "6e4a0011-b5a3-f393-e0a9-e50e24dcca9e";
public static String DELETE_COCKTAIL_CHARACTERISTIC = "6e4a0013-b5a3-f393-e0a9-e50e24dcca9e";
public static String DELETE_INGREDIENT_CHARACTERISTIC = "6e4a0014-b5a3-f393-e0a9-e50e24dcca9e";
public static String COMMANDER_COCKTAIL_CHARACTERISTIC ="6e4a0012-b5a3-f393-e0a9-e50e24dcca9e";
......
......@@ -21,7 +21,8 @@ public class AdminActivity extends Activity {
Button mSupprimerCocktail;
Button mMajMachine;
Button mMajQuantite;
Button mMajListIngredients;
Button mAjouterIngredients;
Button mSupprimerIngredients;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -71,8 +72,8 @@ public class AdminActivity extends Activity {
});
// Démarre l'activité mettre à jour la liste des cocktails
mMajListIngredients = findViewById(R.id.admin_maj_ingrédients);
mMajListIngredients.setOnClickListener(new View.OnClickListener() {
mAjouterIngredients = findViewById(R.id.admin_ajouter_ingrédients);
mAjouterIngredients.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), AdminAddIngredientActivity.class);
......@@ -80,6 +81,16 @@ public class AdminActivity extends Activity {
}
});
// Démarre l'activité mettre à jour la liste des cocktails
mSupprimerIngredients = findViewById(R.id.admin_supprimer_ingrédients);
mSupprimerIngredients.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), AdminDeleteIngredient.class);
startActivity(i);
}
});
// Démarre l'activité mettre à jour la liste des quantités
mMajQuantite = findViewById(R.id.admin_maj_quantite);
mMajQuantite.setOnClickListener(new View.OnClickListener() {
......
package com.example.robotise.control;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import com.example.robotise.R;
import com.example.robotise.model.IngredientItem;
import com.example.robotise.model.Ingredients;
import java.util.ArrayList;
public class AdminDeleteIngredient extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admin_delete_ingredient);
ListView lv = findViewById(R.id.listViewDeleteIngredients);
ArrayAdapter<IngredientItem> ingredientAdapter =
new ArrayAdapter<IngredientItem>(AdminDeleteIngredient.this, android.R.layout.simple_list_item_multiple_choice, Ingredients.getInstance().ings);
lv.setAdapter(ingredientAdapter);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setItemsCanFocus(false);
Button deleteIngredient = findViewById(R.id.admin_supprimer_ingredient);
deleteIngredient.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ArrayList<IngredientItem> ingredientsChecked = new ArrayList<>();
SparseBooleanArray checked = lv.getCheckedItemPositions();
for (int i = 0; i < lv.getCount(); i++)
if (checked.get(i)) {
IngredientItem item = (IngredientItem) lv.getItemAtPosition(i);
ingredientsChecked.add(item);
/* do whatever you want with the checked item */
}
Ingredients.getInstance().deleteIngredient(ingredientsChecked);
}
});
}
}
......@@ -40,6 +40,11 @@ public class IngredientItem implements Serializable {
}
@Override
public String toString() {
return name;
}
/**
* Copy the ingredient with a quantity = 0
* @return
......
......@@ -57,7 +57,17 @@ public class Ingredients {
//Pour mettre à jour si elle existe déjà la page de la liste des ingrédients
Intent signalIntent = new Intent("Update Ingredients");
ctxt.sendBroadcast(signalIntent);
}
public void deleteIngredient(ArrayList<IngredientItem> toDelete){
String msg = "";
for (IngredientItem ingredientItem: toDelete){
msg+=ingredientItem.id+"/";
}
msg = msg.substring(0, msg.length() - 1);
Log.d("A supprimer", msg);
DeviceControl dc = DeviceControl.getInstance();
dc.writeOnDeleteIngredient(msg);
}
......
......@@ -87,11 +87,20 @@
<com.google.android.material.button.MaterialButton
android:theme = "@style/Widget.Material3.Button.ElevatedButton"
android:id="@+id/admin_maj_ingrédients"
android:id="@+id/admin_ajouter_ingrédients"
android:layout_width="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_height="wrap_content"
android:text="Mettre à jour la liste des ingrédients"
android:text="Ajouter ingrédients"
android:textAlignment="center" />
<com.google.android.material.button.MaterialButton
android:theme = "@style/Widget.Material3.Button.ElevatedButton"
android:id="@+id/admin_supprimer_ingrédients"
android:layout_width="match_parent"
android:layout_marginHorizontal="20dp"
android:layout_height="wrap_content"
android:text="Supprimer ingrédients"
android:textAlignment="center" />
<com.google.android.material.button.MaterialButton
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".control.LoginActivity"
android:theme="@style/Theme.Robotise">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/Theme.Robotise.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title="Robotise"
app:toolbarId="@+id/toolbar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/Theme.Robotise.PopupOverlay" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Supprimer ingrédient"
android:textSize="20dp"/>
<ListView
android:id="@+id/listViewDeleteIngredients"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:dividerHeight="0dp"
android:listSelector="@color/white"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/admin_supprimer_ingredient"
android:theme="@style/Widget.Material3.Button.ElevatedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Supprimer" />
</LinearLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ 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