From 8744b99cb5b9cec35e0e3db03c80ea18a7e70e6b Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 1 Nov 2020 11:41:58 -0800 Subject: [PATCH 1/2] Delete list now works --- .../java/com/example/listify/ListPage.java | 11 ---- .../ShoppingListsSwipeableAdapter.java | 53 ++++++++++++++++++- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index 42c2c3d..3a74aa4 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -114,16 +114,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { public void onClick(DialogInterface dialog, int which) { EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail); String sharedEmail = sharedEmailText.getText().toString(); - //String[] sharedEmailList = sharedEmails.split(", "); - //for(String email : sharedEmailList) { - //Properties configs = new Properties(); - //try { - // configs = AuthManager.loadProperties(ListPage.this, "android.resource://" + getPackageName() + "/raw/auths.json"); - //} catch (IOException | JSONException e) { - // e.printStackTrace(); - //} - //Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); - //SynchronousReceiver ls = new SynchronousReceiver<>(); ListShare listShare = new ListShare(listID, sharedEmail); try { requestor.postObject(listShare); @@ -131,7 +121,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { catch(Exception e) { e.printStackTrace(); } - //} } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { diff --git a/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java b/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java index 763159b..08474ec 100644 --- a/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java +++ b/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java @@ -1,22 +1,34 @@ package com.example.listify.adapter; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; +import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.chauthai.swipereveallayout.SwipeRevealLayout; import com.chauthai.swipereveallayout.ViewBinderHelper; +import com.example.listify.AuthManager; import com.example.listify.ListPage; import com.example.listify.R; +import com.example.listify.Requestor; import com.example.listify.data.List; +import com.example.listify.data.ListShare; +import org.json.JSONException; + +import java.io.IOException; import java.util.ArrayList; +import java.util.Properties; + +import static com.example.listify.MainActivity.am; public class ShoppingListsSwipeableAdapter extends BaseAdapter { private Activity activity; @@ -77,7 +89,20 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { @Override public void onClick(View v) { // TODO: Add database call to delete the list on the server - + + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(activity, "android.resource://" + activity.getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); + try { + requestor.deleteObject(Integer.toString(curList.getItemID()), List.class); + } + catch(Exception e) { + e.printStackTrace(); + } Toast.makeText(activity, String.format("%s deleted", curList.getName()), Toast.LENGTH_SHORT).show(); lists.remove(position); @@ -92,6 +117,32 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { public void onClick(View v) { // TODO: Add database call to share list + /*View codeView = getLayoutInflater().inflate(R.layout.activity_sharedemail, null); + AlertDialog.Builder builder = new AlertDialog.Builder(ListPage.this); + builder.setView(codeView); + builder.setTitle("Share list"); + builder.setMessage("Please enter the email of the user who you want to share the list with."); + builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail); + String sharedEmail = sharedEmailText.getText().toString(); + ListShare listShare = new ListShare(listID, sharedEmail); + try { + requestor.postObject(listShare); + } + catch(Exception e) { + e.printStackTrace(); + } + } + }); + builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) {} + }); + AlertDialog dialog = builder.create(); + dialog.show();*/ + Toast.makeText(activity, String.format("Share %s", curList.getName()), Toast.LENGTH_SHORT).show(); // Close the layout From 62735aae0c7525e432fbd5c14300c1983a5722a5 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sun, 1 Nov 2020 16:12:28 -0800 Subject: [PATCH 2/2] Made sharing list an option after swiping --- .../java/com/example/listify/ListPage.java | 24 +++++++++--------- .../ShoppingListsSwipeableAdapter.java | 25 ++++++++++--------- .../app/src/main/res/layout/activity_list.xml | 19 +++++++------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index 3a74aa4..af88aa3 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -42,7 +42,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { Button decrQuan; Button removeItem; Button clearAll; - Button shareList; + //Button shareList; TextView tvTotalPrice; ProgressBar loadingListItems; @@ -70,6 +70,15 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { final int listID = (int) getIntent().getSerializableExtra("listID"); + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + requestor = new Requestor(am, configs.getProperty("apiKey")); + requestor.getObject(Integer.toString(listID), List.class, this); + listView = findViewById(R.id.listView); myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages); listView.setAdapter(myAdapter); @@ -100,7 +109,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } }); - shareList = (Button) findViewById(R.id.buttonShare); + /*shareList = (Button) findViewById(R.id.buttonShare); shareList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -130,16 +139,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { AlertDialog dialog = builder.create(); dialog.show(); } - }); - - Properties configs = new Properties(); - try { - configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); - } catch (IOException | JSONException e) { - e.printStackTrace(); - } - requestor = new Requestor(am, configs.getProperty("apiKey")); - requestor.getObject(Integer.toString(listID), List.class, this); + });*/ } @Override diff --git a/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java b/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java index 08474ec..5a7bd68 100644 --- a/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java +++ b/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java @@ -61,6 +61,14 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(activity, "android.resource://" + activity.getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); + if (inflater == null) { inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @@ -89,14 +97,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { @Override public void onClick(View v) { // TODO: Add database call to delete the list on the server - - Properties configs = new Properties(); - try { - configs = AuthManager.loadProperties(activity, "android.resource://" + activity.getPackageName() + "/raw/auths.json"); - } catch (IOException | JSONException e) { - e.printStackTrace(); - } - Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); + try { requestor.deleteObject(Integer.toString(curList.getItemID()), List.class); } @@ -117,8 +118,8 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { public void onClick(View v) { // TODO: Add database call to share list - /*View codeView = getLayoutInflater().inflate(R.layout.activity_sharedemail, null); - AlertDialog.Builder builder = new AlertDialog.Builder(ListPage.this); + View codeView = inflater.inflate(R.layout.activity_sharedemail, null); + AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setView(codeView); builder.setTitle("Share list"); builder.setMessage("Please enter the email of the user who you want to share the list with."); @@ -127,7 +128,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { public void onClick(DialogInterface dialog, int which) { EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail); String sharedEmail = sharedEmailText.getText().toString(); - ListShare listShare = new ListShare(listID, sharedEmail); + ListShare listShare = new ListShare(curList.getItemID(), sharedEmail); try { requestor.postObject(listShare); } @@ -141,7 +142,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { public void onClick(DialogInterface dialog, int which) {} }); AlertDialog dialog = builder.create(); - dialog.show();*/ + dialog.show(); Toast.makeText(activity, String.format("Share %s", curList.getName()), Toast.LENGTH_SHORT).show(); diff --git a/Listify/app/src/main/res/layout/activity_list.xml b/Listify/app/src/main/res/layout/activity_list.xml index 12e55da..3b3427a 100644 --- a/Listify/app/src/main/res/layout/activity_list.xml +++ b/Listify/app/src/main/res/layout/activity_list.xml @@ -16,33 +16,33 @@ +