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

Supprimer cocktails + changements noms

parent 3d25618c
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,7 @@
</intent-filter>
</activity>
<activity android:name=".control.AdminAddCocktail" />
<activity android:name=".control.AdminDeleteCocktail" />
<activity
android:name=".control.AdminMajQuantityActivity"
......@@ -91,7 +92,7 @@
</activity>
<activity
android:name=".control.AdminMajListIngredientActivity"
android:name=".control.AdminAddIngredientActivity"
android:configChanges="orientation"
android:theme="@style/Theme.Robotise"
android:exported="true"
......
......@@ -36,8 +36,6 @@ import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import com.example.robotise.control.AdminActivity;
import com.example.robotise.control.AdminMajListIngredientActivity;
import com.example.robotise.model.Ingredients;
import com.example.robotise.model.Recettes;
......@@ -76,6 +74,7 @@ public class DeviceControl {
public BluetoothGattCharacteristic MajIngredientsCharacteristic;
public BluetoothGattCharacteristic AjouterIngredientCharacteristic;
public BluetoothGattCharacteristic AddCocktailCharacteristic;
public BluetoothGattCharacteristic DeleteCocktailCharacteristic;
DeviceControl(Context c, String deviceName, String deviceAddress) {
......@@ -205,6 +204,17 @@ public class DeviceControl {
}
}
public void writeOnDeleteCocktail(String data){
if (DeleteCocktailCharacteristic!=null){
DeleteCocktailCharacteristic.setValue(data);
mBluetoothLeService.writeCharacteristic(DeleteCocktailCharacteristic);
}
else{
Log.d("Characteristic", "DeleteCocktailCharacteristic is nuuuuuuuuuuuuull");
onError();
}
}
public void writeOnMajIngredientsCharacteristic(String data){
if (MajIngredientsCharacteristic !=null){
MajIngredientsCharacteristic.setValue(data);
......@@ -346,6 +356,9 @@ public class DeviceControl {
if(uuid.equals(SampleGattAttributes.ADD_COCKTAIL_CHARACTERISTIC)){
AddCocktailCharacteristic = gattCharacteristic;
}
if(uuid.equals(SampleGattAttributes.DELETE_COCKTAIL_CHARACTERISTIC)){
DeleteCocktailCharacteristic = gattCharacteristic;
}
currentCharaData.put(
LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString));
currentCharaData.put(LIST_UUID, uuid);
......
......@@ -10,7 +10,6 @@ import android.widget.Toast;
import com.example.robotise.R;
import com.example.robotise.ble.DeviceControl;
import com.example.robotise.model.Recettes;
/**
* Cette activité est utile pour l'administrateur
......@@ -52,9 +51,8 @@ public class AdminActivity extends Activity {
mSupprimerCocktail = findViewById(R.id.admin_supprimer_cocktail);
mSupprimerCocktail.setOnClickListener(new View.OnClickListener(){
public void onClick(View view) {
Toast.makeText(getApplicationContext(),"Supprimer Cocktail",Toast.LENGTH_LONG).show();
//DeviceControl dc = DeviceControl.getInstance();
//dc.listenToTXCharacteristic();
Intent i = new Intent(getApplicationContext(), AdminDeleteCocktail.class);
startActivity(i);
//TODO : receive the characteristic qui correspond
}
......@@ -77,7 +75,7 @@ public class AdminActivity extends Activity {
mMajListIngredients.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), AdminMajListIngredientActivity.class);
Intent i = new Intent(getApplicationContext(), AdminAddIngredientActivity.class);
startActivity(i);
}
});
......
......@@ -24,7 +24,7 @@ package com.example.robotise.control;
/**
* Cette activité permet d'avoir plus de détail sur un cocktail spécifique et communique avec le raspberry
*/
public class AdminMajListIngredientActivity extends Activity {
public class AdminAddIngredientActivity extends Activity {
private Button mValider;
private EditText mEditName;
private static ArrayList<IngredientItem> ing;
......@@ -40,13 +40,13 @@ public class AdminMajListIngredientActivity extends Activity {
dc.listenToBDIngredientsCharacteristic();
Log.d("Listen", "send");
setContentView(R.layout.admin_maj_list);
setContentView(R.layout.admin_add_ingredient);
//int ir = (int) b.get("ressource");
ing = Ingredients.getInstance().ings;
mListView =findViewById(R.id.majListViewIngredients);
fillListViewIngredients(AdminMajListIngredientActivity.this, mListView, ing);
fillListViewIngredients(AdminAddIngredientActivity.this, mListView, ing);
mEditName = findViewById(R.id.edit_text_ajout_liquide);
......@@ -88,7 +88,7 @@ public class AdminMajListIngredientActivity extends Activity {
public void receiveNewData(){
//Contient id_ingredient, id_bec, nom_ingrédient
fillListViewIngredients(AdminMajListIngredientActivity.this, mListView, Ingredients.getInstance().ings);
fillListViewIngredients(AdminAddIngredientActivity.this, mListView, Ingredients.getInstance().ings);
IngredientArrayAdapter adapter = (IngredientArrayAdapter)(mListView.getAdapter());
adapter.notifyDataSetChanged();
}
......
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.CocktailItem;
import com.example.robotise.model.Recettes;
import java.util.ArrayList;
public class AdminDeleteCocktail extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admin_delete_cocktail);
ListView lv = findViewById(R.id.supprimerCocktailListView);
ArrayAdapter<CocktailItem> ingredientAdapter =
new ArrayAdapter<CocktailItem>(AdminDeleteCocktail.this, android.R.layout.simple_list_item_multiple_choice, Recettes.getInstance().cocktailsItems);
lv.setAdapter(ingredientAdapter);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lv.setItemsCanFocus(false);
Button deleteCocktails = findViewById(R.id.delete_cocktail);
deleteCocktails.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ArrayList<CocktailItem> cocktailsChecked = new ArrayList<>();
SparseBooleanArray checked = lv.getCheckedItemPositions();
for (int i = 0; i < lv.getCount(); i++)
if (checked.get(i)) {
CocktailItem item = (CocktailItem) lv.getItemAtPosition(i);
cocktailsChecked.add(item);
/* do whatever you want with the checked item */
}
Recettes.getInstance().deleteCocktail(cocktailsChecked);
}
});
}
}
......@@ -4,6 +4,7 @@ package com.example.robotise.model;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.NonNull;
import java.util.ArrayList;
/**
......@@ -45,7 +46,11 @@ public class CocktailItem {
this.favorite = fav;
}
@NonNull
@Override
public String toString() {
return name;
}
}
......@@ -94,6 +94,18 @@ public class Recettes {
}
public void deleteCocktail(ArrayList<CocktailItem> cocktailsToDelete){
String msg = "";
for (CocktailItem cocktailItem: cocktailsToDelete){
msg+=cocktailItem.id+"/";
}
msg = msg.substring(0, msg.length() - 1);
Log.d("A supprimer", msg);
DeviceControl dc = DeviceControl.getInstance();
dc.writeOnDeleteCocktail(msg);
}
public void sendOrder(int id, ArrayList<IngredientItem> ings){
//id_recettes, id_ing, quantity
String msg = "";
......@@ -107,6 +119,7 @@ public class Recettes {
dc.writeOnCommanderCocktailCharacteristic(msg);
}
public static Recettes getInstance(){
if (instance==null)
new Recettes();
......
......@@ -52,7 +52,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Liste des ingrédients présents dans Robotise"
android:text="Ajout ingrédient"
android:textSize="20dp"/>
<ListView
......
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:layout_weight="1"
android:text="Supprimer un cocktail"
android:textSize="20dp"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/refresh_page_supprimer_cocktail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Refresh "
android:icon="@android:drawable/ic_menu_rotate"
android:layout_weight="0"
android:theme="@style/Widget.Material3.Button.ElevatedButton" />
</LinearLayout>
<ListView
android:id="@+id/supprimerCocktailListView"
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/delete_cocktail"
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 cocktails sélectionnés" />
</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