mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-15 18:28:47 +00:00
commit
2099fb72b1
@ -2,9 +2,10 @@ import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProvider;
|
||||
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClientBuilder;
|
||||
import com.amazonaws.services.cognitoidp.model.AdminDeleteUserRequest;
|
||||
import com.amazonaws.services.cognitoidp.model.AdminUserGlobalSignOutRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -12,13 +13,15 @@ import java.util.Properties;
|
||||
|
||||
public class UserDeleter implements CallHandler {
|
||||
|
||||
private Connection connector;
|
||||
private Connection connection;
|
||||
private String cognitoID;
|
||||
|
||||
//private final String REMOVE_FROM_LIST = "DELETE FROM ListProduct WHERE (ProductID = ? AND ListID = ?);";
|
||||
private final String GET_LISTS = "SELECT * FROM List WHERE (owner = ?);";
|
||||
private final String DELETE_LIST_PRODUCT = "DELETE FROM ListProduct WHERE (listID = ?);";
|
||||
private final String DELETE_LISTS = "DELETE FROM List WHERE (owner = ?);";
|
||||
|
||||
public UserDeleter(Connection connector, String cognitoID) {
|
||||
this.connector = connector;
|
||||
public UserDeleter(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
@ -41,19 +44,30 @@ public class UserDeleter implements CallHandler {
|
||||
adminDeleteUserRequest.setUsername(cognitoID);
|
||||
System.out.println(adminDeleteUserRequest);
|
||||
awsCognitoIdentityProvider.adminDeleteUser(adminDeleteUserRequest);
|
||||
return null;
|
||||
|
||||
// Connection connection = connector.getConnection();
|
||||
// try {
|
||||
// PreparedStatement statement = connection.prepareStatement(REMOVE_FROM_LIST);
|
||||
// statement.setInt(1, (Integer) bodyMap.get("ProductID"));
|
||||
// statement.setInt(2, (Integer) bodyMap.get("ListID"));
|
||||
// System.out.println(statement);
|
||||
// statement.executeUpdate();
|
||||
// connection.commit();
|
||||
// } finally {
|
||||
// connection.close();
|
||||
// }
|
||||
// return null;
|
||||
|
||||
try {
|
||||
PreparedStatement statement = connection.prepareStatement(GET_LISTS);
|
||||
statement.setString(1, cognitoID);
|
||||
System.out.println(statement);
|
||||
ResultSet userLists = statement.executeQuery();
|
||||
while (userLists.next()) {
|
||||
int listID = userLists.getInt("listID");
|
||||
|
||||
statement = connection.prepareStatement(DELETE_LIST_PRODUCT);
|
||||
statement.setInt(1, listID);
|
||||
System.out.println(statement);
|
||||
statement.executeQuery();
|
||||
}
|
||||
|
||||
statement = connection.prepareStatement(DELETE_LISTS);
|
||||
statement.setString(1, cognitoID);
|
||||
System.out.println(statement);
|
||||
statement.executeQuery();
|
||||
connection.commit();
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,97 @@
|
||||
package com.example.listify;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
|
||||
public class CreateListAddDialogFragment extends DialogFragment {
|
||||
|
||||
public interface OnNewListAddListener {
|
||||
void sendNewListName(String name, int quantity);
|
||||
}
|
||||
|
||||
public OnNewListAddListener onNewAddListListener;
|
||||
|
||||
EditText etNewListName;
|
||||
EditText etQuantity;
|
||||
Button btnMinus;
|
||||
Button btnPlus;
|
||||
|
||||
public CreateListAddDialogFragment() {}
|
||||
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
// Get the layout inflater
|
||||
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||
|
||||
// Inflate and set the layout for the dialog
|
||||
// Pass null as the parent view because its going in the dialog layout
|
||||
View root = inflater.inflate(R.layout.dialog_create_list_add, null);
|
||||
builder.setView(root)
|
||||
// Add action buttons
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
onNewAddListListener.sendNewListName(etNewListName.getText().toString(), Integer.parseInt(etQuantity.getText().toString()));
|
||||
}
|
||||
})
|
||||
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
CreateListAddDialogFragment.this.getDialog().cancel();
|
||||
}
|
||||
});
|
||||
|
||||
etNewListName = (EditText) root.findViewById(R.id.et_new_list_name);
|
||||
|
||||
// Set up quantity selection
|
||||
etQuantity = (EditText) root.findViewById(R.id.et_quantity);
|
||||
|
||||
btnMinus = (Button) root.findViewById(R.id.btn_minus);
|
||||
btnMinus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int curQauntity = Integer.parseInt(etQuantity.getText().toString());
|
||||
if (curQauntity > 0) {
|
||||
curQauntity--;
|
||||
etQuantity.setText(String.format("%d", curQauntity));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
btnPlus = (Button) root.findViewById(R.id.btn_plus);
|
||||
btnPlus.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int curQauntity = Integer.parseInt(etQuantity.getText().toString());
|
||||
curQauntity++;
|
||||
etQuantity.setText(String.format("%d", curQauntity));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
// Required to extend DialogFragment
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
try {
|
||||
onNewAddListListener = (OnNewListAddListener) getActivity();
|
||||
} catch (ClassCastException e) {
|
||||
Log.e("CreateListAddDialogFragment", "onAttach: ClassCastException: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,7 +51,6 @@ public class CreateListDialogFragment extends DialogFragment {
|
||||
|
||||
etNewListName = (EditText) root.findViewById(R.id.et_new_list_name);
|
||||
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
package com.example.listify;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.amplifyframework.auth.AuthException;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.listify.data.List;
|
||||
import com.example.listify.data.ListEntry;
|
||||
import com.example.listify.model.Product;
|
||||
import com.example.listify.model.ShoppingList;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
@ -13,9 +16,17 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ItemDetails extends AppCompatActivity implements ListPickerDialogFragment.OnListPickListener, CreateListDialogFragment.OnNewListListener {
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
import static com.example.listify.MainActivity.am;
|
||||
|
||||
public class ItemDetails extends AppCompatActivity implements ListPickerDialogFragment.OnListPickListener, CreateListAddDialogFragment.OnNewListAddListener {
|
||||
private Product curProduct;
|
||||
private LinearLayout linAddItem;
|
||||
private LinearLayout linCreateList;
|
||||
@ -28,7 +39,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
|
||||
private TextView tvItemDesc;
|
||||
private ImageButton backToSearchbutton;
|
||||
|
||||
ArrayList<ShoppingList> shoppingLists = new ArrayList<>();
|
||||
ArrayList<List> shoppingLists = new ArrayList<>();
|
||||
|
||||
private boolean isFABOpen = false;
|
||||
|
||||
@ -62,9 +73,26 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
|
||||
public void onClick(View v) {
|
||||
closeFABMenu();
|
||||
|
||||
// Hardcode shopping lists to demonstrate displaying lists
|
||||
for (int i = 0; i < 10; i++) {
|
||||
shoppingLists.add(new ShoppingList(Integer.toString(i)));
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(ItemDetails.this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
SynchronousReceiver<Integer[]> listIdsReceiver = new SynchronousReceiver<>();
|
||||
SynchronousReceiver<List> listReceiver = new SynchronousReceiver<>();
|
||||
|
||||
requestor.getListOfIds(List.class, listIdsReceiver, listIdsReceiver);
|
||||
try {
|
||||
Integer[] listIds = listIdsReceiver.await();
|
||||
for (int i = 0; i < listIds.length; i++) {
|
||||
requestor.getObject(Integer.toString(listIds[i]), List.class, listReceiver, listReceiver);
|
||||
shoppingLists.add(listReceiver.await());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ListPickerDialogFragment listPickerDialog = new ListPickerDialogFragment(shoppingLists);
|
||||
@ -77,8 +105,8 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
|
||||
public void onClick(View v) {
|
||||
closeFABMenu();
|
||||
|
||||
CreateListDialogFragment createListDialogFragment = new CreateListDialogFragment();
|
||||
createListDialogFragment.show(getSupportFragmentManager(), "Create New List");
|
||||
CreateListAddDialogFragment createListAddDialogFragment = new CreateListAddDialogFragment();
|
||||
createListAddDialogFragment.show(getSupportFragmentManager(), "Create New List");
|
||||
}
|
||||
});
|
||||
|
||||
@ -130,13 +158,55 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
|
||||
}
|
||||
|
||||
|
||||
// Add the viewed item to the selected list
|
||||
@Override
|
||||
public void sendListSelection(int selectedListIndex, int quantity) {
|
||||
Toast.makeText(this, String.format("%d of Item added to %s", quantity, shoppingLists.get(selectedListIndex).getName()), Toast.LENGTH_LONG).show();
|
||||
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||
|
||||
|
||||
try {
|
||||
ListEntry entry = new ListEntry(shoppingLists.get(selectedListIndex).getItemID(), curProduct.getItemId(), quantity, Instant.now().toEpochMilli(),false);
|
||||
requestor.postObject(entry);
|
||||
Toast.makeText(this, String.format("%d of Item added to %s", quantity, shoppingLists.get(selectedListIndex).getName()), Toast.LENGTH_LONG).show();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "An error occurred", Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new list and add the item to it
|
||||
@Override
|
||||
public void sendNewListName(String name) {
|
||||
Toast.makeText(this, String.format("%s created", name), Toast.LENGTH_LONG).show();
|
||||
public void sendNewListName(String name, int quantity) {
|
||||
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||
|
||||
com.example.listify.data.List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli());
|
||||
|
||||
try {
|
||||
requestor.postObject(newList, idReceiver, idReceiver);
|
||||
int newListId = idReceiver.await();
|
||||
ListEntry entry = new ListEntry(newListId, curProduct.getItemId(), quantity, Instant.now().toEpochMilli(),false);
|
||||
requestor.postObject(entry);
|
||||
|
||||
Toast.makeText(this, String.format("%s created and item added", name), Toast.LENGTH_LONG).show();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "An error occurred", Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,6 +48,9 @@ public class ListPage extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
// Read list ID from caller
|
||||
final int listID = (int) getIntent().getSerializableExtra("listID");
|
||||
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
@ -57,7 +60,7 @@ public class ListPage extends AppCompatActivity {
|
||||
requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
SynchronousReceiver<List> lr = new SynchronousReceiver<>();
|
||||
//ListReceiver<List> lr = new ListReceiver<>();
|
||||
requestor.getObject("39", List.class, lr);
|
||||
requestor.getObject(Integer.toString(listID), List.class, lr);
|
||||
|
||||
List list;
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import com.example.listify.adapter.DisplayShoppingListsAdapter;
|
||||
import com.example.listify.data.List;
|
||||
import com.example.listify.model.ShoppingList;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -32,10 +33,10 @@ public class ListPickerDialogFragment extends DialogFragment {
|
||||
Button btnMinus;
|
||||
Button btnPlus;
|
||||
EditText etQuantity;
|
||||
private ArrayList<ShoppingList> userLists;
|
||||
private ArrayList<List> userLists;
|
||||
private int selectedListIndex;
|
||||
|
||||
public ListPickerDialogFragment(ArrayList<ShoppingList> userLists) {
|
||||
public ListPickerDialogFragment(ArrayList<List> userLists) {
|
||||
this.userLists = userLists;
|
||||
}
|
||||
|
||||
@ -63,11 +64,13 @@ public class ListPickerDialogFragment extends DialogFragment {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Display user's shopping lists
|
||||
userListsView = (ListView) root.findViewById(R.id.user_lists);
|
||||
displayShoppingListsAdapter = new DisplayShoppingListsAdapter(getActivity(), userLists);
|
||||
userListsView.setAdapter(displayShoppingListsAdapter);
|
||||
|
||||
// TODO: fix highlighting error
|
||||
userListsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
@ -75,7 +78,8 @@ public class ListPickerDialogFragment extends DialogFragment {
|
||||
parent.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
view.setBackgroundColor(Color.GREEN);
|
||||
parent.getChildAt(position).setBackgroundColor(Color.GREEN);
|
||||
// view.setBackgroundColor(Color.GREEN);
|
||||
selectedListIndex = position;
|
||||
}
|
||||
});
|
||||
|
||||
@ -6,6 +6,7 @@ import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
@ -20,7 +21,6 @@ import com.example.listify.data.List;
|
||||
import com.example.listify.data.ListEntry;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
@ -182,6 +182,24 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
||||
|
||||
@Override
|
||||
public void sendNewListName(String name) {
|
||||
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||
|
||||
List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli());
|
||||
|
||||
try {
|
||||
requestor.postObject(newList, idReceiver, idReceiver);
|
||||
System.out.println(idReceiver.await());
|
||||
Toast.makeText(this, String.format("%s created", name), Toast.LENGTH_LONG).show();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "An error occurred", Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,12 +10,17 @@ import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.Toast;
|
||||
import com.example.listify.adapter.SearchResultsListAdapter;
|
||||
import com.example.listify.data.ItemSearch;
|
||||
import com.example.listify.model.Product;
|
||||
import org.json.JSONException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import static com.example.listify.MainActivity.am;
|
||||
|
||||
public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener {
|
||||
private ListView listView;
|
||||
@ -131,39 +136,30 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
||||
}
|
||||
|
||||
private void doSearch(String query) {
|
||||
// TODO: Query Database
|
||||
// TODO: Create a new Product Object for each result
|
||||
// TODO: Add each result to productList
|
||||
|
||||
// Clear the old search results
|
||||
resultsProductList = new ArrayList<>();
|
||||
resultsProductList.clear();
|
||||
|
||||
// Hardcode some search results...
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Product a = new Product("Bottled Water", "0000", "Walmart", "0001", "0123456780", "Bro, it's water...", "Grocery", 13.37, "9/24/2020", "1", "http://3.bp.blogspot.com/-MfroPPQVDKo/UyhUZWqGvkI/AAAAAAAAB-I/DGk622onsvc/s1600/lettuce-b-kool-cat-meme.jpg");
|
||||
Product b = new Product("Tin Foil", "0001", "Walmart", "0001", "0123456781", "Not aluminum foil", "Grocery", 1.00, "9/24/2020", "1", "https://i.ytimg.com/vi/q9N1doYMxR0/maxresdefault.jpg");
|
||||
Product c = new Product("Lettuce", "0002", "Walmart", "0001", "0123456782", "Burger King foot lettuce", "Grocery", 0.60, "9/24/2020", "1", "https://www.cattitudedaily.com/wp-content/uploads/2019/12/white-cat-meme-feature.jpg");
|
||||
Product d = new Product("Video Game", "0003", "Walmart", "0001", "0123456783", "Fun Vidya Gaemz", "Electronics", 60.00, "9/24/2020", "1", "https://i1.wp.com/bestlifeonline.com/wp-content/uploads/2018/06/cat-meme-67.jpg?resize=1024%2C1024&ssl=1");
|
||||
Product e = new Product("Mountain Dew", "0004", "Walmart", "0001", "0123456784", "Gamer fuel", "Grocery", 5.87, "9/24/2020", "1", "https://memeguy.com/photos/images/gaming-cat-7680.png");
|
||||
Product f = new Product("Tire", "0005", "Kroger", "0002", "0123456785", "30 inch rims", "Automotive", 146.97, "9/24/2020", "1", "http://cdn.sheknows.com/articles/2013/05/pet5.jpg");
|
||||
Product g = new Product("This is a test for a product that has a very long title to see if the text overflows", "0006", "Target", "0003", "0123456786", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Elit ut aliquam purus sit amet luctus venenatis. Tellus orci ac auctor augue mauris augue neque gravida. Habitant morbi tristique senectus et netus. Dignissim diam quis enim lobortis. Suspendisse sed nisi lacus sed viverra tellus in. Viverra adipiscing at in tellus integer feugiat scelerisque. Volutpat consequat mauris nunc congue nisi vitae suscipit tellus. Habitant morbi tristique senectus et netus et malesuada. Quis enim lobortis scelerisque fermentum dui faucibus in ornare quam. Mattis pellentesque id nibh tortor id aliquet. Volutpat blandit aliquam etiam erat. Vestibulum lorem sed risus ultricies tristique nulla aliquet.\n" +
|
||||
"\n" +
|
||||
"Placerat orci nulla pellentesque dignissim. Quisque non tellus orci ac. Mattis enim ut tellus elementum sagittis vitae et. Interdum velit euismod in pellentesque massa placerat duis ultricies. Id nibh tortor id aliquet lectus. Massa placerat duis ultricies lacus sed. Convallis convallis tellus id interdum velit laoreet id donec. Amet luctus venenatis lectus magna fringilla urna porttitor rhoncus. Sodales ut eu sem integer vitae justo. Viverra ipsum nunc aliquet bibendum enim facilisis.\n" +
|
||||
"\n" +
|
||||
"Eget felis eget nunc lobortis mattis aliquam faucibus purus. Odio morbi quis commodo odio aenean sed adipiscing. Hac habitasse platea dictumst quisque sagittis purus sit. Nam libero justo laoreet sit. Et malesuada fames ac turpis egestas. Erat nam at lectus urna duis convallis convallis. Morbi tincidunt ornare massa eget egestas purus viverra accumsan in. Ut venenatis tellus in metus vulputate eu scelerisque felis imperdiet. At auctor urna nunc id cursus. Sed elementum tempus egestas sed. Lorem dolor sed viverra ipsum nunc aliquet bibendum. Orci eu lobortis elementum nibh tellus molestie. Porttitor leo a diam sollicitudin tempor. Adipiscing bibendum est ultricies integer quis auctor elit sed. Arcu cursus euismod quis viverra nibh. A diam sollicitudin tempor id eu nisl.\n" +
|
||||
"\n" +
|
||||
"Sapien eget mi proin sed libero enim sed faucibus turpis. Pharetra massa massa ultricies mi quis hendrerit dolor magna. Integer enim neque volutpat ac tincidunt vitae semper. Euismod lacinia at quis risus sed vulputate. Ut venenatis tellus in metus vulputate eu scelerisque. Etiam erat velit scelerisque in dictum non consectetur. Viverra nam libero justo laoreet sit amet cursus sit. Arcu non sodales neque sodales. Vivamus arcu felis bibendum ut tristique et egestas quis. Sed adipiscing diam donec adipiscing tristique risus. Sollicitudin tempor id eu nisl nunc mi ipsum faucibus vitae. Velit ut tortor pretium viverra suspendisse potenti nullam ac tortor. Non nisi est sit amet facilisis magna etiam. Tortor at risus viverra adipiscing. Donec ultrices tincidunt arcu non sodales neque sodales. Eget egestas purus viverra accumsan. Enim lobortis scelerisque fermentum dui faucibus in ornare. Porttitor massa id neque aliquam. Ut consequat semper viverra nam. Orci ac auctor augue mauris augue neque gravida.\n" +
|
||||
"\n" +
|
||||
"Lacus sed viverra tellus in hac habitasse platea dictumst. Nec ullamcorper sit amet risus nullam eget felis eget nunc. Semper feugiat nibh sed pulvinar. Consequat nisl vel pretium lectus quam id leo in. Volutpat maecenas volutpat blandit aliquam etiam erat velit scelerisque. Faucibus a pellentesque sit amet porttitor eget. Sed viverra tellus in hac habitasse platea dictumst vestibulum. Placerat vestibulum lectus mauris ultrices eros in cursus turpis. Sed tempus urna et pharetra pharetra massa massa ultricies mi. Ornare arcu odio ut sem. Ornare arcu dui vivamus arcu felis bibendum ut. Feugiat pretium nibh ipsum consequat. Consectetur adipiscing elit ut aliquam purus sit amet luctus venenatis. Felis eget velit aliquet sagittis id consectetur purus ut.", "Automotive", 45.22, "9/24/2020", "1", "http://cdn.sheknows.com/articles/2013/05/pet5.jpg");
|
||||
Product h = new Product("Tin Foil", "0001", "Kroger", "0001", "0123456781", "Not aluminum foil", "Grocery", 1.00, "9/24/2020", "1", "https://i.ytimg.com/vi/q9N1doYMxR0/maxresdefault.jpg");
|
||||
resultsProductList.add(a);
|
||||
resultsProductList.add(b);
|
||||
resultsProductList.add(c);
|
||||
resultsProductList.add(d);
|
||||
resultsProductList.add(e);
|
||||
resultsProductList.add(f);
|
||||
resultsProductList.add(g);
|
||||
resultsProductList.add(h);
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
|
||||
SynchronousReceiver<ItemSearch> itemReceiver = new SynchronousReceiver<>();
|
||||
requestor.getObject(query, ItemSearch.class, itemReceiver, itemReceiver);
|
||||
ItemSearch results;
|
||||
try {
|
||||
results = itemReceiver.await();
|
||||
for (int i = 0; i < results.getResults().size(); i++) {
|
||||
// TODO: Change to dynamically grab chain name by id
|
||||
resultsProductList.add(new Product(results.getResults().get(i).getDescription(), results.getResults().get(i).getProductID(), "Kroger", results.getResults().get(i).getChainID(), results.getResults().get(i).getUpc(), results.getResults().get(i).getDescription(), results.getResults().get(i).getPrice(), results.getResults().get(i).getImageURL(), results.getResults().get(i).getDepartment()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Create a list of all stores in the results so the user can filter by store name
|
||||
@ -212,9 +208,9 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
||||
resultsProductListSorted.sort(new Comparator<Product>() {
|
||||
@Override
|
||||
public int compare(Product a, Product b) {
|
||||
if (b.getPrice() - a.getPrice() > 0) {
|
||||
if (b.getPrice().compareTo(a.getPrice()) > 0) {
|
||||
return 1;
|
||||
} else if (b.getPrice() - a.getPrice() < 0) {
|
||||
} else if (b.getPrice().compareTo(a.getPrice()) < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
|
||||
@ -8,15 +8,15 @@ import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
import com.example.listify.R;
|
||||
import com.example.listify.model.ShoppingList;
|
||||
import com.example.listify.data.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DisplayShoppingListsAdapter extends BaseAdapter {
|
||||
private Activity activity;
|
||||
private ArrayList<ShoppingList> lists;
|
||||
private ArrayList<List> lists;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public DisplayShoppingListsAdapter(Activity activity, ArrayList<ShoppingList> lists){
|
||||
public DisplayShoppingListsAdapter(Activity activity, ArrayList<List> lists){
|
||||
this.activity = activity;
|
||||
this.lists = lists;
|
||||
}
|
||||
@ -45,7 +45,7 @@ public class DisplayShoppingListsAdapter extends BaseAdapter {
|
||||
convertView = inflater.inflate(R.layout.display_shopping_lists_item, null);
|
||||
}
|
||||
|
||||
ShoppingList curList = lists.get(position);
|
||||
List curList = lists.get(position);
|
||||
|
||||
TextView tvListName = (TextView) convertView.findViewById(R.id.shopping_list_name);
|
||||
tvListName.setText(curList.getName());
|
||||
|
||||
@ -1,24 +1,38 @@
|
||||
package com.example.listify.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class Product implements Serializable {
|
||||
private String itemName;
|
||||
private String itemId;
|
||||
private int itemId;
|
||||
private String chainName;
|
||||
private String chainId;
|
||||
private int chainId;
|
||||
private String upc;
|
||||
private String description;
|
||||
private String department;
|
||||
private double price;
|
||||
private BigDecimal price;
|
||||
private String retrievedDate;
|
||||
private String fetchCounts;
|
||||
private String imageUrl;
|
||||
|
||||
public Product() {}
|
||||
|
||||
public Product(String itemName, String itemId, String chainName, String chainId, String upc,
|
||||
String description, String department, double price, String retrievedDate,
|
||||
public Product(String itemName, int itemId, String chainName, int chainId, String upc, String description, BigDecimal price, String imageUrl, String department) {
|
||||
this.itemName = itemName;
|
||||
this.itemId = itemId;
|
||||
this.chainName = chainName;
|
||||
this.chainId = chainId;
|
||||
this.upc = upc;
|
||||
this.description = description;
|
||||
this.price = price;
|
||||
this.imageUrl = imageUrl;
|
||||
this.department = department;
|
||||
|
||||
}
|
||||
|
||||
public Product(String itemName, int itemId, String chainName, int chainId, String upc,
|
||||
String description, String department, BigDecimal price, String retrievedDate,
|
||||
String fetchCounts, String imageUrl) {
|
||||
this.itemName = itemName;
|
||||
this.itemId = itemId;
|
||||
@ -41,11 +55,11 @@ public class Product implements Serializable {
|
||||
this.itemName = itemName;
|
||||
}
|
||||
|
||||
public String getItemId() {
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public void setItemId(String itemId) {
|
||||
public void setItemId(int itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
@ -57,11 +71,11 @@ public class Product implements Serializable {
|
||||
this.chainName = chainName;
|
||||
}
|
||||
|
||||
public String getChainId() {
|
||||
public int getChainId() {
|
||||
return chainId;
|
||||
}
|
||||
|
||||
public void setChainId(String chainId) {
|
||||
public void setChainId(int chainId) {
|
||||
this.chainId = chainId;
|
||||
}
|
||||
|
||||
@ -89,11 +103,11 @@ public class Product implements Serializable {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.example.listify.ui.lists;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -8,37 +9,62 @@ import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.amplifyframework.auth.AuthException;
|
||||
import com.example.listify.AuthManager;
|
||||
import com.example.listify.CreateListAddDialogFragment;
|
||||
import com.example.listify.CreateListDialogFragment;
|
||||
import com.example.listify.MainActivity;
|
||||
import com.example.listify.ItemDetails;
|
||||
import com.example.listify.ListPage;
|
||||
import com.example.listify.R;
|
||||
import com.example.listify.Requestor;
|
||||
import com.example.listify.SearchResults;
|
||||
import com.example.listify.SynchronousReceiver;
|
||||
import com.example.listify.adapter.DisplayShoppingListsAdapter;
|
||||
import com.example.listify.model.ShoppingList;
|
||||
import com.example.listify.data.List;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
import static com.example.listify.MainActivity.am;
|
||||
|
||||
public class ListsFragment extends Fragment implements CreateListDialogFragment.OnNewListListener {
|
||||
ArrayList<List> shoppingLists = new ArrayList<>();
|
||||
ListView shoppingListsView;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = inflater.inflate(R.layout.fragment_lists, container, false);
|
||||
|
||||
// Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar_lists);
|
||||
// ((AppCompatActivity)getActivity()).setActionBar(toolbar);
|
||||
|
||||
// Hardcode shopping lists to demonstrate displaying lists
|
||||
shoppingListsView = root.findViewById(R.id.shopping_lists);
|
||||
ShoppingList a = new ShoppingList("first list");
|
||||
ShoppingList b = new ShoppingList("Groceries");
|
||||
ShoppingList c = new ShoppingList("Expensive Stuff");
|
||||
ArrayList<ShoppingList> shoppingLists = new ArrayList<>();
|
||||
shoppingLists.add(a);
|
||||
shoppingLists.add(b);
|
||||
shoppingLists.add(c);
|
||||
|
||||
// TODO: Switch this to async
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
SynchronousReceiver<Integer[]> listIdsReceiver = new SynchronousReceiver<>();
|
||||
SynchronousReceiver<List> listReceiver = new SynchronousReceiver<>();
|
||||
|
||||
requestor.getListOfIds(List.class, listIdsReceiver, listIdsReceiver);
|
||||
try {
|
||||
Integer[] listIds = listIdsReceiver.await();
|
||||
for (int i = 0; i < listIds.length; i++) {
|
||||
requestor.getObject(Integer.toString(listIds[i]), List.class, listReceiver, listReceiver);
|
||||
shoppingLists.add(listReceiver.await());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
// Set adapter and display this users lists
|
||||
DisplayShoppingListsAdapter displayShoppingListsAdapter = new DisplayShoppingListsAdapter(getActivity(), shoppingLists);
|
||||
@ -46,7 +72,11 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment.
|
||||
shoppingListsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Toast.makeText(getContext(), "open and display " + shoppingLists.get(position).getName(), Toast.LENGTH_SHORT).show();
|
||||
Intent listPage = new Intent(getContext(), ListPage.class);
|
||||
|
||||
// Send the list ID
|
||||
listPage.putExtra("listID", shoppingLists.get(position).getItemID());
|
||||
startActivity(listPage);
|
||||
}
|
||||
});
|
||||
|
||||
@ -64,6 +94,25 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment.
|
||||
|
||||
@Override
|
||||
public void sendNewListName(String name) {
|
||||
Toast.makeText(getActivity(), String.format("%s created", name), Toast.LENGTH_LONG).show();
|
||||
|
||||
Properties configs = new Properties();
|
||||
try {
|
||||
configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json");
|
||||
} catch (IOException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||
|
||||
List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli());
|
||||
|
||||
try {
|
||||
requestor.postObject(newList, idReceiver, idReceiver);
|
||||
System.out.println(idReceiver.await());
|
||||
Toast.makeText(getContext(), String.format("%s created", name), Toast.LENGTH_LONG).show();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getContext(), "An error occurred", Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,7 +16,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:hint="@string/new_list_name"/>
|
||||
|
||||
</LinearLayout>
|
||||
49
Listify/app/src/main/res/layout/dialog_create_list_add.xml
Normal file
49
Listify/app/src/main/res/layout/dialog_create_list_add.xml
Normal file
@ -0,0 +1,49 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/create_a_new_list"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginTop="5dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_new_list_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginHorizontal="15dp"
|
||||
android:singleLine="true"
|
||||
android:hint="@string/new_list_name"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_minus"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="50dp"
|
||||
android:text="@string/minus"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_quantity"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="50dp"
|
||||
android:text="@string/_1"
|
||||
android:inputType="number"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_plus"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="50dp"
|
||||
android:text="@string/plus"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@ -32,7 +32,7 @@
|
||||
<string name="menu_lists">My Lists</string>
|
||||
<string name="title_activity_item_details">ItemDetails</string>
|
||||
<string name="add_to_list">Add to list</string>
|
||||
<string name="create_new_list">Create new list</string>
|
||||
<string name="create_new_list">Add to new list</string>
|
||||
<string name="default_product_name">Product Name</string>
|
||||
<string name="default_store">Store</string>
|
||||
<string name="default__00_00">$00.00</string>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user