From e98d2a6a937f132462d35216b9fd7f1e151651f1 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 18 Oct 2020 19:50:00 -0400 Subject: [PATCH 01/20] Search activity price seekbar layout --- Listify/app/build.gradle | 2 +- .../example/listify/SortDialogFragment.java | 34 +++++++++++++++ .../app/src/main/res/layout/dialog_sort.xml | 43 ++++++++++++++++++- 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/Listify/app/build.gradle b/Listify/app/build.gradle index 0ad5dc3..d90a79b 100644 --- a/Listify/app/build.gradle +++ b/Listify/app/build.gradle @@ -51,5 +51,5 @@ dependencies { implementation 'com.github.bumptech.glide:glide:4.11.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' implementation 'com.squareup.okhttp3:okhttp:4.8.1' - + implementation 'com.crystal:crystalrangeseekbar:1.1.3' } \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java index ac4713f..d94f120 100644 --- a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java +++ b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java @@ -10,9 +10,18 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ImageButton; import android.widget.Spinner; +import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; + +import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarChangeListener; +import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarFinalValueListener; +import com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar; + +import org.w3c.dom.Text; + import java.util.ArrayList; @@ -136,6 +145,31 @@ public class SortDialogFragment extends DialogFragment { sortDirectionButton.setEnabled(false); } + // Set up the seekbar for price + final CrystalRangeSeekbar priceSeekbar = (CrystalRangeSeekbar) root.findViewById(R.id.price_range_seekbar); + final TextView tvMin = (TextView) root.findViewById(R.id.tv_min_price); + final TextView tvMax = (TextView) root.findViewById(R.id.tv_max_price); + + priceSeekbar.setMaxValue(367); + + // Update price display + priceSeekbar.setOnRangeSeekbarChangeListener(new OnRangeSeekbarChangeListener() { + @Override + public void valueChanged(Number minValue, Number maxValue) { + tvMin.setText(String.format("$%.2f", minValue.doubleValue())); + tvMax.setText(String.format("$%.2f", maxValue.doubleValue())); + } + }); + + // Save price values when user finishes moving the slider + priceSeekbar.setOnRangeSeekbarFinalValueListener(new OnRangeSeekbarFinalValueListener() { + @Override + public void finalValue(Number minValue, Number maxValue) { + System.out.println(String.format("Min: $%.2f, Max: $%.2f", minValue.doubleValue(), maxValue.doubleValue())); + } + }); + + return builder.create(); } diff --git a/Listify/app/src/main/res/layout/dialog_sort.xml b/Listify/app/src/main/res/layout/dialog_sort.xml index 38e5002..6a6d5b1 100644 --- a/Listify/app/src/main/res/layout/dialog_sort.xml +++ b/Listify/app/src/main/res/layout/dialog_sort.xml @@ -31,7 +31,7 @@ + + + + + + + + + + + + + \ No newline at end of file From 4e7b180fe086af6f34a8735b4f9aa0ff7cfd73d3 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Tue, 20 Oct 2020 05:45:33 -0400 Subject: [PATCH 02/20] Async load search results --- .../com/example/listify/SearchResults.java | 77 ++++++++++++------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index 0b312c6..3841f4a 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -22,7 +22,7 @@ import java.util.Properties; import static com.example.listify.MainActivity.am; -public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener { +public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener, Requestor.Receiver { private ListView listView; private SearchResultsListAdapter searchResultsListAdapter; private List resultsProductList = new ArrayList<>(); @@ -148,32 +148,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme } Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); - - SynchronousReceiver 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); } // Sorts the search results @@ -258,6 +233,52 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme resultsProductListSorted.addAll(temp); } - searchResultsListAdapter.notifyDataSetChanged(); + // 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(); + } + }); + } + + // 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(); } } \ No newline at end of file From 4757ba2ddf15041af7d48c32f8d07067444e4924 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Tue, 20 Oct 2020 07:28:58 -0400 Subject: [PATCH 03/20] Create new thread on search and show progress bar --- .../com/example/listify/SearchResults.java | 38 ++++++++++++++----- .../res/layout/content_search_results.xml | 10 +++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index 3841f4a..37f78cb 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -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; @@ -23,7 +24,7 @@ import java.util.Properties; import static com.example.listify.MainActivity.am; public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener, Requestor.Receiver { - private ListView listView; + private ProgressBar loadingSearch; private SearchResultsListAdapter searchResultsListAdapter; private List resultsProductList = new ArrayList<>(); private List resultsProductListSorted = new ArrayList<>(); @@ -31,6 +32,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme private int storeSelection; private int sortMode; private boolean descending; + boolean doneLoading = false; @Override public void sendSort(int storeSelection, int sortMode, boolean descending) { @@ -47,6 +49,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() { @@ -77,7 +81,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() { @@ -96,7 +100,15 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { - doSearch(query); + // Show progress bar + loadingSearch.setVisibility(View.VISIBLE); + Thread t = new Thread(new Runnable() { + @Override + public void run() { + doSearch(query); + } + }); + t.start(); return false; } @@ -122,12 +134,8 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme sortDialog.show(getSupportFragmentManager(), "Sort"); } }); - } - - - // Override default phone back button to add animation @Override public void onBackPressed() { @@ -136,10 +144,13 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme } private void doSearch(String query) { - // Clear the old search results resultsProductList.clear(); + // Clear old search results from the view + resultsProductListSorted.clear(); + searchResultsListAdapter.notifyDataSetChanged(); + Properties configs = new Properties(); try { configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); @@ -178,7 +189,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() { @Override @@ -238,7 +248,13 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme runOnUiThread(new Runnable() { @Override public void run() { - searchResultsListAdapter.notifyDataSetChanged(); + if (doneLoading) { + doneLoading = false; + searchResultsListAdapter.notifyDataSetChanged(); + + // Hide progress bar + loadingSearch.setVisibility(View.GONE); + } } }); } @@ -280,5 +296,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme // Apply selected sorting to the list sortResults(); + + doneLoading = true; } } \ No newline at end of file diff --git a/Listify/app/src/main/res/layout/content_search_results.xml b/Listify/app/src/main/res/layout/content_search_results.xml index cd08592..51ff208 100644 --- a/Listify/app/src/main/res/layout/content_search_results.xml +++ b/Listify/app/src/main/res/layout/content_search_results.xml @@ -12,6 +12,16 @@ tools:context=".SearchResults" tools:showIn="@layout/activity_search_results"> + + Date: Thu, 22 Oct 2020 16:28:00 -0400 Subject: [PATCH 04/20] async search bug fixes --- .../com/example/listify/SearchResults.java | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index 37f78cb..6b62c74 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -32,7 +32,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme private int storeSelection; private int sortMode; private boolean descending; - boolean doneLoading = false; @Override public void sendSort(int storeSelection, int sortMode, boolean descending) { @@ -102,6 +101,14 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme 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(); + Thread t = new Thread(new Runnable() { @Override public void run() { @@ -144,13 +151,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme } private void doSearch(String query) { - // Clear the old search results - resultsProductList.clear(); - - // Clear old search results from the view - resultsProductListSorted.clear(); - searchResultsListAdapter.notifyDataSetChanged(); - Properties configs = new Properties(); try { configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); @@ -242,21 +242,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme resultsProductListSorted.clear(); resultsProductListSorted.addAll(temp); } - - // 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() { - if (doneLoading) { - doneLoading = false; - searchResultsListAdapter.notifyDataSetChanged(); - - // Hide progress bar - loadingSearch.setVisibility(View.GONE); - } - } - }); } // This is called after the search results come back from the server @@ -297,6 +282,17 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme // Apply selected sorting to the list sortResults(); - doneLoading = true; + // 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); + + } + }); } } \ No newline at end of file From ec28e8babca7f2aca1f4009a7812bb72e0af3032 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Thu, 22 Oct 2020 18:06:10 -0400 Subject: [PATCH 05/20] Async loading lists page --- .../listify/ui/lists/ListsFragment.java | 77 ++++++++++++------- .../src/main/res/layout/fragment_lists.xml | 10 +++ 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java index c7029ba..e542c0a 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java @@ -7,9 +7,11 @@ import android.view.ViewGroup; import android.view.LayoutInflater; 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; @@ -34,16 +36,19 @@ 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 shoppingLists = new ArrayList<>(); DisplayShoppingListsAdapter displayShoppingListsAdapter; + Requestor requestor; ListView shoppingListsView; + ProgressBar loadingLists; 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,35 +56,18 @@ 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 listIdsReceiver = new SynchronousReceiver<>(); - SynchronousReceiver 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 = new DisplayShoppingListsAdapter(getActivity(), shoppingLists); - shoppingListsView.setAdapter(displayShoppingListsAdapter); - shoppingListsView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + final Requestor.Receiver recv = this; + Thread t = new Thread(new Runnable() { @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); + public void run() { + requestor.getListOfIds(List.class, recv, null); } }); + t.start(); + FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.new_list_fab); Fragment thisFragment = this; @@ -120,4 +108,41 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. e.printStackTrace(); } } + + @Override + public void acceptDelivery(Object delivered) { + SynchronousReceiver listReceiver = new SynchronousReceiver<>(); + Integer[] listIds = (Integer[]) delivered; + 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 = 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); + } + }); + + } } \ No newline at end of file diff --git a/Listify/app/src/main/res/layout/fragment_lists.xml b/Listify/app/src/main/res/layout/fragment_lists.xml index 0793341..e595fb9 100644 --- a/Listify/app/src/main/res/layout/fragment_lists.xml +++ b/Listify/app/src/main/res/layout/fragment_lists.xml @@ -12,6 +12,16 @@ tools:context=".ui.lists.ListsFragment" tools:showIn="@layout/fragment_lists"> + + Date: Thu, 22 Oct 2020 18:36:00 -0400 Subject: [PATCH 06/20] Async loading list products --- .../java/com/example/listify/ListPage.java | 78 ++++++++++--------- .../app/src/main/res/layout/activity_list.xml | 14 +++- 2 files changed, 55 insertions(+), 37 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index f81c481..e05d1f6 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -21,13 +21,14 @@ import java.util.Properties; import static com.example.listify.MainActivity.am; -public class ListPage extends AppCompatActivity { +public class ListPage extends AppCompatActivity implements Requestor.Receiver { ListView listView; MyAdapter myAdapter; Button incrQuan; Button decrQuan; Button removeItem; + ProgressBar loadingListItems; ArrayList pNames = new ArrayList<>(); ArrayList pStores = new ArrayList<>(); @@ -39,11 +40,23 @@ public class ListPage extends AppCompatActivity { Requestor requestor; + // 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); + Properties configs = new Properties(); try { configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); @@ -51,18 +64,31 @@ public class ListPage extends AppCompatActivity { e.printStackTrace(); } requestor = new Requestor(am, configs.getProperty("apiKey")); - SynchronousReceiver lr = new SynchronousReceiver<>(); //ListReceiver lr = new ListReceiver<>(); - requestor.getObject(Integer.toString(listID), List.class, lr); + requestor.getObject(Integer.toString(listID), List.class, this); - List list; + /*pNames.add("Half-gallon organic whole milk"); + pStores.add("Kroger"); + pPrices.add("$5.00"); + pQuantity.add("1"); + pImages.add(R.drawable.milk); - try { - list = lr.await(); - } - catch (Exception e) { - list = null; - } + pNames.add("5-bunch medium bananas"); + pStores.add("Kroger"); + pPrices.add("$3.00"); + pQuantity.add("1"); + pImages.add(R.drawable.bananas); + + pNames.add("JIF 40-oz creamy peanut butter"); + pStores.add("Kroger"); + pPrices.add("$7.00"); + pQuantity.add("1"); + pImages.add(R.drawable.peanutbutter);*/ + } + + @Override + public void acceptDelivery(Object delivered) { + List list = (List) delivered; if(list != null) { for (ListEntry entry : list.getEntries()) { @@ -87,31 +113,13 @@ public class ListPage extends AppCompatActivity { } } - /*pNames.add("Half-gallon organic whole milk"); - pStores.add("Kroger"); - pPrices.add("$5.00"); - pQuantity.add("1"); - pImages.add(R.drawable.milk); - - pNames.add("5-bunch medium bananas"); - pStores.add("Kroger"); - pPrices.add("$3.00"); - pQuantity.add("1"); - pImages.add(R.drawable.bananas); - - pNames.add("JIF 40-oz creamy peanut butter"); - pStores.add("Kroger"); - pPrices.add("$7.00"); - pQuantity.add("1"); - pImages.add(R.drawable.peanutbutter);*/ - - 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); + runOnUiThread(new Runnable() { + @Override + public void run() { + loadingListItems.setVisibility(View.GONE); + myAdapter.notifyDataSetChanged(); + } + }); } class MyAdapter extends ArrayAdapter { diff --git a/Listify/app/src/main/res/layout/activity_list.xml b/Listify/app/src/main/res/layout/activity_list.xml index 65c12f4..97ce5b1 100644 --- a/Listify/app/src/main/res/layout/activity_list.xml +++ b/Listify/app/src/main/res/layout/activity_list.xml @@ -1,9 +1,19 @@ - + + - \ No newline at end of file + \ No newline at end of file From 8604d98e6348da8eb45fe92976291642c76dafeb Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Thu, 22 Oct 2020 23:09:57 -0400 Subject: [PATCH 07/20] Async creating lists and adding items --- .../java/com/example/listify/ItemDetails.java | 96 ++++++++++++++----- .../listify/ui/lists/ListsFragment.java | 49 +++++++++- .../src/main/res/layout/dialog_loading.xml | 16 ++++ .../main/res/menu/activity_main_drawer.xml | 10 +- 4 files changed, 140 insertions(+), 31 deletions(-) create mode 100644 Listify/app/src/main/res/layout/dialog_loading.xml diff --git a/Listify/app/src/main/java/com/example/listify/ItemDetails.java b/Listify/app/src/main/java/com/example/listify/ItemDetails.java index 415d1a4..15f0767 100644 --- a/Listify/app/src/main/java/com/example/listify/ItemDetails.java +++ b/Listify/app/src/main/java/com/example/listify/ItemDetails.java @@ -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,17 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr @Override public void onClick(View v) { closeFABMenu(); + // Create and show a loading dialog + Dialog loadingDialog = new Dialog(ItemDetails.this); + 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); + loadingDialog.show(); Properties configs = new Properties(); try { @@ -82,20 +98,27 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver listIdsReceiver = new SynchronousReceiver<>(); SynchronousReceiver 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() { + 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(); + } + + loadingDialog.cancel(); + ListPickerDialogFragment listPickerDialog = new ListPickerDialogFragment(shoppingLists); + listPickerDialog.show(getSupportFragmentManager(), "User Lists"); + } + }); + t.start(); } }); @@ -184,6 +207,17 @@ 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) { + // Create and show a loading dialog + Dialog loadingDialog = new Dialog(this); + 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); + loadingDialog.show(); Properties configs = new Properties(); try { @@ -196,16 +230,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(); } } \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java index e542c0a..6c1c2c1 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java @@ -1,10 +1,15 @@ 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; @@ -85,6 +90,17 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. @Override public void sendNewListName(String name) { + // Create and show a loading dialog + Dialog loadingDialog = new Dialog(getActivity()); + 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); + loadingDialog.show(); Properties configs = new Properties(); try { @@ -99,14 +115,39 @@ 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 diff --git a/Listify/app/src/main/res/layout/dialog_loading.xml b/Listify/app/src/main/res/layout/dialog_loading.xml new file mode 100644 index 0000000..a51c2a1 --- /dev/null +++ b/Listify/app/src/main/res/layout/dialog_loading.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/Listify/app/src/main/res/menu/activity_main_drawer.xml b/Listify/app/src/main/res/menu/activity_main_drawer.xml index 93efe47..f2e00a0 100644 --- a/Listify/app/src/main/res/menu/activity_main_drawer.xml +++ b/Listify/app/src/main/res/menu/activity_main_drawer.xml @@ -20,10 +20,10 @@ android:id="@+id/nav_lists" android:icon="@drawable/ic_baseline_list_alt_28" android:title="@string/menu_lists" /> - + + + + + \ No newline at end of file From 6b30476ccd68581040ec58689fb26e05d8e1c8bf Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Fri, 23 Oct 2020 22:27:01 -0400 Subject: [PATCH 08/20] Move loading circle into its own object --- .../java/com/example/listify/ItemDetails.java | 24 ++----------- .../example/listify/LoadingCircleDialog.java | 36 +++++++++++++++++++ .../listify/ui/lists/ListsFragment.java | 12 ++----- 3 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 Listify/app/src/main/java/com/example/listify/LoadingCircleDialog.java diff --git a/Listify/app/src/main/java/com/example/listify/ItemDetails.java b/Listify/app/src/main/java/com/example/listify/ItemDetails.java index 15f0767..e76f699 100644 --- a/Listify/app/src/main/java/com/example/listify/ItemDetails.java +++ b/Listify/app/src/main/java/com/example/listify/ItemDetails.java @@ -76,16 +76,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr @Override public void onClick(View v) { closeFABMenu(); - // Create and show a loading dialog - Dialog loadingDialog = new Dialog(ItemDetails.this); - 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); + LoadingCircleDialog loadingDialog = new LoadingCircleDialog(ItemDetails.this); loadingDialog.show(); Properties configs = new Properties(); @@ -180,7 +171,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) { @@ -207,16 +198,7 @@ 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) { - // Create and show a loading dialog - Dialog loadingDialog = new Dialog(this); - 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); + LoadingCircleDialog loadingDialog = new LoadingCircleDialog(this); loadingDialog.show(); Properties configs = new Properties(); diff --git a/Listify/app/src/main/java/com/example/listify/LoadingCircleDialog.java b/Listify/app/src/main/java/com/example/listify/LoadingCircleDialog.java new file mode 100644 index 0000000..d4f6d82 --- /dev/null +++ b/Listify/app/src/main/java/com/example/listify/LoadingCircleDialog.java @@ -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(); + } +} diff --git a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java index 6c1c2c1..0e1ccbf 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java @@ -24,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; @@ -90,16 +91,7 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. @Override public void sendNewListName(String name) { - // Create and show a loading dialog - Dialog loadingDialog = new Dialog(getActivity()); - 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); + LoadingCircleDialog loadingDialog = new LoadingCircleDialog(getActivity()); loadingDialog.show(); Properties configs = new Properties(); From 45c7ac15bdbca51bbe8ce5e521a25731b30d8c9d Mon Sep 17 00:00:00 2001 From: NMerz Date: Sat, 24 Oct 2020 11:53:12 -0400 Subject: [PATCH 09/20] Limit item search results Add a limit on item search results so the user is not overwhelmed. --- .../Lists/ItemSearch/src/ItemSearcher.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Lambdas/Lists/ItemSearch/src/ItemSearcher.java b/Lambdas/Lists/ItemSearch/src/ItemSearcher.java index 29bc78c..a3a7381 100644 --- a/Lambdas/Lists/ItemSearch/src/ItemSearcher.java +++ b/Lambdas/Lists/ItemSearch/src/ItemSearcher.java @@ -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 body, HashMap 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; } } From c9d40d0eaec6699c4e817a18e4b345596463d3c2 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sat, 24 Oct 2020 13:51:11 -0400 Subject: [PATCH 10/20] Price filter debugging --- .../com/example/listify/SearchResults.java | 30 ++++++++++++- .../example/listify/SortDialogFragment.java | 42 ++++++++++++------- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index 0b312c6..429c080 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -31,12 +31,18 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme private int storeSelection; private int sortMode; private boolean descending; + private double minPrice = 0; + private double maxPrice = 0; @Override - public void sendSort(int storeSelection, int sortMode, boolean descending) { + public void sendSort(int storeSelection, int sortMode, boolean descending, double maxPrice, double minPrice) { this.storeSelection = storeSelection; this.sortMode = sortMode; this.descending = descending; + this.minPrice = minPrice; + this.maxPrice = maxPrice; + System.out.println(minPrice); + System.out.println(maxPrice); sortResults(); } @@ -118,7 +124,27 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme return o1.compareTo(o2); } }); - SortDialogFragment sortDialog = new SortDialogFragment(storeSelection, stores, sortMode, descending); + + // Determine the max price for the price slider + double maxProductPrice; + if (resultsProductList.isEmpty()) { + // default to $100 + maxProductPrice = 100.00; + + minPrice = 0; + maxPrice = 100; + } else { + maxProductPrice = resultsProductList.get(0).getPrice().doubleValue(); + for (int i = 1; i < resultsProductList.size(); i++) { + if (resultsProductList.get(i).getPrice().doubleValue() > maxProductPrice) { + maxProductPrice = resultsProductList.get(i).getPrice().doubleValue(); + } + } + if (maxPrice == 0) { + maxPrice = maxProductPrice; + } + } + SortDialogFragment sortDialog = new SortDialogFragment(storeSelection, stores, sortMode, descending, maxProductPrice, minPrice, maxPrice); sortDialog.show(getSupportFragmentManager(), "Sort"); } }); diff --git a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java index d94f120..c5862ef 100644 --- a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java +++ b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java @@ -20,29 +20,35 @@ import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarChangeListener; import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarFinalValueListener; import com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar; -import org.w3c.dom.Text; - import java.util.ArrayList; public class SortDialogFragment extends DialogFragment { public interface OnSortingListener { - void sendSort(int storeSelection, int sortMode, boolean descending); + void sendSort(int storeSelection, int sortMode, boolean descending, double minPrice, double maxPrice); } public OnSortingListener onSortingListener; + CrystalRangeSeekbar priceSeekbar; + private int storeSelection; private int sortMode; private boolean descending; private ArrayList stores; + private double maxProductPrice; // The highest price on the slider + private double minPrice; // The selected min price + private double maxPrice; // The selected max price - public SortDialogFragment(int storeSelection, ArrayList stores, int sortMode, boolean descending) { + public SortDialogFragment(int storeSelection, ArrayList stores, int sortMode, boolean descending, double maxProductPrice, double minPrice, double maxPrice) { this.storeSelection = storeSelection; this.stores = stores; this.sortMode = sortMode; this.descending = descending; + this.maxProductPrice = maxProductPrice; + this.minPrice = minPrice; + this.maxPrice = maxPrice; } @@ -60,7 +66,7 @@ public class SortDialogFragment extends DialogFragment { .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { - onSortingListener.sendSort(storeSelection, sortMode, descending); + onSortingListener.sendSort(storeSelection, sortMode, descending, priceSeekbar.getSelectedMinValue().doubleValue(), priceSeekbar.getSelectedMaxValue().doubleValue()); } }) .setNegativeButton("cancel", new DialogInterface.OnClickListener() { @@ -100,7 +106,7 @@ public class SortDialogFragment extends DialogFragment { sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_upward_50); } - // Change array pointing direction whenever the user clicks the button + // Change arrow pointing direction whenever the user clicks the button sortDirectionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -146,11 +152,15 @@ public class SortDialogFragment extends DialogFragment { } // Set up the seekbar for price - final CrystalRangeSeekbar priceSeekbar = (CrystalRangeSeekbar) root.findViewById(R.id.price_range_seekbar); + priceSeekbar = (CrystalRangeSeekbar) root.findViewById(R.id.price_range_seekbar); final TextView tvMin = (TextView) root.findViewById(R.id.tv_min_price); final TextView tvMax = (TextView) root.findViewById(R.id.tv_max_price); - priceSeekbar.setMaxValue(367); + priceSeekbar.setMaxValue((float) this.maxProductPrice); + System.out.println(String.format("%f : %f", this.minPrice, this.maxPrice)); + priceSeekbar.setMinStartValue((float) this.minPrice); + priceSeekbar.setMaxStartValue((float) this.maxPrice); + priceSeekbar.apply(); // Update price display priceSeekbar.setOnRangeSeekbarChangeListener(new OnRangeSeekbarChangeListener() { @@ -161,13 +171,15 @@ public class SortDialogFragment extends DialogFragment { } }); - // Save price values when user finishes moving the slider - priceSeekbar.setOnRangeSeekbarFinalValueListener(new OnRangeSeekbarFinalValueListener() { - @Override - public void finalValue(Number minValue, Number maxValue) { - System.out.println(String.format("Min: $%.2f, Max: $%.2f", minValue.doubleValue(), maxValue.doubleValue())); - } - }); +// // Save price values when user finishes moving the slider +// priceSeekbar.setOnRangeSeekbarFinalValueListener(new OnRangeSeekbarFinalValueListener() { +// @Override +// public void finalValue(Number minValue, Number maxValue) { +// minPrice = minValue.doubleValue(); +// maxPrice = maxValue.doubleValue(); +//// System.out.println(String.format("Min: $%.2f, Max: $%.2f", minValue.doubleValue(), maxValue.doubleValue())); +// } +// }); return builder.create(); From c07599ecc6b2417a4ed3480ea21c52204ba84f4f Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 25 Oct 2020 16:53:51 -0400 Subject: [PATCH 11/20] Add threads in awaited for loops. Remove new threads from Requestor.getObject calls --- .../java/com/example/listify/ItemDetails.java | 40 ++++++++++++++--- .../com/example/listify/SearchResults.java | 9 +--- .../listify/ui/lists/ListsFragment.java | 44 ++++++++++++------- 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ItemDetails.java b/Listify/app/src/main/java/com/example/listify/ItemDetails.java index e76f699..89fe980 100644 --- a/Listify/app/src/main/java/com/example/listify/ItemDetails.java +++ b/Listify/app/src/main/java/com/example/listify/ItemDetails.java @@ -88,22 +88,50 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver listIdsReceiver = new SynchronousReceiver<>(); - SynchronousReceiver listReceiver = new SynchronousReceiver<>(); requestor.getListOfIds(List.class, listIdsReceiver, listIdsReceiver); Thread t = new Thread(new Runnable() { @Override public void run() { + Integer[] listIds = null; 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()); - } + 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 listReceiver = new SynchronousReceiver<>(); + requestor.getObject(Integer.toString(listIds[i]), List.class, listReceiver, listReceiver); + 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(); + } + + // 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"); diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index 6b62c74..18e4671 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -108,14 +108,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme // Clear old search results from the view resultsProductListSorted.clear(); searchResultsListAdapter.notifyDataSetChanged(); - - Thread t = new Thread(new Runnable() { - @Override - public void run() { - doSearch(query); - } - }); - t.start(); + doSearch(query); return false; } diff --git a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java index 0e1ccbf..cec4674 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java @@ -66,13 +66,7 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. SynchronousReceiver listIdsReceiver = new SynchronousReceiver<>(); final Requestor.Receiver recv = this; - Thread t = new Thread(new Runnable() { - @Override - public void run() { - requestor.getListOfIds(List.class, recv, null); - } - }); - t.start(); + requestor.getListOfIds(List.class, recv, null); FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.new_list_fab); @@ -144,16 +138,36 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. @Override public void acceptDelivery(Object delivered) { - SynchronousReceiver listReceiver = new SynchronousReceiver<>(); Integer[] listIds = (Integer[]) delivered; - 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()); + // 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 listReceiver = new SynchronousReceiver<>(); + requestor.getObject(Integer.toString(listIds[i]), List.class, listReceiver, listReceiver); + 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(); } - } catch (Exception e) { - e.printStackTrace(); + shoppingLists.add(results[i]); } // Set adapter and display this users lists From 9462bc67239b5403dc883398f5594c0022097df2 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 25 Oct 2020 21:19:02 -0400 Subject: [PATCH 12/20] Price range filtering finished --- .../com/example/listify/SearchResults.java | 27 ++++++++++++++----- .../example/listify/SortDialogFragment.java | 17 +----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index 429c080..fcea894 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -32,17 +32,15 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme private int sortMode; private boolean descending; private double minPrice = 0; - private double maxPrice = 0; + private double maxPrice = -1; @Override - public void sendSort(int storeSelection, int sortMode, boolean descending, double maxPrice, double minPrice) { + public void sendSort(int storeSelection, int sortMode, boolean descending, double minPrice, double maxPrice) { this.storeSelection = storeSelection; this.sortMode = sortMode; this.descending = descending; this.minPrice = minPrice; this.maxPrice = maxPrice; - System.out.println(minPrice); - System.out.println(maxPrice); sortResults(); } @@ -89,7 +87,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { -// Toast.makeText(SearchResults.this, resultsProductListSorted.get(position).getItemName(), Toast.LENGTH_SHORT).show(); Intent itemDetailsPage = new Intent(SearchResults.this, ItemDetails.class); // Send the selected product @@ -112,6 +109,8 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme } }); + // TODO: Change this to a menu in which sort and filter are two different options + // TODO: Sort should be disabled until a search is made // Create a dialog for filtering and sorting search results ImageButton sortButton = (ImageButton) findViewById(R.id.results_sort_button); sortButton.setOnClickListener(new View.OnClickListener() { @@ -140,10 +139,14 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme maxProductPrice = resultsProductList.get(i).getPrice().doubleValue(); } } - if (maxPrice == 0) { + if (maxPrice == -1) { maxPrice = maxProductPrice; } } + + // Round up to nearest whole number for display on price seekbar + maxProductPrice = Math.ceil(maxProductPrice); + SortDialogFragment sortDialog = new SortDialogFragment(storeSelection, stores, sortMode, descending, maxProductPrice, minPrice, maxPrice); sortDialog.show(getSupportFragmentManager(), "Sort"); } @@ -264,6 +267,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme break; } + // Flip the list if descending is selected if (this.sortMode != 0 & this.descending) { for (int i = 0; i < resultsProductListSorted.size() / 2; i++) { Product temp = resultsProductListSorted.get(i); @@ -284,6 +288,17 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme resultsProductListSorted.addAll(temp); } + // Filter out products that don't fit price restraints + ArrayList temp = new ArrayList<>(); + resultsProductListSorted.forEach(product -> { + if (product.getPrice().doubleValue() >= this.minPrice && + (this.maxPrice == -1 || product.getPrice().doubleValue() <= this.maxPrice)) { + temp.add(product); + } + }); + resultsProductListSorted.clear(); + resultsProductListSorted.addAll(temp); + searchResultsListAdapter.notifyDataSetChanged(); } } \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java index c5862ef..7cc71a4 100644 --- a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java +++ b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java @@ -17,7 +17,6 @@ import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarChangeListener; -import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarFinalValueListener; import com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar; import java.util.ArrayList; @@ -140,9 +139,7 @@ public class SortDialogFragment extends DialogFragment { } @Override - public void onNothingSelected(AdapterView parent) { - - } + public void onNothingSelected(AdapterView parent) {} }); // Disable the direction button if they have the default sorting mode selected @@ -157,7 +154,6 @@ public class SortDialogFragment extends DialogFragment { final TextView tvMax = (TextView) root.findViewById(R.id.tv_max_price); priceSeekbar.setMaxValue((float) this.maxProductPrice); - System.out.println(String.format("%f : %f", this.minPrice, this.maxPrice)); priceSeekbar.setMinStartValue((float) this.minPrice); priceSeekbar.setMaxStartValue((float) this.maxPrice); priceSeekbar.apply(); @@ -171,17 +167,6 @@ public class SortDialogFragment extends DialogFragment { } }); -// // Save price values when user finishes moving the slider -// priceSeekbar.setOnRangeSeekbarFinalValueListener(new OnRangeSeekbarFinalValueListener() { -// @Override -// public void finalValue(Number minValue, Number maxValue) { -// minPrice = minValue.doubleValue(); -// maxPrice = maxValue.doubleValue(); -//// System.out.println(String.format("Min: $%.2f, Max: $%.2f", minValue.doubleValue(), maxValue.doubleValue())); -// } -// }); - - return builder.create(); } From 07db1c833ad446fa1babb580581fd0fa53b92736 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 25 Oct 2020 21:57:57 -0400 Subject: [PATCH 13/20] Fix duplicate lists displaying --- Listify/app/src/main/java/com/example/listify/ItemDetails.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Listify/app/src/main/java/com/example/listify/ItemDetails.java b/Listify/app/src/main/java/com/example/listify/ItemDetails.java index 89fe980..f2fb43c 100644 --- a/Listify/app/src/main/java/com/example/listify/ItemDetails.java +++ b/Listify/app/src/main/java/com/example/listify/ItemDetails.java @@ -121,6 +121,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr l.start(); } + shoppingLists.clear(); // Wait for each thread to finish and add results to shoppingLists for (int i = 0; i < threads.length; i++) { try { From caf929a71e2569e267be5d5603a96bdec29b0c44 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 25 Oct 2020 22:52:35 -0400 Subject: [PATCH 14/20] Floating total price bar --- .../java/com/example/listify/ListPage.java | 8 +++++ .../com/example/listify/SearchResults.java | 1 + .../app/src/main/res/layout/activity_list.xml | 32 ++++++++++++++++--- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index fa449d2..8558e28 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -16,6 +16,7 @@ import com.example.listify.data.ListEntry; import org.json.JSONException; import java.io.IOException; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Properties; @@ -64,6 +65,7 @@ public class ListPage extends AppCompatActivity { list = null; } + double totalPrice = 0; if(list != null) { for (ListEntry entry : list.getEntries()) { int product = entry.getProductID(); @@ -83,6 +85,9 @@ public class ListPage extends AppCompatActivity { pQuantity.add(entry.getQuantity().toString()); pImages.add(R.drawable.placeholder); pListItemPair.add(entry); + + // Increment total price + totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); } } } @@ -112,6 +117,9 @@ public class ListPage extends AppCompatActivity { myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages); listView.setAdapter(myAdapter); + + TextView tvTotalPrice = (TextView) findViewById(R.id.total_price); + tvTotalPrice.setText(String.format("$%.2f", totalPrice)); } class MyAdapter extends ArrayAdapter { diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index 0b312c6..d799cca 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -176,6 +176,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme sortResults(); } + // 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 diff --git a/Listify/app/src/main/res/layout/activity_list.xml b/Listify/app/src/main/res/layout/activity_list.xml index 65c12f4..12e134b 100644 --- a/Listify/app/src/main/res/layout/activity_list.xml +++ b/Listify/app/src/main/res/layout/activity_list.xml @@ -1,5 +1,5 @@ - @@ -7,8 +7,32 @@ - + android:id="@+id/listView" + android:paddingBottom="20dp"> - \ No newline at end of file + + + + + + + + + \ No newline at end of file From 04a944f2d5a4dbcfcd6125a3004995f79d29f27d Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 25 Oct 2020 23:06:56 -0400 Subject: [PATCH 15/20] Update total price when quantities change and items are removed --- .../java/com/example/listify/ListPage.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index 8558e28..580bb65 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -16,7 +16,6 @@ import com.example.listify.data.ListEntry; import org.json.JSONException; import java.io.IOException; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Properties; @@ -29,6 +28,7 @@ public class ListPage extends AppCompatActivity { Button incrQuan; Button decrQuan; Button removeItem; + TextView tvTotalPrice; ArrayList pNames = new ArrayList<>(); ArrayList pStores = new ArrayList<>(); @@ -39,6 +39,7 @@ public class ListPage extends AppCompatActivity { ArrayList pListItemPair = new ArrayList<>(); Requestor requestor; + double totalPrice = 0; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -65,7 +66,6 @@ public class ListPage extends AppCompatActivity { list = null; } - double totalPrice = 0; if(list != null) { for (ListEntry entry : list.getEntries()) { int product = entry.getProductID(); @@ -118,7 +118,7 @@ public class ListPage extends AppCompatActivity { listView.setAdapter(myAdapter); - TextView tvTotalPrice = (TextView) findViewById(R.id.total_price); + tvTotalPrice = (TextView) findViewById(R.id.total_price); tvTotalPrice.setText(String.format("$%.2f", totalPrice)); } @@ -158,6 +158,10 @@ public class ListPage extends AppCompatActivity { 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 synchronousenforcer = new SynchronousReceiver<>(); requestor.deleteObject(le, synchronousenforcer, synchronousenforcer); try { @@ -187,6 +191,10 @@ public class ListPage extends AppCompatActivity { 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 synchronousenforcer = new SynchronousReceiver<>(); requestor.deleteObject(le, synchronousenforcer, synchronousenforcer); try { @@ -211,6 +219,10 @@ public class ListPage extends AppCompatActivity { removeItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + totalPrice -= (Double.parseDouble(pPrices.get(position)) * + Double.parseDouble(pQuantity.get(position))); + tvTotalPrice.setText(String.format("$%.2f", totalPrice)); + pNames.remove(position); pStores.remove(position); pPrices.remove(position); From 739699d7a525ea3128e98b927a86953049e187ff Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sat, 31 Oct 2020 19:54:11 -0400 Subject: [PATCH 16/20] Explicitly declared inner loop variables to final --- Listify/app/src/main/java/com/example/listify/ItemDetails.java | 2 +- .../main/java/com/example/listify/ui/lists/ListsFragment.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ItemDetails.java b/Listify/app/src/main/java/com/example/listify/ItemDetails.java index f2fb43c..46dd926 100644 --- a/Listify/app/src/main/java/com/example/listify/ItemDetails.java +++ b/Listify/app/src/main/java/com/example/listify/ItemDetails.java @@ -106,7 +106,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr for (int i = 0; i < listIds.length; i++) { SynchronousReceiver listReceiver = new SynchronousReceiver<>(); requestor.getObject(Integer.toString(listIds[i]), List.class, listReceiver, listReceiver); - int finalI = i; + final int finalI = i; Thread l = new Thread(new Runnable() { @Override public void run() { diff --git a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java index cec4674..fdcc4d4 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/lists/ListsFragment.java @@ -48,6 +48,7 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. 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); @@ -145,7 +146,7 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. for (int i = 0; i < listIds.length; i++) { SynchronousReceiver listReceiver = new SynchronousReceiver<>(); requestor.getObject(Integer.toString(listIds[i]), List.class, listReceiver, listReceiver); - int finalI = i; + final int finalI = i; Thread t = new Thread(new Runnable() { @Override public void run() { From 8364ed049b4eaa27596656beb4e2c5b54104bce8 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sat, 31 Oct 2020 20:10:09 -0400 Subject: [PATCH 17/20] Fixed formatting from merge --- .../main/java/com/example/listify/ListPage.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index 2a551b5..4f2a794 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -168,13 +168,14 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } } } - runOnUiThread(new Runnable() { - @Override - public void run() { - loadingListItems.setVisibility(View.GONE); - myAdapter.notifyDataSetChanged(); - } - }); + + runOnUiThread(new Runnable() { + @Override + public void run() { + loadingListItems.setVisibility(View.GONE); + myAdapter.notifyDataSetChanged(); + } + }); } } From d9ea934021c5a471e8ec97ccc0c336c258450075 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sat, 31 Oct 2020 20:34:54 -0400 Subject: [PATCH 18/20] Fix total price being incorrect --- .../main/java/com/example/listify/ListPage.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index dd6a28b..b821dcf 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -47,7 +47,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { ArrayList pListItemPair = new ArrayList<>(); - Requestor requestor; double totalPrice = 0; Map totalPriceByStore = new HashMap<>(); @@ -163,9 +162,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { pQuantity.add(index, entry.getQuantity().toString()); pImages.add(index, item.getImageURL()); pListItemPair.add(index, entry); - - // Increment total price - totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); for(String store : storeHeaderIndex.keySet()) { if(storeHeaderIndex.get(store) > index) { @@ -173,14 +169,21 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } } } + + // Increment total price + System.out.println(totalPrice); + System.out.println(item.getPrice().doubleValue()); + System.out.println(entry.getQuantity()); + totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); + System.out.println(totalPrice); } } - tvTotalPrice = (TextView) findViewById(R.id.total_price); - tvTotalPrice.setText(String.format("$%.2f", totalPrice)); + 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(); } From 1f7a1b10db8d8dd123619428d2aca889d11a4d55 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sat, 31 Oct 2020 20:35:31 -0400 Subject: [PATCH 19/20] Remove print statements --- Listify/app/src/main/java/com/example/listify/ListPage.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index b821dcf..a914890 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -171,11 +171,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } // Increment total price - System.out.println(totalPrice); - System.out.println(item.getPrice().doubleValue()); - System.out.println(entry.getQuantity()); totalPrice += (item.getPrice().doubleValue() * entry.getQuantity()); - System.out.println(totalPrice); } } From fdb1ea6213aec62bed83f3ef1418c5a5bc38a0a5 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sat, 31 Oct 2020 20:47:48 -0400 Subject: [PATCH 20/20] Fix branch merge bug --- .../src/main/java/com/example/listify/SearchResults.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/SearchResults.java b/Listify/app/src/main/java/com/example/listify/SearchResults.java index c9712a0..0421b58 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -277,6 +277,13 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme }); resultsProductListSorted.clear(); resultsProductListSorted.addAll(temp); + + runOnUiThread(new Runnable() { + @Override + public void run() { + searchResultsListAdapter.notifyDataSetChanged(); + } + }); } // This is called after the search results come back from the server @@ -321,8 +328,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme runOnUiThread(new Runnable() { @Override public void run() { - searchResultsListAdapter.notifyDataSetChanged(); - // Hide progress bar loadingSearch.setVisibility(View.GONE);