From 9570e1e180cf58396fd90a9a8acd4a42b9649a82 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Mon, 30 Nov 2020 13:53:02 -0800 Subject: [PATCH] Displays email of sharer next to shared list --- .../java/com/example/listify/ListSharees.java | 8 +- .../adapter/ShareeSwipeableAdapter.java | 128 ------------------ .../listify/adapter/ShoppingListsAdapter.java | 55 +++++++- .../ShoppingListsSwipeableAdapter.java | 38 ++++-- 4 files changed, 75 insertions(+), 154 deletions(-) delete mode 100644 Listify/app/src/main/java/com/example/listify/adapter/ShareeSwipeableAdapter.java 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 0393b0d..e0cce7f 100644 --- a/Listify/app/src/main/java/com/example/listify/ListSharees.java +++ b/Listify/app/src/main/java/com/example/listify/ListSharees.java @@ -72,7 +72,7 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver ListShare sharee = (ListShare) delivered; if(sharee != null) { - lShareeEmails.add(sharee.getShareWithEmail()); + //lShareeEmails.add(sharee.getShareWithEmail()); if(sharee.getEntries() != null) { for(ListShare ls : sharee.getEntries()) { @@ -128,12 +128,6 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver } }); - //No need to show owner - if(position == 0) { - shareeEmail.setVisibility(View.GONE); - removeSharee.setVisibility(View.GONE); - } - 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 deleted file mode 100644 index 0c5327b..0000000 --- a/Listify/app/src/main/java/com/example/listify/adapter/ShareeSwipeableAdapter.java +++ /dev/null @@ -1,128 +0,0 @@ -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 ShareeSwipeableAdapter extends BaseAdapter { - private Activity activity; - private ArrayList sharees; - private LayoutInflater inflater; - private final ViewBinderHelper binderHelper; - - public ShareeSwipeableAdapter(Activity activity, ArrayList sharees){ - binderHelper = new ViewBinderHelper(); - this.activity = activity; - this.sharees = sharees; - } - - @Override - public int getCount() { - return sharees.size(); - } - - @Override - public Object getItem(int position) { - return sharees.get(position); - } - - @Override - public long getItemId(int position) { - return position; - } - - @Override - 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); - } - if (convertView == null) { - convertView = inflater.inflate(R.layout.shopping_lists_swipeable_name_item, null); - - holder = new ViewHolder(); - 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.textView = (TextView) convertView.findViewById(R.id.shopping_list_name); - - convertView.setTag(holder); - } else { - holder = (ViewHolder) convertView.getTag(); - } - - final ListShare currSharee = sharees.get(position); - - // Bind the view to the unique list ID - binderHelper.bind(holder.swipeLayout, currSharee.getShareWithEmail()); - - holder.textView.setText(currSharee.getShareWithEmail()); - - holder.deleteList.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 - public void onClick(View v) { - - } - }); - - return convertView; - } - - private class ViewHolder { - SwipeRevealLayout swipeLayout; - View frontView; - View deleteList; - View shareList; - TextView textView; - } -} diff --git a/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsAdapter.java b/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsAdapter.java index fa986a5..5f49bf5 100644 --- a/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsAdapter.java +++ b/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsAdapter.java @@ -7,14 +7,28 @@ import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; -import com.example.listify.R; -import com.example.listify.data.List; -import java.util.ArrayList; -public class ShoppingListsAdapter extends BaseAdapter { +import com.example.listify.AuthManager; +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 ShoppingListsAdapter extends BaseAdapter implements Requestor.Receiver { private Activity activity; private ArrayList lists; private LayoutInflater inflater; + private TextView tvListName; + private List curList; + private Requestor requestor; public ShoppingListsAdapter(Activity activity, ArrayList lists){ this.activity = activity; @@ -45,11 +59,19 @@ public class ShoppingListsAdapter extends BaseAdapter { convertView = inflater.inflate(R.layout.shopping_lists_name_item, null); } - List curList = lists.get(position); + curList = lists.get(position); + + tvListName = (TextView) convertView.findViewById(R.id.shopping_list_name); - TextView tvListName = (TextView) convertView.findViewById(R.id.shopping_list_name); if(curList.isShared()) { - tvListName.setText(curList.getName() + " (shared by " + curList.getOwner() + ")"); + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(activity, "android.resource://" + activity.getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + requestor = new Requestor(am, configs.getProperty("apiKey")); + requestor.getObject(Integer.toString(curList.getListID()), ListShare.class, this); } else { tvListName.setText(curList.getName()); @@ -57,4 +79,23 @@ public class ShoppingListsAdapter extends BaseAdapter { return convertView; } + + @Override + public void acceptDelivery(Object delivered) { + ListShare sharee = (ListShare) delivered; + + if(sharee != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if(sharee.getShareWithEmail().equals(am.getEmail(requestor))) { + tvListName.setText(curList.getName() + " (shared by me)"); + } + else { + tvListName.setText(curList.getName() + " (shared by " + sharee.getShareWithEmail() + ")"); + } + } + }); + } + } } \ No newline at end of file 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 1ad6d5e..8be09ed 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 @@ -31,10 +31,13 @@ import java.util.Properties; import static com.example.listify.MainActivity.am; -public class ShoppingListsSwipeableAdapter extends BaseAdapter { +public class ShoppingListsSwipeableAdapter extends BaseAdapter implements Requestor.Receiver { private Activity activity; private ArrayList lists; private LayoutInflater inflater; + private List curList; + private ViewHolder holder; + private Requestor requestor; private final ViewBinderHelper binderHelper; public ShoppingListsSwipeableAdapter(Activity activity, ArrayList lists){ @@ -59,16 +62,33 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { } @Override - public View getView(int position, View convertView, ViewGroup parent) { - ViewHolder holder; + public void acceptDelivery(Object delivered) { + ListShare sharee = (ListShare) delivered; + if(sharee != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if(sharee.getShareWithEmail().equals(am.getEmail(requestor))) { + holder.listName.setText(curList.getName() + " (shared by me)"); + } + else { + holder.listName.setText(curList.getName() + " (shared by " + sharee.getShareWithEmail() + ")"); + } + } + }); + } + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { 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")); + requestor = new Requestor(am, configs.getProperty("apiKey")); if (inflater == null) { inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); @@ -89,13 +109,13 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { holder = (ViewHolder) convertView.getTag(); } - final List curList = lists.get(position); + curList = lists.get(position); // Bind the view to the unique list ID binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getListID())); if(curList.isShared()) { - holder.listName.setText(curList.getName() + " (shared by " + curList.getOwner() + ")"); + requestor.getObject(Integer.toString(curList.getListID()), ListShare.class, this); } else { holder.listName.setText(curList.getName()); @@ -129,10 +149,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { @Override public void onClick(View v) { Intent listSharees = new Intent(activity, ListSharees.class); - - // Send the list ID and list name listSharees.putExtra("listID", curList.getListID()); - activity.startActivity(listSharees); } }); @@ -141,10 +158,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { @Override public void onClick(View v) { Intent listPage = new Intent(activity, ListPage.class); - - // Send the selected list listPage.putExtra("selectedList", curList); - activity.startActivity(listPage); } });