From 0550ae4faf0ad07b7169a4223e325fb5a4cea399 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 27 Nov 2020 15:08:21 -0500 Subject: [PATCH 1/3] duplicate lists functionality --- .../java/com/example/listify/ListPage.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 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 783924d..b695e23 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -59,14 +59,16 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { Map storeHeaderIndex = new HashMap<>(); DecimalFormat df = new DecimalFormat("0.00"); + int LIST_ID; + String LIST_NAME; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); - final int LIST_ID = (int) getIntent().getSerializableExtra("listID"); - final String LIST_NAME = (String) getIntent().getSerializableExtra("listName"); + LIST_ID = (int) getIntent().getSerializableExtra("listID"); + LIST_NAME = (String) getIntent().getSerializableExtra("listName"); setTitle(LIST_NAME); Properties configs = new Properties(); @@ -193,7 +195,24 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { duplicateItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - Toast.makeText(ListPage.this, "Duplicate List", Toast.LENGTH_SHORT).show(); + + ListDuplicate duplicate = new ListDuplicate(LIST_ID, String.format("%s copy", LIST_NAME)); + + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(ListPage.this, "android.resource://" + getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + requestor = new Requestor(am, configs.getProperty("apiKey")); + try { + requestor.postObject(duplicate); + } catch (JSONException e) { + e.printStackTrace(); + } + + Toast.makeText(ListPage.this, "List duplicated", Toast.LENGTH_SHORT).show(); return false; } }); From c0a93e3684cbba0ff737819b66436cf3efdf3a9c Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 27 Nov 2020 18:13:37 -0500 Subject: [PATCH 2/3] Rename list functionality --- .../java/com/example/listify/ListPage.java | 55 ++++++++++---- .../listify/RenameListDialogFragment.java | 71 +++++++++++++++++++ .../ShoppingListsSwipeableAdapter.java | 11 +-- .../java/com/example/listify/data/List.java | 3 +- .../com/example/listify/data/ListEntry.java | 4 +- .../main/res/layout/dialog_rename_list.xml | 22 ++++++ 6 files changed, 146 insertions(+), 20 deletions(-) create mode 100644 Listify/app/src/main/java/com/example/listify/RenameListDialogFragment.java create mode 100644 Listify/app/src/main/res/layout/dialog_rename_list.xml 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 b695e23..86bbdee 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -1,15 +1,16 @@ package com.example.listify; -import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; +import android.text.Editable; import android.util.Log; import android.view.*; import android.widget.*; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; @@ -27,7 +28,7 @@ import java.util.Properties; import static com.example.listify.MainActivity.am; -public class ListPage extends AppCompatActivity implements Requestor.Receiver { +public class ListPage extends AppCompatActivity implements Requestor.Receiver, RenameListDialogFragment.OnRenameListListener { ListView listView; MyAdapter myAdapter; Requestor requestor; @@ -59,17 +60,15 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { Map storeHeaderIndex = new HashMap<>(); DecimalFormat df = new DecimalFormat("0.00"); - int LIST_ID; - String LIST_NAME; + List selectedList; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); - LIST_ID = (int) getIntent().getSerializableExtra("listID"); - LIST_NAME = (String) getIntent().getSerializableExtra("listName"); - setTitle(LIST_NAME); + selectedList = (List) getIntent().getSerializableExtra("selectedList"); + setTitle(selectedList.getName()); Properties configs = new Properties(); try { @@ -78,7 +77,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { e.printStackTrace(); } requestor = new Requestor(am, configs.getProperty("apiKey")); - requestor.getObject(Integer.toString(LIST_ID), List.class, this); + requestor.getObject(Integer.toString(selectedList.getListID()), List.class, this); listView = findViewById(R.id.listView); myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages); @@ -160,7 +159,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } requestor = new Requestor(am, configs.getProperty("apiKey")); - requestor.getObject(Integer.toString(LIST_ID), List.class, ListPage.this); + requestor.getObject(Integer.toString(selectedList.getListID()), List.class, ListPage.this); } }); } @@ -168,16 +167,16 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { @Override public boolean onCreateOptionsMenu(Menu menu) { //Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.list, menu); - - //return super.onCreateOptionsMenu(menu); + + MenuItem renameItem = menu.findItem(R.id.action_rename_list); renameItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { - Toast.makeText(ListPage.this, "Rename List", Toast.LENGTH_SHORT).show(); + RenameListDialogFragment renameListDialog = new RenameListDialogFragment(); + renameListDialog.show(getSupportFragmentManager(), "Rename List"); return false; } }); @@ -196,7 +195,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { @Override public boolean onMenuItemClick(MenuItem item) { - ListDuplicate duplicate = new ListDuplicate(LIST_ID, String.format("%s copy", LIST_NAME)); + ListDuplicate duplicate = new ListDuplicate(selectedList.getListID(), String.format("%s copy", selectedList.getName())); Properties configs = new Properties(); try { @@ -348,6 +347,34 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { refreshList.setRefreshing(false); } + @Override + public void sendRenameListName(String name) { + selectedList.setName(name); + + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(ListPage.this, "android.resource://" + getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + requestor = new Requestor(am, configs.getProperty("apiKey")); + try { + requestor.putObject(selectedList); + } catch (Exception e) { + e.printStackTrace(); + } + + + runOnUiThread(new Runnable() { + @Override + public void run() { + setTitle(name); + Toast.makeText(ListPage.this, "List Renamed", Toast.LENGTH_SHORT).show(); + } + }); + } + class MyAdapter extends ArrayAdapter { Context context; ArrayList pNames; diff --git a/Listify/app/src/main/java/com/example/listify/RenameListDialogFragment.java b/Listify/app/src/main/java/com/example/listify/RenameListDialogFragment.java new file mode 100644 index 0000000..1b82b6d --- /dev/null +++ b/Listify/app/src/main/java/com/example/listify/RenameListDialogFragment.java @@ -0,0 +1,71 @@ +package com.example.listify; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; + + +public class RenameListDialogFragment extends DialogFragment { + + public interface OnRenameListListener { + void sendRenameListName(String name); + } + + public OnRenameListListener onRenameListListener; + + EditText etRenameListName; + + public RenameListDialogFragment() {} + + + @Override + public Dialog onCreateDialog(final Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + + // Get the layout inflater + LayoutInflater inflater = requireActivity().getLayoutInflater(); + + // Inflate and set the layout for the dialog + // Pass null as the parent view because its going in the dialog layout + View root = inflater.inflate(R.layout.dialog_rename_list, null); + builder.setView(root) + // Add action buttons + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + onRenameListListener.sendRenameListName(etRenameListName.getText().toString()); + } + }) + .setNegativeButton("cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + RenameListDialogFragment.this.getDialog().cancel(); + } + }); + + etRenameListName = (EditText) root.findViewById(R.id.et_renamed_list_name); + + return builder.create(); + } + + // Required to extend DialogFragment + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + try { + onRenameListListener = (OnRenameListListener) getTargetFragment(); + if (onRenameListListener == null) { + onRenameListListener = (OnRenameListListener) getActivity(); + } + } catch (ClassCastException e) { + Log.e("CreateListDialogFragment", "onAttach: ClassCastException: " + e.getMessage()); + } + } +} 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 fbdf493..dc2bd72 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 @@ -100,7 +100,11 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { holder.listName.setText(curList.getName()); } - holder.itemCount.setText(String.format("%d items", curList.getEntries().length)); + if (curList.getEntries() != null) { + holder.itemCount.setText(String.format("%d items", curList.getEntries().length)); + } else { + holder.itemCount.setText("0 items"); + } holder.deleteList.setOnClickListener(new View.OnClickListener() { @Override @@ -161,9 +165,8 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { public void onClick(View v) { Intent listPage = new Intent(activity, ListPage.class); - // Send the list ID and list name - listPage.putExtra("listID", curList.getListID()); - listPage.putExtra("listName", curList.getName()); + // Send the selected list + listPage.putExtra("selectedList", curList); activity.startActivity(listPage); } diff --git a/Listify/app/src/main/java/com/example/listify/data/List.java b/Listify/app/src/main/java/com/example/listify/data/List.java index 47f3971..79fc8d1 100644 --- a/Listify/app/src/main/java/com/example/listify/data/List.java +++ b/Listify/app/src/main/java/com/example/listify/data/List.java @@ -1,8 +1,9 @@ package com.example.listify.data; +import java.io.Serializable; import java.util.Arrays; -public class List { +public class List implements Serializable { Integer listID; String name; String owner; diff --git a/Listify/app/src/main/java/com/example/listify/data/ListEntry.java b/Listify/app/src/main/java/com/example/listify/data/ListEntry.java index e482079..66720e8 100644 --- a/Listify/app/src/main/java/com/example/listify/data/ListEntry.java +++ b/Listify/app/src/main/java/com/example/listify/data/ListEntry.java @@ -1,6 +1,8 @@ package com.example.listify.data; -public class ListEntry { +import java.io.Serializable; + +public class ListEntry implements Serializable { Integer listID; Integer productID; Integer quantity; diff --git a/Listify/app/src/main/res/layout/dialog_rename_list.xml b/Listify/app/src/main/res/layout/dialog_rename_list.xml new file mode 100644 index 0000000..55ca2e1 --- /dev/null +++ b/Listify/app/src/main/res/layout/dialog_rename_list.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file From cf4791badc1352142cedf4697dbc8ff26e05d594 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 27 Nov 2020 18:21:26 -0500 Subject: [PATCH 3/3] Removed share button from sliding lists --- .../adapter/ShareeSwipeableAdapter.java | 14 ++-- .../ShoppingListsSwipeableAdapter.java | 74 +++++++++---------- .../shopping_lists_swipeable_name_item.xml | 12 +-- 3 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/adapter/ShareeSwipeableAdapter.java b/Listify/app/src/main/java/com/example/listify/adapter/ShareeSwipeableAdapter.java index ac8ee0e..0c5327b 100644 --- a/Listify/app/src/main/java/com/example/listify/adapter/ShareeSwipeableAdapter.java +++ b/Listify/app/src/main/java/com/example/listify/adapter/ShareeSwipeableAdapter.java @@ -79,7 +79,7 @@ public class ShareeSwipeableAdapter extends BaseAdapter { holder.swipeLayout = (SwipeRevealLayout)convertView.findViewById(R.id.swipe_layout); holder.frontView = convertView.findViewById(R.id.front_layout); holder.deleteList = convertView.findViewById(R.id.delete_list); - holder.shareList = convertView.findViewById(R.id.share_list); +// holder.shareList = convertView.findViewById(R.id.share_list); holder.textView = (TextView) convertView.findViewById(R.id.shopping_list_name); convertView.setTag(holder); @@ -101,12 +101,12 @@ public class ShareeSwipeableAdapter extends BaseAdapter { } }); - holder.shareList.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - } - }); +// holder.shareList.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// +// } +// }); holder.frontView.setOnClickListener(new View.OnClickListener() { @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 dc2bd72..3f5d7a7 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 @@ -79,7 +79,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { holder.swipeLayout = (SwipeRevealLayout)convertView.findViewById(R.id.swipe_layout); holder.frontView = convertView.findViewById(R.id.front_layout); holder.deleteList = convertView.findViewById(R.id.delete_list); - holder.shareList = convertView.findViewById(R.id.share_list); +// holder.shareList = convertView.findViewById(R.id.share_list); holder.listName = (TextView) convertView.findViewById(R.id.shopping_list_name); holder.itemCount = (TextView) convertView.findViewById(R.id.shopping_list_item_count); @@ -124,41 +124,41 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { } }); - holder.shareList.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - 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."); - 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(curList.getListID(), sharedEmail, "Read, Write, Delete, Share", null); - try { - requestor.putObject(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 - binderHelper.closeLayout(Integer.toString(curList.getListID())); - } - }); +// holder.shareList.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// 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."); +// 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(curList.getListID(), sharedEmail, "Read, Write, Delete, Share", null); +// try { +// requestor.putObject(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 +// binderHelper.closeLayout(Integer.toString(curList.getListID())); +// } +// }); holder.frontView.setOnClickListener(new View.OnClickListener() { @Override @@ -179,7 +179,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { SwipeRevealLayout swipeLayout; View frontView; View deleteList; - View shareList; +// View shareList; TextView listName; TextView itemCount; } diff --git a/Listify/app/src/main/res/layout/shopping_lists_swipeable_name_item.xml b/Listify/app/src/main/res/layout/shopping_lists_swipeable_name_item.xml index 9ecf6db..df2c9e7 100644 --- a/Listify/app/src/main/res/layout/shopping_lists_swipeable_name_item.xml +++ b/Listify/app/src/main/res/layout/shopping_lists_swipeable_name_item.xml @@ -17,12 +17,12 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"> - + + + + + +