Merge branch 'master' into search-filter

This commit is contained in:
Clayton Wilson 2020-10-31 20:40:19 -04:00 committed by GitHub
commit 7cb7f5f468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 857 additions and 411 deletions

View File

@ -7,26 +7,24 @@ import java.util.Map;
public class ItemSearcher implements CallHandler {
DBConnector connector;
Connection connection;
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) {
this.connector = connector;
public ItemSearcher(Connection connection, String cognitoID) {
this.connection = connection;
this.cognitoID = cognitoID;
}
@Override
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);
getItemMatches.setString(1, "%" + queryParams.get("id") + "%");
System.out.println(getItemMatches);
ResultSet searchResults = getItemMatches.executeQuery();
ItemSearch searchResultsObject = new ItemSearch(searchResults);
System.out.println(searchResultsObject);
return searchResultsObject;
}
PreparedStatement getItemMatches = connection.prepareStatement(GET_ITEM_MATCHES);
getItemMatches.setString(1, "%" + queryParams.get("id") + "%");
System.out.println(getItemMatches);
ResultSet searchResults = getItemMatches.executeQuery();
ItemSearch searchResultsObject = new ItemSearch(searchResults);
System.out.println(searchResultsObject);
return searchResultsObject;
}
}

View File

@ -33,9 +33,9 @@
android:name=".SearchResults"
android:label=""
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity android:name="com.example.listify.SplashActivity" />
<activity android:name="com.example.listify.ui.SignupPage" />
<activity android:name="com.example.listify.ui.LoginPage" />
<activity android:name="com.example.listify.ui.ForgotPasswordPage" />

View File

@ -28,7 +28,6 @@ public class AuthManager {
String password = null;
volatile boolean waiting = false;
void fetchAuthSession() throws AuthException {
waiting = true;
Amplify.Auth.fetchAuthSession(
@ -61,6 +60,13 @@ public class AuthManager {
return authSession.getUserPoolTokens().getValue().getIdToken();
}
public String getEmail() {
return email;
}
public String getPassword() {
return password;
}
public void setAuthSession(AuthSession toSet) {
authSession = (AWSCognitoAuthSession) toSet;
@ -117,7 +123,6 @@ public class AuthManager {
error -> setAuthError(error)
);
throwIfAuthError();
}
public void confirmSignUp(String confirmationCode) throws AuthException {
@ -151,13 +156,15 @@ public class AuthManager {
public void signOutUser() throws AuthException {
authSession = null;
email = null;
password = null;
waiting = true;
Amplify.Auth.signOut(this::signOutSuccess, error -> setAuthError(error));
throwIfAuthError();
}
public void changePassword(String email) throws AuthException {
this.email = email;
//this.email = email;
//waiting = true;
Amplify.Auth.resetPassword(email, result -> setAuthResetPasswordResult(result), error -> setAuthError(error));
throwIfAuthError();

View File

@ -1,5 +1,8 @@
package com.example.listify;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import com.amplifyframework.auth.AuthException;
@ -11,6 +14,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -71,6 +76,8 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
@Override
public void onClick(View v) {
closeFABMenu();
LoadingCircleDialog loadingDialog = new LoadingCircleDialog(ItemDetails.this);
loadingDialog.show();
Properties configs = new Properties();
try {
@ -81,21 +88,57 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
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);
listPickerDialog.show(getSupportFragmentManager(), "User Lists");
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Integer[] listIds = null;
try {
listIds = listIdsReceiver.await();
} catch (Exception e) {
e.printStackTrace();
}
// Create threads and add them to a list
Thread[] threads = new Thread[listIds.length];
List[] results = new List[listIds.length];
for (int i = 0; i < listIds.length; i++) {
SynchronousReceiver<List> listReceiver = new SynchronousReceiver<>();
requestor.getObject(Integer.toString(listIds[i]), List.class, listReceiver, listReceiver);
final int finalI = i;
Thread l = new Thread(new Runnable() {
@Override
public void run() {
try {
results[finalI] = listReceiver.await();
} catch (Exception e) {
e.printStackTrace();
}
}
});
threads[i] = l;
l.start();
}
shoppingLists.clear();
// Wait for each thread to finish and add results to shoppingLists
for (int i = 0; i < threads.length; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
shoppingLists.add(results[i]);
}
loadingDialog.cancel();
ListPickerDialogFragment listPickerDialog = new ListPickerDialogFragment(shoppingLists);
listPickerDialog.show(getSupportFragmentManager(), "User Lists");
}
});
t.start();
}
});
@ -157,7 +200,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
}
// Add the viewed item to the selected list
// Add the selected item to the selected list
@Override
public void sendListSelection(int selectedListIndex, int quantity) {
@ -184,6 +227,8 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
// Create a new list and add the item to it
@Override
public void sendNewListName(String name, int quantity) {
LoadingCircleDialog loadingDialog = new LoadingCircleDialog(this);
loadingDialog.show();
Properties configs = new Properties();
try {
@ -196,16 +241,34 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
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);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
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();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ItemDetails.this, String.format("%s created and item added", name), Toast.LENGTH_LONG).show();
loadingDialog.cancel();
}
});
} catch (Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ItemDetails.this, "An error occurred", Toast.LENGTH_LONG).show();
loadingDialog.cancel();
e.printStackTrace();
}
});
}
}
});
t.start();
}
}

View File

@ -10,40 +10,75 @@ import android.widget.*;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.bumptech.glide.Glide;
import com.example.listify.data.Item;
import com.example.listify.data.List;
import com.example.listify.data.ListEntry;
import org.json.JSONException;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.json.JSONException;
import static com.example.listify.MainActivity.am;
public class ListPage extends AppCompatActivity {
public class ListPage extends AppCompatActivity implements Requestor.Receiver {
ListView listView;
MyAdapter myAdapter;
Requestor requestor;
Button incrQuan;
Button decrQuan;
Button removeItem;
TextView tvTotalPrice;
ProgressBar loadingListItems;
ArrayList<String> pNames = new ArrayList<>();
ArrayList<String> pStores = new ArrayList<>();
ArrayList<String> pPrices = new ArrayList<>();
ArrayList<String> pQuantity = new ArrayList<>();
ArrayList<Integer> pImages = new ArrayList<>();
ArrayList<String> pImages = new ArrayList<>();
ArrayList<ListEntry> pListItemPair = new ArrayList<>();
Requestor requestor;
double totalPrice = 0;
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
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// Read list ID from caller
final int listID = (int) getIntent().getSerializableExtra("listID");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
listView = findViewById(R.id.listView);
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
listView.setAdapter(myAdapter);
loadingListItems = findViewById(R.id.progress_loading_list_items);
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();
try {
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
@ -51,41 +86,8 @@ public class ListPage extends AppCompatActivity {
e.printStackTrace();
}
requestor = new Requestor(am, configs.getProperty("apiKey"));
SynchronousReceiver<List> lr = new SynchronousReceiver<>();
//ListReceiver<List> lr = new ListReceiver<>();
requestor.getObject(Integer.toString(listID), List.class, lr);
List list;
try {
list = lr.await();
}
catch (Exception e) {
list = null;
}
if(list != null) {
for (ListEntry entry : list.getEntries()) {
int product = entry.getProductID();
SynchronousReceiver<Item> pr = new SynchronousReceiver<>();
requestor.getObject(Integer.toString(product), Item.class, pr, pr);
Item item;
try {
item = pr.await();
}
catch (Exception e) {
item = null;
}
if(item != null) {
pNames.add(item.getDescription());
pStores.add("Kroger");
pPrices.add(item.getPrice().toString());
pQuantity.add(entry.getQuantity().toString());
pImages.add(R.drawable.placeholder);
pListItemPair.add(entry);
}
}
}
requestor.getObject(Integer.toString(listID), List.class, this);
/*pNames.add("Half-gallon organic whole milk");
pStores.add("Kroger");
@ -104,14 +106,86 @@ public class ListPage extends AppCompatActivity {
pPrices.add("$7.00");
pQuantity.add("1");
pImages.add(R.drawable.peanutbutter);*/
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
@Override
public void acceptDelivery(Object delivered) {
List list = (List) delivered;
listView = findViewById(R.id.listView);
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
if(list != null) {
for (ListEntry entry : list.getEntries()) {
int product = entry.getProductID();
SynchronousReceiver<Item> pr = new SynchronousReceiver<>();
requestor.getObject(Integer.toString(product), Item.class, pr, pr);
Item item;
try {
item = pr.await();
}
catch (Exception e) {
item = null;
}
if(item != null) {
if(!totalPriceByStore.containsKey("Kroger")) {
totalPriceByStore.put("Kroger", item.getPrice().doubleValue() * entry.getQuantity());
storeHeaderIndex.put("Kroger", pNames.size());
listView.setAdapter(myAdapter);
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());
pStores.add("Kroger");
pPrices.add(df.format(item.getPrice()));
pQuantity.add(entry.getQuantity().toString());
pImages.add(item.getImageURL());
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);
}
}
}
// Increment total price
totalPrice += (item.getPrice().doubleValue() * entry.getQuantity());
}
}
tvTotalPrice = (TextView) findViewById(R.id.total_price);
runOnUiThread(new Runnable() {
@Override
public void run() {
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
loadingListItems.setVisibility(View.GONE);
myAdapter.notifyDataSetChanged();
}
});
}
}
class MyAdapter extends ArrayAdapter<String> {
@ -120,10 +194,10 @@ public class ListPage extends AppCompatActivity {
ArrayList<String> pStores;
ArrayList<String> pPrices;
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) {
super(c, R.layout.listproduct, R.id.productView, names);
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);
context = c;
pNames = names;
pStores = stores;
@ -136,7 +210,7 @@ public class ListPage extends AppCompatActivity {
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View listproduct = layoutInflater.inflate(R.layout.listproduct, parent,false);
View listproduct = layoutInflater.inflate(R.layout.activity_listproductentry, parent,false);
decrQuan = (Button) listproduct.findViewById(R.id.buttonDecr);
incrQuan = (Button) listproduct.findViewById(R.id.buttonIncr);
@ -147,9 +221,17 @@ public class ListPage extends AppCompatActivity {
public void onClick(View v) {
int q = Integer.parseInt(pQuantity.get(position)) - 1;
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);
le.setQuantity(le.getQuantity() - 1);
pListItemPair.add(position, le);
totalPrice -= Double.parseDouble(pPrices.get(position));
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
SynchronousReceiver<Integer> synchronousenforcer = new SynchronousReceiver<>();
requestor.deleteObject(le, synchronousenforcer, synchronousenforcer);
try {
@ -176,9 +258,17 @@ public class ListPage extends AppCompatActivity {
public void onClick(View v) {
int q = Integer.parseInt(pQuantity.get(position)) + 1;
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);
le.setQuantity(le.getQuantity() + 1);
pListItemPair.add(position, le);
totalPrice += Double.parseDouble(pPrices.get(position));
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
SynchronousReceiver<Integer> synchronousenforcer = new SynchronousReceiver<>();
requestor.deleteObject(le, synchronousenforcer, synchronousenforcer);
try {
@ -203,13 +293,45 @@ public class ListPage extends AppCompatActivity {
removeItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pNames.remove(position);
pStores.remove(position);
pPrices.remove(position);
pQuantity.remove(position);
pImages.remove(position);
totalPrice -= (Double.parseDouble(pPrices.get(position)) *
Double.parseDouble(pQuantity.get(position)));
tvTotalPrice.setText(String.format("$%.2f", totalPrice));
requestor.deleteObject(pListItemPair.remove(position));
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);
pStores.remove(position);
pPrices.remove(position);
pQuantity.remove(position);
pImages.remove(position);
requestor.deleteObject(pListItemPair.remove(position));
}
listView.setAdapter(myAdapter);
}
@ -224,36 +346,33 @@ public class ListPage extends AppCompatActivity {
if(!pNames.isEmpty()) {
name.setText(pNames.get(position));
store.setText(pStores.get(position));
price.setText(pPrices.get(position));
quantity.setText(pQuantity.get(position));
image.setImageResource(pImages.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));
}
if(pImages.get(position).equals("-1")) {
image.setVisibility(View.INVISIBLE);
}
else {
Glide.with(getContext()).load(pImages.get(position)).into(image);
}
}
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);
}
}
}

View File

@ -0,0 +1,36 @@
package com.example.listify;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Window;
import android.view.WindowManager;
public class LoadingCircleDialog {
Dialog loadingDialog;
public LoadingCircleDialog(Context context) {
loadingDialog = new Dialog(context);
// Create and show a loading dialog
loadingDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
loadingDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// layout to display
loadingDialog.setContentView(R.layout.dialog_loading);
// set color transpartent
loadingDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
loadingDialog.setCancelable(false);
loadingDialog.setCanceledOnTouchOutside(false);
}
public void show() {
loadingDialog.show();
}
public void cancel() {
loadingDialog.cancel();
}
}

View File

@ -2,6 +2,7 @@ package com.example.listify;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
@ -14,12 +15,16 @@ import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.amplifyframework.auth.AuthException;
import com.example.listify.data.Item;
import com.example.listify.data.ItemSearch;
import com.example.listify.data.List;
import com.example.listify.data.ListEntry;
import com.example.listify.ui.LoginPage;
import com.google.android.material.navigation.NavigationView;
import static com.example.listify.SplashActivity.showSplash;
import org.json.JSONException;
import java.io.IOException;
import java.time.Instant;
@ -29,13 +34,30 @@ import java.util.Random;
public class MainActivity extends AppCompatActivity implements CreateListDialogFragment.OnNewListListener {
private AppBarConfiguration mAppBarConfiguration;
public static AuthManager am = new AuthManager();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(showSplash) {
showSplash = false;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MainActivity.this, SplashActivity.class);
startActivity(intent);
finish();
}
}, 1);
}
if(am.getEmail() == null) {
Intent intent = new Intent(MainActivity.this, LoginPage.class);
startActivity(intent);
}
//------------------------------Auth Testing---------------------------------------------//
@ -180,6 +202,24 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
});
}
public void onClickSignout(MenuItem m) {
m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
am.signOutUser();
Intent intent = new Intent(MainActivity.this, com.example.listify.ui.LoginPage.class);
startActivity(intent);
finish();
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
return false;
}
});
}
@Override
public void sendNewListName(String name) {
Properties configs = new Properties();

View File

@ -9,6 +9,7 @@ import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SearchView;
import com.example.listify.adapter.SearchResultsListAdapter;
import com.example.listify.data.ItemSearch;
@ -22,8 +23,8 @@ import java.util.Properties;
import static com.example.listify.MainActivity.am;
public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener {
private ListView listView;
public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener, Requestor.Receiver {
private ProgressBar loadingSearch;
private SearchResultsListAdapter searchResultsListAdapter;
private List<Product> resultsProductList = new ArrayList<>();
private List<Product> resultsProductListSorted = new ArrayList<>();
@ -51,6 +52,8 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
loadingSearch = (ProgressBar) findViewById(R.id.progress_loading_search);
// Back button closes this activity and returns to previous activity (MainActivity)
ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton);
backButton.setOnClickListener(new View.OnClickListener() {
@ -81,7 +84,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
}
});
listView = (ListView) findViewById(R.id.search_results_list);
ListView listView = (ListView) findViewById(R.id.search_results_list);
searchResultsListAdapter = new SearchResultsListAdapter(this, resultsProductListSorted);
listView.setAdapter(searchResultsListAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@ -99,6 +102,15 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// Show progress bar
loadingSearch.setVisibility(View.VISIBLE);
// Clear the old search results
resultsProductList.clear();
// Clear old search results from the view
resultsProductListSorted.clear();
searchResultsListAdapter.notifyDataSetChanged();
doSearch(query);
return false;
}
@ -151,12 +163,8 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
sortDialog.show(getSupportFragmentManager(), "Sort");
}
});
}
// Override default phone back button to add animation
@Override
public void onBackPressed() {
@ -165,10 +173,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
}
private void doSearch(String query) {
// Clear the old search results
resultsProductList.clear();
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json");
@ -177,34 +181,10 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
}
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
for (int i = 0; i < resultsProductList.size(); i++) {
if (!stores.contains(resultsProductList.get(i).getChainName())) {
stores.add(resultsProductList.get(i).getChainName());
}
}
// Add all results to the sorted list
resultsProductListSorted.addAll(resultsProductList);
// Apply selected sorting to the list
sortResults();
requestor.getObject(query, ItemSearch.class, this);
}
// TODO: Scroll the list back to the top when a search, sort, or filter is performed
// Sorts the search results
private void sortResults() {
// Reset the filtered list
@ -232,7 +212,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
});
break;
// TODO: May need to change this depending on if price is stored as a string or a double
case 2:
resultsProductListSorted.sort(new Comparator<Product>() {
@Override
@ -287,8 +266,8 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
resultsProductListSorted.clear();
resultsProductListSorted.addAll(temp);
}
// Filter out products that don't fit price restraints
// Filter out products that don't fit price restraints
ArrayList<Product> temp = new ArrayList<>();
resultsProductListSorted.forEach(product -> {
if (product.getPrice().doubleValue() >= this.minPrice &&
@ -298,7 +277,56 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
});
resultsProductListSorted.clear();
resultsProductListSorted.addAll(temp);
}
searchResultsListAdapter.notifyDataSetChanged();
// This is called after the search results come back from the server
// TODO: Display a "no results" message if nothing is found when searching
@Override
public void acceptDelivery(Object delivered) {
ItemSearch results = (ItemSearch) delivered;
try {
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
for (int i = 0; i < resultsProductList.size(); i++) {
if (!stores.contains(resultsProductList.get(i).getChainName())) {
stores.add(resultsProductList.get(i).getChainName());
}
}
// Add all results to the sorted list
resultsProductListSorted.addAll(resultsProductList);
// Apply selected sorting to the list
sortResults();
// Updates the list of search results. Runs on the main UI thread since other threads are
// not allowed to change UI elements
runOnUiThread(new Runnable() {
@Override
public void run() {
searchResultsListAdapter.notifyDataSetChanged();
// Hide progress bar
loadingSearch.setVisibility(View.GONE);
}
});
}
}

View File

@ -0,0 +1,28 @@
package com.example.listify;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
public static boolean showSplash = true;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
showSplash = false;
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, 3000);
}
}

View File

@ -1,70 +0,0 @@
package com.example.listify.ui;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.listify.AuthManager;
import com.example.listify.R;
import com.example.listify.MainActivity;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDialog;
import androidx.appcompat.app.AppCompatDialogFragment;
public class CodePage extends AppCompatDialogFragment {
private EditText ediTextCode;
private CodeDialogListener listener;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.activity_code, null);
builder.setView(view)
.setTitle("Verification code")
.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String code = ediTextCode.getText().toString();
listener.sendCode("" + code + "", false);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String code = ediTextCode.getText().toString();
listener.sendCode("" + code + "", true);
}
});
ediTextCode = view.findViewById(R.id.editTextCode);
return builder.create();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
listener = (CodeDialogListener) context;
} catch (ClassCastException e) {
throw new ClassCastException("CodeDialogListener not implemented.");
}
}
public interface CodeDialogListener {
void sendCode(String code, boolean cancel);
}
}

View File

@ -1,5 +1,7 @@
package com.example.listify.ui;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@ -8,31 +10,46 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.listify.MainActivity;
import com.example.listify.R;
import static com.example.listify.MainActivity.am;
import androidx.appcompat.app.AppCompatActivity;
public class ForgotPasswordPage extends AppCompatActivity implements CodePage.CodeDialogListener {
public class ForgotPasswordPage extends AppCompatActivity {
private Button button1; //Code page button
String email;
String newPassword;
String confirmNewPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forgotpswd);
if(am.getEmail() != null) {
Intent intent = new Intent(ForgotPasswordPage.this, MainActivity.class);
startActivity(intent);
}
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText emailText = (EditText) findViewById(R.id.editTextTextEmailAddress2);
EditText newPasswordText = (EditText) findViewById(R.id.editTextTextPassword2);
EditText emailText = (EditText) findViewById(R.id.editTextTextEmailAddress);
EditText newPasswordText = (EditText) findViewById(R.id.editTextTextPassword);
EditText confirmNewPasswordText = (EditText) findViewById(R.id.editTextTextPassword2);
email = emailText.getText().toString();
newPassword = newPasswordText.getText().toString();
confirmNewPassword = confirmNewPasswordText.getText().toString();
if(!newPassword.equals(confirmNewPassword)) {
TextView invalidCred = findViewById(R.id.textView6);
invalidCred.setText("\"Confirm New Password\" does not match \"New Password\".");
return;
}
try {
am.changePassword(email);
@ -41,29 +58,37 @@ public class ForgotPasswordPage extends AppCompatActivity implements CodePage.Co
Log.i("Authentication", e.toString());
TextView invalidCred = findViewById(R.id.textView6);
invalidCred.setText("Password criteria not met. Please try again.");
return;
}
openDialog();
View codeView = getLayoutInflater().inflate(R.layout.activity_code, null);
AlertDialog.Builder builder = new AlertDialog.Builder(ForgotPasswordPage.this);
builder.setView(codeView);
builder.setTitle("Verification code");
builder.setMessage("Please enter the 6-digit verification code sent to your email.");
builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText codeText = (EditText) codeView.findViewById(R.id.editTextCode);
String code = codeText.getText().toString();
try {
am.confirmPasswordReset(newPassword, code);
Intent intent = new Intent(ForgotPasswordPage.this, LoginPage.class);
startActivity(intent);
finish();
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
public void openDialog() {
CodePage codePage = new CodePage();
codePage.show(getSupportFragmentManager(), "Verification code");
}
@Override
public void sendCode(String code, boolean cancel) {
if(!cancel) {
try {
am.confirmPasswordReset(newPassword, code);
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
}
Intent intent = new Intent(ForgotPasswordPage.this, LoginPage.class);
startActivity(intent);
}
}

View File

@ -25,6 +25,11 @@ public class LoginPage extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if(am.getEmail() != null) {
Intent intent = new Intent(LoginPage.this, MainActivity.class);
startActivity(intent);
}
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
@ -57,6 +62,7 @@ public class LoginPage extends AppCompatActivity {
am.signIn(email, password);
Intent intent = new Intent(LoginPage.this, MainActivity.class);
startActivity(intent);
finish();
}
catch(Exception e) {
Log.i("Authentication", e.toString());

View File

@ -1,5 +1,7 @@
package com.example.listify.ui;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@ -11,19 +13,35 @@ import android.widget.TextView;
import com.example.listify.R;
import com.example.listify.AuthManager;
import com.example.listify.MainActivity;
import com.example.listify.Requestor;
import org.json.JSONException;
import java.io.IOException;
import java.util.Properties;
import static com.example.listify.MainActivity.am;
import androidx.appcompat.app.AppCompatActivity;
public class SignupPage extends AppCompatActivity implements CodePage.CodeDialogListener {
public class SignupPage extends AppCompatActivity {
private Button button1; //Log in page button
private Button button2; //Sign up button
String email;
String password;
String confirmPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
if(am.getEmail() != null) {
Intent intent = new Intent(SignupPage.this, MainActivity.class);
startActivity(intent);
}
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
@ -41,9 +59,9 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
EditText passwordText = (EditText) findViewById(R.id.editTextTextPassword);
EditText confirmPasswordText = (EditText) findViewById(R.id.editTextTextPassword2);
String email = emailText.getText().toString();
String password = passwordText.getText().toString();
String confirmPassword = confirmPasswordText.getText().toString();
email = emailText.getText().toString();
password = passwordText.getText().toString();
confirmPassword = confirmPasswordText.getText().toString();
if(!password.equals(confirmPassword)) {
TextView invalidCred = findViewById(R.id.textView3);
@ -61,27 +79,35 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
return;
}
openDialog();
View codeView = getLayoutInflater().inflate(R.layout.activity_code, null);
AlertDialog.Builder builder = new AlertDialog.Builder(SignupPage.this);
builder.setView(codeView);
builder.setTitle("Verification code");
builder.setMessage("Please enter the 6-digit verification code sent to your email.");
builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText codeText = (EditText) codeView.findViewById(R.id.editTextCode);
String code = codeText.getText().toString();
try {
am.confirmSignUp(code);
am.signIn(email, password);
Intent intent = new Intent(SignupPage.this, MainActivity.class);
startActivity(intent);
finish();
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
public void openDialog() {
CodePage codePage = new CodePage();
codePage.show(getSupportFragmentManager(), "Verification code");
}
@Override
public void sendCode(String code, boolean cancel) {
if(!cancel) {
try {
am.confirmSignUp(code);
Intent intent = new Intent(SignupPage.this, MainActivity.class);
startActivity(intent);
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
}
}
}

View File

@ -1,5 +1,7 @@
package com.example.listify.ui.home;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@ -8,6 +10,8 @@ import android.widget.Button;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
@ -25,41 +29,51 @@ import java.io.IOException;
import java.util.Properties;
public class HomeFragment extends Fragment {
private Button toLoginPage;
private Button toListPage;
private Button toDeleteAccountPage;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_home, container, false);
toLoginPage = (Button) root.findViewById(R.id.button1);
toLoginPage.setOnClickListener(new View.OnClickListener() {
toDeleteAccountPage = (Button) root.findViewById(R.id.button);
toDeleteAccountPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), com.example.listify.ui.LoginPage.class);
startActivity(intent);
}
});
toListPage = (Button) root.findViewById(R.id.button2);
toListPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Intent intent = new Intent(HomeFragment.this.getActivity(), com.example.listify.ListPage.class);
//startActivity(intent);
try {
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json");
} catch (IOException | JSONException e) {
e.printStackTrace();
View passwordView = getLayoutInflater().inflate(R.layout.activity_code, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(passwordView);
builder.setTitle("Account deletion verification");
builder.setMessage("Are you sure you want to delete your account? If so, enter your password below and hit \"Yes\".");
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText passwordText = (EditText) passwordView.findViewById(R.id.editTextCode);
String password = passwordText.getText().toString();
if(password.equals(am.getPassword())) {
try {
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"));
am.deleteUser(requestor);
Intent intent = new Intent(getActivity(), com.example.listify.ui.LoginPage.class);
startActivity(intent);
getActivity().finish();
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
}
}
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
am.deleteUser(requestor);
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});

View File

@ -1,15 +1,22 @@
package com.example.listify.ui.lists;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.ListFragment;
import com.amplifyframework.auth.AuthException;
import com.example.listify.AuthManager;
@ -17,6 +24,7 @@ import com.example.listify.CreateListAddDialogFragment;
import com.example.listify.CreateListDialogFragment;
import com.example.listify.ItemDetails;
import com.example.listify.ListPage;
import com.example.listify.LoadingCircleDialog;
import com.example.listify.R;
import com.example.listify.Requestor;
import com.example.listify.SearchResults;
@ -34,16 +42,20 @@ import java.util.Properties;
import static com.example.listify.MainActivity.am;
public class ListsFragment extends Fragment implements CreateListDialogFragment.OnNewListListener {
public class ListsFragment extends Fragment implements CreateListDialogFragment.OnNewListListener, Requestor.Receiver {
ArrayList<List> shoppingLists = new ArrayList<>();
DisplayShoppingListsAdapter displayShoppingListsAdapter;
Requestor requestor;
ListView shoppingListsView;
ProgressBar loadingLists;
int resultsIndex;
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_lists, container, false);
shoppingListsView = root.findViewById(R.id.shopping_lists);
loadingLists = (ProgressBar) root.findViewById(R.id.progress_loading_lists);
loadingLists.setVisibility(View.VISIBLE);
// TODO: Switch this to async
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json");
@ -51,36 +63,13 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment.
e.printStackTrace();
}
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
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();
}
final Requestor.Receiver<Integer[]> recv = this;
requestor.getListOfIds(List.class, recv, null);
// Set adapter and display this users lists
displayShoppingListsAdapter = new DisplayShoppingListsAdapter(getActivity(), shoppingLists);
shoppingListsView.setAdapter(displayShoppingListsAdapter);
shoppingListsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent listPage = new Intent(getContext(), ListPage.class);
// Send the list ID
listPage.putExtra("listID", shoppingLists.get(position).getItemID());
startActivity(listPage);
}
});
FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.new_list_fab);
Fragment thisFragment = this;
fab.setOnClickListener(new View.OnClickListener() {
@ -97,6 +86,8 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment.
@Override
public void sendNewListName(String name) {
LoadingCircleDialog loadingDialog = new LoadingCircleDialog(getActivity());
loadingDialog.show();
Properties configs = new Properties();
try {
@ -111,13 +102,95 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment.
try {
requestor.postObject(newList, idReceiver, idReceiver);
newList.setItemID(idReceiver.await());
shoppingLists.add(newList);
displayShoppingListsAdapter.notifyDataSetChanged();
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();
}
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
newList.setItemID(idReceiver.await());
} catch (Exception e) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), "An error occurred", Toast.LENGTH_LONG).show();
loadingDialog.cancel();
}
});
e.printStackTrace();
}
shoppingLists.add(newList);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
displayShoppingListsAdapter.notifyDataSetChanged();
loadingDialog.cancel();
Toast.makeText(getContext(), String.format("%s created", name), Toast.LENGTH_LONG).show();
}
});
}
});
t.start();
}
@Override
public void acceptDelivery(Object delivered) {
Integer[] listIds = (Integer[]) delivered;
// Create threads and add them to a list
Thread[] threads = new Thread[listIds.length];
List[] results = new List[listIds.length];
for (int i = 0; i < listIds.length; i++) {
SynchronousReceiver<List> listReceiver = new SynchronousReceiver<>();
requestor.getObject(Integer.toString(listIds[i]), List.class, listReceiver, listReceiver);
final int finalI = i;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
results[finalI] = listReceiver.await();
} catch (Exception e) {
e.printStackTrace();
}
}
});
threads[i] = t;
t.start();
}
// Wait for each thread to finish and add results to shoppingLists
for (int i = 0; i < threads.length; i++) {
try {
threads[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
shoppingLists.add(results[i]);
}
// Set adapter and display this users lists
displayShoppingListsAdapter = new DisplayShoppingListsAdapter(getActivity(), shoppingLists);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
shoppingListsView.setAdapter(displayShoppingListsAdapter);
shoppingListsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent listPage = new Intent(getContext(), ListPage.class);
// Send the list ID
listPage.putExtra("listID", shoppingLists.get(position).getItemID());
startActivity(listPage);
}
});
loadingLists.setVisibility(View.GONE);
}
});
}
}

View File

@ -11,8 +11,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Code"
android:inputType="textPersonName"
android:hint=""
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@ -9,51 +9,64 @@
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:layout_marginTop="51dp"
android:text="Submit"
app:layout_constraintEnd_toStartOf="@+id/textView6"
app:layout_constraintStart_toStartOf="@+id/textView6"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword2" />
<EditText
android:id="@+id/editTextTextEmailAddress2"
android:id="@+id/editTextTextEmailAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="295dp"
android:layout_marginTop="263dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
app:layout_constraintStart_toStartOf="@+id/editTextTextPassword2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextTextPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:ems="10"
android:hint="New Password"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="@+id/editTextTextEmailAddress"
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress" />
<EditText
android:id="@+id/editTextTextPassword2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:layout_marginTop="35dp"
android:ems="10"
android:hint="New Password"
android:hint="Confirm New Password"
android:inputType="textPassword"
app:layout_constraintEnd_toStartOf="@+id/textView6"
app:layout_constraintStart_toStartOf="@+id/textView6"
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress2" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="34dp"
android:layout_marginEnd="2dp"
android:text="Please enter your email address."
app:layout_constraintBottom_toTopOf="@+id/editTextTextEmailAddress2"
app:layout_constraintEnd_toEndOf="@+id/editTextTextEmailAddress2" />
app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/button1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="46dp"
android:layout_marginEnd="2dp"
android:text="Please enter your email address."
app:layout_constraintBottom_toTopOf="@+id/editTextTextEmailAddress"
app:layout_constraintEnd_toEndOf="@+id/editTextTextEmailAddress" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,14 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progress_loading_list_items"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="gone"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView">
android:id="@+id/listView"
android:paddingBottom="20dp">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="@color/colorPrimaryDark">
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="16sp"
android:text="Total: "/>
<TextView
android:id="@+id/total_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="16sp"
android:text="@string/default__00_00"/>
</LinearLayout>
</RelativeLayout>

View File

@ -33,7 +33,7 @@
android:layout_marginTop="23dp"
android:ems="10"
android:hint="Password"
android:inputType="textPersonName"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="@+id/editTextTextEmailAddress"
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress" />

View File

@ -12,6 +12,16 @@
tools:context=".SearchResults"
tools:showIn="@layout/activity_search_results">
<ProgressBar
android:id="@+id/progress_loading_search"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="gone"/>
<ListView
android:id="@+id/search_results_list"
android:layout_width="fill_parent"

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null">
<ProgressBar
android:id="@+id/progress_loading_lists"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="visible"/>
</RelativeLayout>

View File

@ -7,42 +7,13 @@
tools:context=".ui.home.HomeFragment">
<Button
android:id="@+id/button1"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginEnd="25dp"
android:text="Log in"
app:layout_constraintBottom_toTopOf="@+id/button2"
app:layout_constraintEnd_toEndOf="@+id/button2" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="148dp"
android:text="Delete Account"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="29dp"
android:text="Kroger"
app:layout_constraintBottom_toTopOf="@+id/button1"
app:layout_constraintStart_toStartOf="@+id/button1" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="31dp"
android:text="Search these stores:"
app:layout_constraintBottom_toTopOf="@+id/switch1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -12,6 +12,16 @@
tools:context=".ui.lists.ListsFragment"
tools:showIn="@layout/fragment_lists">
<ProgressBar
android:id="@+id/progress_loading_lists"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:visibility="gone"/>
<ListView
android:id="@+id/shopping_lists"
android:layout_width="fill_parent"

View File

@ -8,22 +8,21 @@
android:id="@+id/nav_home"
android:icon="@drawable/ic_menu_camera"
android:title="@string/menu_home" />
<!-- <item-->
<!-- android:id="@+id/nav_gallery"-->
<!-- android:icon="@drawable/ic_menu_gallery"-->
<!-- android:title="@string/menu_gallery" />-->
<!-- <item-->
<!-- android:id="@+id/nav_slideshow"-->
<!-- android:icon="@drawable/ic_menu_slideshow"-->
<!-- android:title="@string/menu_slideshow" />-->
<!-- <item-->
<!-- android:id="@+id/nav_gallery"-->
<!-- android:icon="@drawable/ic_menu_gallery"-->
<!-- android:title="@string/menu_gallery" />-->
<!-- <item-->
<!-- android:id="@+id/nav_slideshow"-->
<!-- android:icon="@drawable/ic_menu_slideshow"-->
<!-- android:title="@string/menu_slideshow" />-->
<item
android:id="@+id/nav_lists"
android:icon="@drawable/ic_baseline_list_alt_28"
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"/>
android:id="@+id/nav_logout"
android:title="Sign out"
android:onClick="onClickSignout" />
</group>
</menu>

View File

@ -7,7 +7,7 @@
<string name="nav_header_desc">Navigation header</string>
<string name="action_settings">Settings</string>
<string name="menu_home">Home</string>
<string name="menu_home">Profile</string>
<string name="menu_gallery">Gallery</string>
<string name="menu_slideshow">Slideshow</string>