Restored list page code back to version ba8f249

This commit is contained in:
Aaron Sun 2020-12-03 22:51:05 -08:00
parent 5312bd3b8e
commit 433ad774f3
2 changed files with 17 additions and 75 deletions

View File

@ -22,13 +22,11 @@ import java.util.Properties;
import static com.example.listify.MainActivity.am;
public class ShoppingListsAdapter extends BaseAdapter implements Requestor.Receiver {
public class ShoppingListsAdapter extends BaseAdapter {
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;
@ -59,54 +57,22 @@ public class ShoppingListsAdapter extends BaseAdapter implements Requestor.Recei
convertView = inflater.inflate(R.layout.shopping_lists_name_item, null);
}
curList = lists.get(position);
final List curList = lists.get(position);
tvListName = (TextView) convertView.findViewById(R.id.shopping_list_name);
tvListName.setText(curList.getName());
if(curList.isShared()) {
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(activity, "android.resource://" + activity.getPackageName() + "/raw/auths.json");
} catch (IOException | JSONException e) {
e.printStackTrace();
tvListName.setText(curList.getName() + " (shared by User " + curList.getOwner() + ")");
String listText = tvListName.getText().toString();
if(listText.length() > 25) {
tvListName.setText(listText.substring(0, 25) + "...");
}
requestor = new Requestor(am, configs.getProperty("apiKey"));
requestor.getObject(Integer.toString(curList.getListID()), ListShare.class, this);
}
String listText = tvListName.getText().toString();
if(listText.length() > 25) {
tvListName.setText(listText.substring(0, 25) + "...");
}
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)");
}
else {
tvListName.setText(curList.getName() + " (" + sharee.getShareWithEmail() + ")");
}
String listText = tvListName.getText().toString();
if(listText.length() > 25) {
tvListName.setText(listText.substring(0, 25) + "...");
}
}
});
}
}
}

View File

@ -22,11 +22,10 @@ import java.util.Properties;
import static com.example.listify.MainActivity.am;
public class ShoppingListsSwipeableAdapter extends BaseAdapter implements Requestor.Receiver {
public class ShoppingListsSwipeableAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<List> lists;
private LayoutInflater inflater;
private List curList;
private ViewHolder holder;
private Requestor requestor;
private final ViewBinderHelper binderHelper;
@ -52,31 +51,6 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter implements Reques
return position;
}
@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))) {
holder.listName.setText(curList.getName() + " (shared)");
}
else {
holder.listName.setText(curList.getName() + " (" + sharee.getShareWithEmail() + ")");
}
String listText = holder.listName.getText().toString();
if(listText.length() > 25) {
holder.listName.setText(listText.substring(0, 25) + "...");
}
}
});
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Properties configs = new Properties();
@ -106,7 +80,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter implements Reques
holder = (ViewHolder) convertView.getTag();
}
curList = lists.get(position);
final List curList = lists.get(position);
// Bind the view to the unique list ID
binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getListID()));
@ -114,15 +88,17 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter implements Reques
holder.listName.setText(curList.getName());
if(curList.isShared()) {
requestor.getObject(Integer.toString(curList.getListID()), ListShare.class, this);
holder.listName.setText(curList.getName() + " (shared by User " + curList.getOwner() + ")");
String listText = holder.listName.getText().toString();
if(listText.length() > 25) {
holder.listName.setText(listText.substring(0, 25) + "...");
}
}
String listText = holder.listName.getText().toString();
if(listText.length() > 25) {
holder.listName.setText(listText.substring(0, 25) + "...");
}
if (curList.getEntries() != null) {
holder.itemCount.setText(String.format("%d items", curList.getEntries().length));
} else {