From 19c925700a786ab54014200561b367a5be80e093 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Sat, 28 Nov 2020 18:11:01 -0800 Subject: [PATCH] Can now view the Sharee page --- Listify/app/src/main/AndroidManifest.xml | 1 + .../java/com/example/listify/ListSharees.java | 70 ++++++++++++------- .../adapter/ShareeSwipeableAdapter.java | 2 +- .../ShoppingListsSwipeableAdapter.java | 42 +++-------- .../res/layout/activity_listofsharees.xml | 32 ++++++--- .../res/layout/shopping_list_sharee_entry.xml | 29 ++++++++ .../shopping_lists_swipeable_name_item.xml | 4 +- 7 files changed, 110 insertions(+), 70 deletions(-) create mode 100644 Listify/app/src/main/res/layout/shopping_list_sharee_entry.xml diff --git a/Listify/app/src/main/AndroidManifest.xml b/Listify/app/src/main/AndroidManifest.xml index 7389dd5..5b77371 100644 --- a/Listify/app/src/main/AndroidManifest.xml +++ b/Listify/app/src/main/AndroidManifest.xml @@ -40,6 +40,7 @@ + \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/ListSharees.java b/Listify/app/src/main/java/com/example/listify/ListSharees.java index c7527a8..1747415 100644 --- a/Listify/app/src/main/java/com/example/listify/ListSharees.java +++ b/Listify/app/src/main/java/com/example/listify/ListSharees.java @@ -41,14 +41,12 @@ import androidx.appcompat.app.AppCompatActivity; import static com.example.listify.MainActivity.am; public class ListSharees extends AppCompatActivity implements Requestor.Receiver { - ShareeSwipeableAdapter myAdapter; + ListView listView; + MyAdapter myAdapter; Requestor requestor; - ProgressBar loadingListItems; + ArrayList lShareeEmails = new ArrayList<>(); - DecimalFormat df = new DecimalFormat("0.00"); - - // TODO: Display a message if their list is empty @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -65,8 +63,9 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver requestor = new Requestor(am, configs.getProperty("apiKey")); requestor.getObject(Integer.toString(listID), ListShare.class, this); - loadingListItems = findViewById(R.id.progress_loading_list_items); - loadingListItems.setVisibility(View.VISIBLE); + listView = findViewById(R.id.listOfSharees); + myAdapter = new MyAdapter(this, lShareeEmails); + listView.setAdapter(myAdapter); } @Override @@ -74,29 +73,46 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver ListShare sharee = (ListShare) delivered; if(sharee != null) { - SynchronousReceiver listShareReceiver = new SynchronousReceiver<>(); - requestor.getObject(Integer.toString(sharee.getListID()), ListShare.class, listShareReceiver, listShareReceiver); + lShareeEmails.add("sharee.getShareWithEmail()"); - ArrayList resultList = new ArrayList<>(); - ListShare result; - - try { - result = listShareReceiver.await(); - } - catch (Exception e) { - e.printStackTrace(); - result = null; - } - - if(result != null) { - resultList.add(result); - - for(ListShare r : result.getEntries()) { - resultList.add(r); + if(sharee.getEntries() != null) { + for(ListShare ls : sharee.getEntries()) { + lShareeEmails.add(ls.getShareWithEmail()); } - - myAdapter = new ShareeSwipeableAdapter(this, resultList); } + + runOnUiThread(new Runnable() { + @Override + public void run() { + myAdapter.notifyDataSetChanged(); + } + }); + } + } + + class MyAdapter extends ArrayAdapter { + Context context; + ArrayList lShareeEmails; + + MyAdapter (Context c, ArrayList shareeEmails) { + super(c, R.layout.shopping_list_sharee_entry, R.id.textView14, shareeEmails); + context = c; + lShareeEmails = shareeEmails; + } + + @NonNull + @Override + public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { + LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View listproduct = layoutInflater.inflate(R.layout.shopping_list_sharee_entry, parent,false); + + TextView shareeEmail = listproduct.findViewById(R.id.textView14); + + if(!lShareeEmails.isEmpty()) { + shareeEmail.setText(lShareeEmails.get(position)); + } + + return listproduct; } } } 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 dd0a2d9..ac8ee0e 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); 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 1b12834..9716ec1 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 @@ -17,6 +17,7 @@ import com.chauthai.swipereveallayout.SwipeRevealLayout; import com.chauthai.swipereveallayout.ViewBinderHelper; import com.example.listify.AuthManager; import com.example.listify.ListPage; +import com.example.listify.ListSharees; import com.example.listify.R; import com.example.listify.Requestor; import com.example.listify.data.List; @@ -79,7 +80,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); @@ -120,41 +121,18 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { } }); - /*holder.shareList.setOnClickListener(new View.OnClickListener() { + 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(); + Intent listSharees = new Intent(activity, ListSharees.class); - Toast.makeText(activity, String.format("Share %s", curList.getName()), Toast.LENGTH_SHORT).show(); + // Send the list ID and list name + listSharees.putExtra("listID", curList.getListID()); + //listPage.putExtra("listName", curList.getName()); - // Close the layout - binderHelper.closeLayout(Integer.toString(curList.getListID())); + activity.startActivity(listSharees); } - });*/ + }); holder.frontView.setOnClickListener(new View.OnClickListener() { @Override @@ -176,7 +154,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/activity_listofsharees.xml b/Listify/app/src/main/res/layout/activity_listofsharees.xml index 58747d3..add74b0 100644 --- a/Listify/app/src/main/res/layout/activity_listofsharees.xml +++ b/Listify/app/src/main/res/layout/activity_listofsharees.xml @@ -3,20 +3,36 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:text="Enter the email of the user you want to share the list with." + android:layout_marginTop="10dp" + android:layout_marginLeft="13dp"/> + + + +