From 2c9eaee1be4148420f87531511a163ab6636742a Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Thu, 8 Oct 2020 20:10:28 -0400 Subject: [PATCH] Removed hardcoded db interaction --- .../java/com/example/listify/ItemDetails.java | 26 ++++--------------- .../com/example/listify/MainActivity.java | 8 +----- .../com/example/listify/SearchResults.java | 11 +++----- .../listify/ui/lists/ListsFragment.java | 19 ++++---------- 4 files changed, 14 insertions(+), 50 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 9e5e901..b672924 100644 --- a/Listify/app/src/main/java/com/example/listify/ItemDetails.java +++ b/Listify/app/src/main/java/com/example/listify/ItemDetails.java @@ -24,6 +24,8 @@ import java.time.Instant; import java.util.ArrayList; import java.util.Properties; +import static com.example.listify.MainActivity.am; + public class ItemDetails extends AppCompatActivity implements ListPickerDialogFragment.OnListPickListener, CreateListAddDialogFragment.OnNewListAddListener { private Product curProduct; private LinearLayout linAddItem; @@ -71,12 +73,6 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr public void onClick(View v) { closeFABMenu(); - AuthManager authManager = new AuthManager(); - try { - authManager.signIn("merzn@purdue.edu", "Password123"); - } catch (AuthException e) { - e.printStackTrace(); - } Properties configs = new Properties(); try { configs = AuthManager.loadProperties(ItemDetails.this, "android.resource://" + getPackageName() + "/raw/auths.json"); @@ -84,7 +80,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr e.printStackTrace(); } - Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey")); + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver listIdsReceiver = new SynchronousReceiver<>(); SynchronousReceiver listReceiver = new SynchronousReceiver<>(); @@ -166,19 +162,13 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr @Override public void sendListSelection(int selectedListIndex, int quantity) { - AuthManager authManager = new AuthManager(); - try { - authManager.signIn("merzn@purdue.edu", "Password123"); - } catch (AuthException e) { - e.printStackTrace(); - } Properties configs = new Properties(); try { configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); } catch (IOException | JSONException e) { e.printStackTrace(); } - Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey")); + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver idReceiver = new SynchronousReceiver<>(); @@ -196,19 +186,13 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr @Override public void sendNewListName(String name, int quantity) { - AuthManager authManager = new AuthManager(); - try { - authManager.signIn("merzn@purdue.edu", "Password123"); - } catch (AuthException e) { - e.printStackTrace(); - } Properties configs = new Properties(); try { configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); } catch (IOException | JSONException e) { e.printStackTrace(); } - Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey")); + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver idReceiver = new SynchronousReceiver<>(); com.example.listify.data.List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli()); 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 811771c..6c5b237 100644 --- a/Listify/app/src/main/java/com/example/listify/MainActivity.java +++ b/Listify/app/src/main/java/com/example/listify/MainActivity.java @@ -180,19 +180,13 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF @Override public void sendNewListName(String name) { - AuthManager authManager = new AuthManager(); - try { - authManager.signIn("merzn@purdue.edu", "Password123"); - } catch (AuthException e) { - e.printStackTrace(); - } Properties configs = new Properties(); try { configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); } catch (IOException | JSONException e) { e.printStackTrace(); } - Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey")); + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver idReceiver = new SynchronousReceiver<>(); List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli()); 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 85e57f1..0b312c6 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -10,7 +10,6 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.SearchView; -import com.amplifyframework.auth.AuthException; import com.example.listify.adapter.SearchResultsListAdapter; import com.example.listify.data.ItemSearch; import com.example.listify.model.Product; @@ -21,6 +20,8 @@ import java.util.Comparator; import java.util.List; import java.util.Properties; +import static com.example.listify.MainActivity.am; + public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener { private ListView listView; private SearchResultsListAdapter searchResultsListAdapter; @@ -139,12 +140,6 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme // Clear the old search results resultsProductList.clear(); - AuthManager authManager = new AuthManager(); - try { - authManager.signIn("merzn@purdue.edu", "Password123"); - } catch (AuthException e) { - e.printStackTrace(); - } Properties configs = new Properties(); try { configs = AuthManager.loadProperties(this, "android.resource://" + getPackageName() + "/raw/auths.json"); @@ -152,7 +147,7 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme e.printStackTrace(); } - Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey")); + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver itemReceiver = new SynchronousReceiver<>(); requestor.getObject(query, ItemSearch.class, itemReceiver, itemReceiver); 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 06274f3..0d70572 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 @@ -32,6 +32,8 @@ import java.time.Instant; import java.util.ArrayList; import java.util.Properties; +import static com.example.listify.MainActivity.am; + public class ListsFragment extends Fragment implements CreateListDialogFragment.OnNewListListener { ArrayList shoppingLists = new ArrayList<>(); ListView shoppingListsView; @@ -41,12 +43,6 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. shoppingListsView = root.findViewById(R.id.shopping_lists); // TODO: Switch this to async - AuthManager authManager = new AuthManager(); - try { - authManager.signIn("merzn@purdue.edu", "Password123"); - } catch (AuthException e) { - e.printStackTrace(); - } Properties configs = new Properties(); try { configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json"); @@ -54,7 +50,7 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. e.printStackTrace(); } - Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey")); + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver listIdsReceiver = new SynchronousReceiver<>(); SynchronousReceiver listReceiver = new SynchronousReceiver<>(); @@ -98,19 +94,14 @@ public class ListsFragment extends Fragment implements CreateListDialogFragment. @Override public void sendNewListName(String name) { - AuthManager authManager = new AuthManager(); - try { - authManager.signIn("merzn@purdue.edu", "Password123"); - } catch (AuthException e) { - e.printStackTrace(); - } + 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(authManager, configs.getProperty("apiKey")); + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver idReceiver = new SynchronousReceiver<>(); List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli());