mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Merge branch 'master' into async-loading
This commit is contained in:
commit
4a43b84aba
@ -7,19 +7,18 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class ItemSearcher implements CallHandler {
|
public class ItemSearcher implements CallHandler {
|
||||||
|
|
||||||
DBConnector connector;
|
Connection connection;
|
||||||
String cognitoID;
|
String cognitoID;
|
||||||
|
|
||||||
private final String GET_ITEM_MATCHES = "SELECT * FROM Product WHERE description LIKE ?";
|
private final String GET_ITEM_MATCHES = "SELECT * FROM Product WHERE description LIKE ? LIMIT 100;";
|
||||||
|
|
||||||
public ItemSearcher(DBConnector connector, String cognitoID) {
|
public ItemSearcher(Connection connection, String cognitoID) {
|
||||||
this.connector = connector;
|
this.connection = connection;
|
||||||
this.cognitoID = cognitoID;
|
this.cognitoID = cognitoID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object conductAction(Map<String, Object> body, HashMap<String, String> queryParams, String s) throws SQLException {
|
public Object conductAction(Map<String, Object> body, HashMap<String, String> queryParams, String s) throws SQLException {
|
||||||
try (Connection connection = connector.getConnection()) {
|
|
||||||
PreparedStatement getItemMatches = connection.prepareStatement(GET_ITEM_MATCHES);
|
PreparedStatement getItemMatches = connection.prepareStatement(GET_ITEM_MATCHES);
|
||||||
getItemMatches.setString(1, "%" + queryParams.get("id") + "%");
|
getItemMatches.setString(1, "%" + queryParams.get("id") + "%");
|
||||||
System.out.println(getItemMatches);
|
System.out.println(getItemMatches);
|
||||||
@ -28,5 +27,4 @@ public class ItemSearcher implements CallHandler {
|
|||||||
System.out.println(searchResultsObject);
|
System.out.println(searchResultsObject);
|
||||||
return searchResultsObject;
|
return searchResultsObject;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,20 +10,28 @@ import android.widget.*;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
|
||||||
import com.example.listify.data.Item;
|
import com.example.listify.data.Item;
|
||||||
import com.example.listify.data.List;
|
import com.example.listify.data.List;
|
||||||
import com.example.listify.data.ListEntry;
|
import com.example.listify.data.ListEntry;
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
import static com.example.listify.MainActivity.am;
|
import static com.example.listify.MainActivity.am;
|
||||||
|
|
||||||
public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
||||||
ListView listView;
|
ListView listView;
|
||||||
MyAdapter myAdapter;
|
MyAdapter myAdapter;
|
||||||
|
Requestor requestor;
|
||||||
|
|
||||||
Button incrQuan;
|
Button incrQuan;
|
||||||
Button decrQuan;
|
Button decrQuan;
|
||||||
@ -34,11 +42,14 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
ArrayList<String> pStores = new ArrayList<>();
|
ArrayList<String> pStores = new ArrayList<>();
|
||||||
ArrayList<String> pPrices = new ArrayList<>();
|
ArrayList<String> pPrices = new ArrayList<>();
|
||||||
ArrayList<String> pQuantity = new ArrayList<>();
|
ArrayList<String> pQuantity = new ArrayList<>();
|
||||||
ArrayList<Integer> pImages = new ArrayList<>();
|
ArrayList<String> pImages = new ArrayList<>();
|
||||||
|
|
||||||
ArrayList<ListEntry> pListItemPair = new ArrayList<>();
|
ArrayList<ListEntry> pListItemPair = new ArrayList<>();
|
||||||
|
|
||||||
Requestor requestor;
|
Map<String, Double> totalPriceByStore = new HashMap<>();
|
||||||
|
Map<String, Integer> storeHeaderIndex = new HashMap<>();
|
||||||
|
|
||||||
|
DecimalFormat df = new DecimalFormat("0.00");
|
||||||
|
|
||||||
// TODO: Display a message if their list is empty
|
// TODO: Display a message if their list is empty
|
||||||
@Override
|
@Override
|
||||||
@ -57,6 +68,14 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
loadingListItems = findViewById(R.id.progress_loading_list_items);
|
loadingListItems = findViewById(R.id.progress_loading_list_items);
|
||||||
loadingListItems.setVisibility(View.VISIBLE);
|
loadingListItems.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
pNames.add("Total Price");
|
||||||
|
pStores.add("");
|
||||||
|
pPrices.add("0.00");
|
||||||
|
pQuantity.add("-1");
|
||||||
|
pImages.add("-1");
|
||||||
|
pListItemPair.add(null);
|
||||||
|
|
||||||
|
|
||||||
Properties configs = new Properties();
|
Properties configs = new Properties();
|
||||||
try {
|
try {
|
||||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||||
@ -64,7 +83,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
requestor = new Requestor(am, configs.getProperty("apiKey"));
|
requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
//ListReceiver<List> lr = new ListReceiver<>();
|
|
||||||
requestor.getObject(Integer.toString(listID), List.class, this);
|
requestor.getObject(Integer.toString(listID), List.class, this);
|
||||||
|
|
||||||
/*pNames.add("Half-gallon organic whole milk");
|
/*pNames.add("Half-gallon organic whole milk");
|
||||||
@ -103,16 +122,52 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
item = null;
|
item = null;
|
||||||
}
|
}
|
||||||
if(item != null) {
|
if(item != null) {
|
||||||
|
if(!totalPriceByStore.containsKey("Kroger")) {
|
||||||
|
totalPriceByStore.put("Kroger", item.getPrice().doubleValue() * entry.getQuantity());
|
||||||
|
storeHeaderIndex.put("Kroger", pNames.size());
|
||||||
|
|
||||||
|
double newTotal = Double.parseDouble(pPrices.get(0)) + (item.getPrice().doubleValue() * entry.getQuantity());
|
||||||
|
pPrices.set(0, String.valueOf(newTotal));
|
||||||
|
|
||||||
|
pNames.add("Kroger");
|
||||||
|
pStores.add("");
|
||||||
|
pPrices.add(df.format(totalPriceByStore.get("Kroger")));
|
||||||
|
pQuantity.add("-1");
|
||||||
|
pImages.add("-1");
|
||||||
|
pListItemPair.add(null);
|
||||||
|
|
||||||
pNames.add(item.getDescription());
|
pNames.add(item.getDescription());
|
||||||
pStores.add("Kroger");
|
pStores.add("Kroger");
|
||||||
pPrices.add(item.getPrice().toString());
|
pPrices.add(df.format(item.getPrice()));
|
||||||
pQuantity.add(entry.getQuantity().toString());
|
pQuantity.add(entry.getQuantity().toString());
|
||||||
pImages.add(R.drawable.placeholder);
|
pImages.add(item.getImageURL());
|
||||||
pListItemPair.add(entry);
|
pListItemPair.add(entry);
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
}
|
int index = storeHeaderIndex.get("Kroger");
|
||||||
|
|
||||||
|
totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") + (item.getPrice().doubleValue() * entry.getQuantity()));
|
||||||
|
pPrices.set(index, df.format(totalPriceByStore.get("Kroger")));
|
||||||
|
|
||||||
|
double newTotal = Double.parseDouble(pPrices.get(0)) + (item.getPrice().doubleValue() * entry.getQuantity());
|
||||||
|
pPrices.set(0, df.format(newTotal));
|
||||||
|
index++;
|
||||||
|
|
||||||
|
pNames.add(index, item.getDescription());
|
||||||
|
pStores.add(index, "Kroger");
|
||||||
|
pPrices.add(index, df.format(item.getPrice()));
|
||||||
|
pQuantity.add(index, entry.getQuantity().toString());
|
||||||
|
pImages.add(index, item.getImageURL());
|
||||||
|
pListItemPair.add(index, entry);
|
||||||
|
|
||||||
|
for(String store : storeHeaderIndex.keySet()) {
|
||||||
|
if(storeHeaderIndex.get(store) > index) {
|
||||||
|
storeHeaderIndex.put(store, storeHeaderIndex.get(store) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -121,6 +176,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MyAdapter extends ArrayAdapter<String> {
|
class MyAdapter extends ArrayAdapter<String> {
|
||||||
Context context;
|
Context context;
|
||||||
@ -128,9 +184,9 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
ArrayList<String> pStores;
|
ArrayList<String> pStores;
|
||||||
ArrayList<String> pPrices;
|
ArrayList<String> pPrices;
|
||||||
ArrayList<String> pQuantity;
|
ArrayList<String> pQuantity;
|
||||||
ArrayList<Integer> pImages;
|
ArrayList<String> pImages;
|
||||||
|
|
||||||
MyAdapter (Context c, ArrayList<String> names, ArrayList<String> stores, ArrayList<String> prices, ArrayList<String> quantity, ArrayList<Integer> images) {
|
MyAdapter (Context c, ArrayList<String> names, ArrayList<String> stores, ArrayList<String> prices, ArrayList<String> quantity, ArrayList<String> images) {
|
||||||
super(c, R.layout.activity_listproductentry, R.id.productView, names);
|
super(c, R.layout.activity_listproductentry, R.id.productView, names);
|
||||||
context = c;
|
context = c;
|
||||||
pNames = names;
|
pNames = names;
|
||||||
@ -155,6 +211,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int q = Integer.parseInt(pQuantity.get(position)) - 1;
|
int q = Integer.parseInt(pQuantity.get(position)) - 1;
|
||||||
pQuantity.set(position, Integer.toString(q));
|
pQuantity.set(position, Integer.toString(q));
|
||||||
|
totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) - Double.parseDouble(pPrices.get(position)));
|
||||||
|
pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position))));
|
||||||
|
double newTotal = Double.parseDouble(pPrices.get(0)) - Double.parseDouble(pPrices.get(position));
|
||||||
|
pPrices.set(0, df.format(newTotal));
|
||||||
ListEntry le = pListItemPair.remove(position);
|
ListEntry le = pListItemPair.remove(position);
|
||||||
le.setQuantity(le.getQuantity() - 1);
|
le.setQuantity(le.getQuantity() - 1);
|
||||||
pListItemPair.add(position, le);
|
pListItemPair.add(position, le);
|
||||||
@ -184,6 +244,10 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
int q = Integer.parseInt(pQuantity.get(position)) + 1;
|
int q = Integer.parseInt(pQuantity.get(position)) + 1;
|
||||||
pQuantity.set(position, Integer.toString(q));
|
pQuantity.set(position, Integer.toString(q));
|
||||||
|
totalPriceByStore.put(pStores.get(position), totalPriceByStore.get(pStores.get(position)) + Double.parseDouble(pPrices.get(position)));
|
||||||
|
pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position))));
|
||||||
|
double newTotal = Double.parseDouble(pPrices.get(0)) + Double.parseDouble(pPrices.get(position));
|
||||||
|
pPrices.set(0, df.format(newTotal));
|
||||||
ListEntry le = pListItemPair.remove(position);
|
ListEntry le = pListItemPair.remove(position);
|
||||||
le.setQuantity(le.getQuantity() + 1);
|
le.setQuantity(le.getQuantity() + 1);
|
||||||
pListItemPair.add(position, le);
|
pListItemPair.add(position, le);
|
||||||
@ -211,6 +275,33 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
removeItem.setOnClickListener(new View.OnClickListener() {
|
removeItem.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
if(position == 0) {
|
||||||
|
pNames.clear();
|
||||||
|
pStores.clear();
|
||||||
|
pPrices.clear();
|
||||||
|
pQuantity.clear();
|
||||||
|
pImages.clear();
|
||||||
|
|
||||||
|
pNames.add("Total Price");
|
||||||
|
pStores.add("");
|
||||||
|
pPrices.add("0.00");
|
||||||
|
pQuantity.add("-1");
|
||||||
|
pImages.add("-1");
|
||||||
|
|
||||||
|
while(pListItemPair.size() > 1) {
|
||||||
|
try {
|
||||||
|
requestor.deleteObject(pListItemPair.remove(1));
|
||||||
|
}
|
||||||
|
catch(Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
totalPriceByStore.put("Kroger", totalPriceByStore.get("Kroger") - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position))));
|
||||||
|
pPrices.set(storeHeaderIndex.get(pStores.get(position)), df.format(totalPriceByStore.get(pStores.get(position))));
|
||||||
|
|
||||||
|
double newTotal = Double.parseDouble(pPrices.get(0)) - (Double.parseDouble(pPrices.get(position)) * Integer.parseInt(pQuantity.get(position)));
|
||||||
|
pPrices.set(0, df.format(newTotal));
|
||||||
|
|
||||||
pNames.remove(position);
|
pNames.remove(position);
|
||||||
pStores.remove(position);
|
pStores.remove(position);
|
||||||
pPrices.remove(position);
|
pPrices.remove(position);
|
||||||
@ -218,6 +309,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
pImages.remove(position);
|
pImages.remove(position);
|
||||||
|
|
||||||
requestor.deleteObject(pListItemPair.remove(position));
|
requestor.deleteObject(pListItemPair.remove(position));
|
||||||
|
}
|
||||||
|
|
||||||
listView.setAdapter(myAdapter);
|
listView.setAdapter(myAdapter);
|
||||||
}
|
}
|
||||||
@ -232,36 +324,33 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
|
|||||||
if(!pNames.isEmpty()) {
|
if(!pNames.isEmpty()) {
|
||||||
name.setText(pNames.get(position));
|
name.setText(pNames.get(position));
|
||||||
store.setText(pStores.get(position));
|
store.setText(pStores.get(position));
|
||||||
price.setText(pPrices.get(position));
|
price.setText("$" + pPrices.get(position));
|
||||||
|
|
||||||
|
if(pQuantity.get(position).equals("-1")) {
|
||||||
|
quantity.setVisibility(View.INVISIBLE);
|
||||||
|
decrQuan.setVisibility(View.INVISIBLE);
|
||||||
|
incrQuan.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
if(position == 0) {
|
||||||
|
removeItem.setText("Clear all");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
removeItem.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
quantity.setText(pQuantity.get(position));
|
quantity.setText(pQuantity.get(position));
|
||||||
image.setImageResource(pImages.get(position));
|
}
|
||||||
|
|
||||||
|
if(pImages.get(position).equals("-1")) {
|
||||||
|
image.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Glide.with(getContext()).load(pImages.get(position)).into(image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return listproduct;
|
return listproduct;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ListReceiver<T> implements Requestor.Receiver<T> {
|
|
||||||
@Override
|
|
||||||
public void acceptDelivery(T delivered) {
|
|
||||||
for(ListEntry entry : ((List) delivered).getEntries()) {
|
|
||||||
int product = entry.getProductID();
|
|
||||||
ProductReceiver<Item> pr = new ProductReceiver<>();
|
|
||||||
requestor.getObject(Integer.toString(product), Item.class, pr);
|
|
||||||
pQuantity.add(entry.getQuantity().toString());
|
|
||||||
pListItemPair.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProductReceiver<T> implements Requestor.Receiver<T> {
|
|
||||||
@Override
|
|
||||||
public void acceptDelivery(T delivered) {
|
|
||||||
Item i = (Item) delivered;
|
|
||||||
pNames.add(i.getDescription());
|
|
||||||
pStores.add("Kroger");
|
|
||||||
pPrices.add(i.getPrice().toString());
|
|
||||||
pImages.add(R.drawable.placeholder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,9 +84,7 @@ public class ForgotPasswordPage extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {}
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|||||||
@ -103,9 +103,7 @@ public class SignupPage extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {}
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|||||||
@ -70,9 +70,7 @@ public class HomeFragment extends Fragment {
|
|||||||
});
|
});
|
||||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {}
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|||||||
@ -20,11 +20,6 @@
|
|||||||
android:id="@+id/nav_lists"
|
android:id="@+id/nav_lists"
|
||||||
android:icon="@drawable/ic_baseline_list_alt_28"
|
android:icon="@drawable/ic_baseline_list_alt_28"
|
||||||
android:title="@string/menu_lists" />
|
android:title="@string/menu_lists" />
|
||||||
<!-- <item-->
|
|
||||||
<!-- android:id="@+id/nav_create_list"-->
|
|
||||||
<!-- android:icon="@drawable/ic_baseline_add_28"-->
|
|
||||||
<!-- android:title="Create New List"-->
|
|
||||||
<!-- android:onClick="onClickCreateList" />-->
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_logout"
|
android:id="@+id/nav_logout"
|
||||||
android:title="Sign out"
|
android:title="Sign out"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user