Merge pull request #150 from ClaytonWWilson/aaron-branch-2

Aaron branch 2
This commit is contained in:
Aaron Sun 2020-12-02 15:03:09 -08:00 committed by GitHub
commit 6987a251fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 153 deletions

View File

@ -129,12 +129,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;
}
}

View File

@ -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<ListShare> sharees;
private LayoutInflater inflater;
private final ViewBinderHelper binderHelper;
public ShareeSwipeableAdapter(Activity activity, ArrayList<ListShare> 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;
}
}

View File

@ -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<List> lists;
private LayoutInflater inflater;
private TextView tvListName;
private List curList;
private Requestor requestor;
public ShoppingListsAdapter(Activity activity, ArrayList<List> 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() + ")");
}
}
});
}
}
}

View File

@ -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<List> lists;
private LayoutInflater inflater;
private List curList;
private ViewHolder holder;
private Requestor requestor;
private final ViewBinderHelper binderHelper;
public ShoppingListsSwipeableAdapter(Activity activity, ArrayList<List> 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);
}
});