From 85f78e3333a2e07044a708e5333396a14b93ef97 Mon Sep 17 00:00:00 2001 From: Aaron Sun Date: Fri, 9 Oct 2020 12:14:44 -0700 Subject: [PATCH 01/36] Can now display splashscreen when first entering the app v.3 --- Listify/app/src/main/AndroidManifest.xml | 1 + .../com/example/listify/MainActivity.java | 18 +++++++++++- .../com/example/listify/SplashActivity.java | 28 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Listify/app/src/main/java/com/example/listify/SplashActivity.java diff --git a/Listify/app/src/main/AndroidManifest.xml b/Listify/app/src/main/AndroidManifest.xml index 73d5a0d..980c079 100644 --- a/Listify/app/src/main/AndroidManifest.xml +++ b/Listify/app/src/main/AndroidManifest.xml @@ -40,6 +40,7 @@ + \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/MainActivity.java b/Listify/app/src/main/java/com/example/listify/MainActivity.java index 0dfb9cc..d56bbee 100644 --- a/Listify/app/src/main/java/com/example/listify/MainActivity.java +++ b/Listify/app/src/main/java/com/example/listify/MainActivity.java @@ -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,15 @@ 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.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 +33,25 @@ 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); + } + //------------------------------Auth Testing---------------------------------------------// diff --git a/Listify/app/src/main/java/com/example/listify/SplashActivity.java b/Listify/app/src/main/java/com/example/listify/SplashActivity.java new file mode 100644 index 0000000..a5d9c2a --- /dev/null +++ b/Listify/app/src/main/java/com/example/listify/SplashActivity.java @@ -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); + } +} \ 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/36] 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/36] 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: Tue, 20 Oct 2020 20:07:31 -0700 Subject: [PATCH 04/36] Removed everything except Login and Delete Account buttons in Home/Profile page --- .../java/com/example/listify/AuthManager.java | 1 - .../example/listify/ui/home/HomeFragment.java | 9 ++---- .../app/src/main/res/layout/fragment_home.xml | 31 ++++--------------- Listify/app/src/main/res/values/strings.xml | 2 +- 4 files changed, 10 insertions(+), 33 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/AuthManager.java b/Listify/app/src/main/java/com/example/listify/AuthManager.java index 7e38e72..c00c8eb 100644 --- a/Listify/app/src/main/java/com/example/listify/AuthManager.java +++ b/Listify/app/src/main/java/com/example/listify/AuthManager.java @@ -117,7 +117,6 @@ public class AuthManager { error -> setAuthError(error) ); throwIfAuthError(); - } public void confirmSignUp(String confirmationCode) throws AuthException { diff --git a/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java b/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java index 6e7b513..68ec5e2 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java @@ -26,7 +26,7 @@ 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); @@ -40,13 +40,10 @@ public class HomeFragment extends Fragment { } }); - toListPage = (Button) root.findViewById(R.id.button2); - toListPage.setOnClickListener(new View.OnClickListener() { + toDeleteAccountPage = (Button) root.findViewById(R.id.button2); + toDeleteAccountPage.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 { diff --git a/Listify/app/src/main/res/layout/fragment_home.xml b/Listify/app/src/main/res/layout/fragment_home.xml index f43f76a..ecc63ce 100644 --- a/Listify/app/src/main/res/layout/fragment_home.xml +++ b/Listify/app/src/main/res/layout/fragment_home.xml @@ -10,39 +10,20 @@ android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="25dp" - android:layout_marginEnd="25dp" + android:layout_marginBottom="40dp" android:text="Log in" - app:layout_constraintBottom_toTopOf="@+id/button2" - app:layout_constraintEnd_toEndOf="@+id/button2" /> + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" />