diff --git a/Lambdas/Lists/List/src/List.java b/Lambdas/Lists/List/src/List.java index daaa7b0..fd73808 100644 --- a/Lambdas/Lists/List/src/List.java +++ b/Lambdas/Lists/List/src/List.java @@ -3,7 +3,7 @@ import java.sql.SQLException; import java.util.ArrayList; public class List { - Integer itemID; + Integer listID; String name; String owner; long lastUpdated; @@ -12,7 +12,7 @@ public class List { Integer uiPosition; public List(ResultSet listRow, boolean shared, Integer uiPosition) throws SQLException { - itemID = listRow.getInt("listID"); + listID = listRow.getInt("listID"); name = listRow.getString("name"); owner = listRow.getString("owner"); lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli(); @@ -24,7 +24,7 @@ public class List { @Override public String toString() { return "List{" + - "itemID=" + itemID + + "listID=" + listID + ", name='" + name + '\'' + ", owner='" + owner + '\'' + ", lastUpdated=" + lastUpdated + @@ -34,12 +34,17 @@ public class List { '}'; } - public Integer getItemID() { - return itemID; + + public ItemEntry[] getEntries() { + return entries.toArray(new ItemEntry[entries.size()]); } - public void setItemID(Integer itemID) { - this.itemID = itemID; + public Integer getListID() { + return listID; + } + + public void setListID(Integer listID) { + this.listID = listID; } public String getName() { diff --git a/Lambdas/Lists/List/src/ListPUT.java b/Lambdas/Lists/List/src/ListPUT.java new file mode 100644 index 0000000..a1ecb06 --- /dev/null +++ b/Lambdas/Lists/List/src/ListPUT.java @@ -0,0 +1,11 @@ +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; + +import java.util.Map; + +public class ListPUT implements RequestHandler, Object> { + + public Object handleRequest(Map inputMap, Context unfilled) { + return BasicHandler.handleRequest(inputMap, unfilled, ListPutter.class); + } +} diff --git a/Lambdas/Lists/List/src/ListPutter.java b/Lambdas/Lists/List/src/ListPutter.java new file mode 100644 index 0000000..4909a7c --- /dev/null +++ b/Lambdas/Lists/List/src/ListPutter.java @@ -0,0 +1,44 @@ +import java.security.AccessControlException; +import java.sql.*; +import java.time.Instant; +import java.util.HashMap; +import java.util.Map; + +public class ListPutter implements CallHandler { + private final Connection connection; + private final String cognitoID; + + private final String ACCESS_CHECK = "SELECT * from ListSharee WHERE userID = ? and listID = ?;"; + private final String LIST_RENAME = "UPDATE List SET name = ?, lastUpdated = ? WHERE listID = ?;"; + + public ListPutter(Connection connection, String cognitoID) { + this.connection = connection; + this.cognitoID = cognitoID; + } + + @Override + public Object conductAction(Map bodyMap, HashMap queryMap, String cognitoID) throws SQLException { + Integer listID = Integer.parseInt(bodyMap.get("listID").toString()); + + PreparedStatement accessCheck = connection.prepareStatement(ACCESS_CHECK); + accessCheck.setString(1, cognitoID); + accessCheck.setInt(2, listID); + System.out.println(accessCheck); + ResultSet userLists = accessCheck.executeQuery(); + if (!userLists.next()) { + throw new AccessControlException("User does not have access to list"); + } else { + if (!ListPermissions.hasPermission(userLists.getInt("permissionLevel"), "Delete")) { + throw new AccessControlException("User " + cognitoID + " does not have permission to edit list " + listID); + } + } + PreparedStatement renameList = connection.prepareStatement(LIST_RENAME); + renameList.setString(1, bodyMap.get("name").toString()); + renameList.setTimestamp(2, Timestamp.from(Instant.now())); + renameList.setInt(3, listID); + System.out.println(renameList); + renameList.executeUpdate(); + connection.commit(); + return null; + } +} diff --git a/Listify/app/src/main/java/com/example/listify/CreateListAddDialogFragment.java b/Listify/app/src/main/java/com/example/listify/CreateListAddDialogFragment.java index 4d93360..9b8e470 100644 --- a/Listify/app/src/main/java/com/example/listify/CreateListAddDialogFragment.java +++ b/Listify/app/src/main/java/com/example/listify/CreateListAddDialogFragment.java @@ -62,8 +62,12 @@ public class CreateListAddDialogFragment extends DialogFragment { btnMinus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + if (etQuantity.getText().toString().equals("")) { + etQuantity.setText("1"); + } + int curQauntity = Integer.parseInt(etQuantity.getText().toString()); - if (curQauntity > 0) { + if (curQauntity > 1) { curQauntity--; etQuantity.setText(String.format("%d", curQauntity)); } @@ -74,6 +78,10 @@ public class CreateListAddDialogFragment extends DialogFragment { btnPlus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + if (etQuantity.getText().toString().equals("")) { + etQuantity.setText("1"); + } + int curQauntity = Integer.parseInt(etQuantity.getText().toString()); curQauntity++; etQuantity.setText(String.format("%d", curQauntity)); 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 6ef7e05..9b9ddc6 100644 --- a/Listify/app/src/main/java/com/example/listify/ItemDetails.java +++ b/Listify/app/src/main/java/com/example/listify/ItemDetails.java @@ -1,6 +1,7 @@ package com.example.listify; import android.os.Bundle; + import android.view.View; import android.widget.*; import androidx.appcompat.app.AppCompatActivity; @@ -203,7 +204,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr try { - ListEntry entry = new ListEntry(shoppingLists.get(selectedListIndex).getItemID(), curProduct.getItemId(), quantity, Instant.now().toEpochMilli(),false); + ListEntry entry = new ListEntry(shoppingLists.get(selectedListIndex).getListID(), curProduct.getItemId(), quantity, Instant.now().toEpochMilli(),false); requestor.postObject(entry); Toast.makeText(this, String.format("%d of Item added to %s", quantity, shoppingLists.get(selectedListIndex).getName()), Toast.LENGTH_LONG).show(); } catch (Exception e) { 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 309eb2d..f536ea4 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -10,6 +10,8 @@ import android.widget.*; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import com.example.listify.ui.home.HomeFragment; import com.bumptech.glide.Glide; import com.example.listify.data.*; import org.json.JSONException; @@ -27,6 +29,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { ListView listView; MyAdapter myAdapter; Requestor requestor; + SwipeRefreshLayout refreshList; Button incrQuan; Button decrQuan; @@ -59,7 +62,9 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); - final int listID = (int) getIntent().getSerializableExtra("listID"); + final int LIST_ID = (int) getIntent().getSerializableExtra("listID"); + final String LIST_NAME = (String) getIntent().getSerializableExtra("listName"); + setTitle(LIST_NAME); Properties configs = new Properties(); try { @@ -68,7 +73,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { e.printStackTrace(); } requestor = new Requestor(am, configs.getProperty("apiKey")); - requestor.getObject(Integer.toString(listID), List.class, this); + requestor.getObject(Integer.toString(LIST_ID), List.class, this); listView = findViewById(R.id.listView); myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages); @@ -77,6 +82,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { loadingListItems = findViewById(R.id.progress_loading_list_items); loadingListItems.setVisibility(View.VISIBLE); + tvTotalPrice = (TextView) findViewById(R.id.total_price); + clearAll = (Button) findViewById(R.id.buttonClear); clearAll.setOnClickListener(new View.OnClickListener() { @Override @@ -114,7 +121,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { public void onClick(DialogInterface dialog, int which) { EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail); String sharedEmail = sharedEmailText.getText().toString(); - ListShare listShare = new ListShare(listID, sharedEmail, "Read, Write, Delete, Share"); + + ListShare listShare = new ListShare(LIST_ID, sharedEmail, "Read, Write, Delete, Share"); try { requestor.putObject(listShare); } @@ -131,6 +139,22 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { dialog.show(); } }); + + refreshList = (SwipeRefreshLayout) findViewById(R.id.refresh_list); + refreshList.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(ListPage.this, "android.resource://" + getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + requestor = new Requestor(am, configs.getProperty("apiKey")); + requestor.getObject(Integer.toString(LIST_ID), List.class, ListPage.this); + } + }); } @Override @@ -180,6 +204,24 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { @Override public void acceptDelivery(Object delivered) { + // Clear out old values + runOnUiThread(new Runnable() { + @Override + public void run() { + pNames.clear(); + pStores.clear(); + pPrices.clear(); + pQuantity.clear(); + pImages.clear(); + totalPriceByStore.clear(); + storeID2Name.clear(); + storeHeaderIndex.clear(); + pListItemPair.clear(); + totalPrice = 0; + tvTotalPrice.setText(String.format("$%.2f", totalPrice)); + } + }); + List list = (List) delivered; if(list != null) { @@ -260,8 +302,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } } - - tvTotalPrice = (TextView) findViewById(R.id.total_price); runOnUiThread(new Runnable() { @Override public void run() { @@ -271,6 +311,8 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { } }); } + + refreshList.setRefreshing(false); } class MyAdapter extends ArrayAdapter { @@ -330,7 +372,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { catch (Exception e) { Log.i("Authentication", e.toString()); } - listView.setAdapter(myAdapter); + myAdapter.notifyDataSetChanged(); } }); if(Integer.parseInt(pQuantity.get(position)) <= 1) { @@ -365,7 +407,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { catch (Exception e) { Log.i("Authentication", e.toString()); } - listView.setAdapter(myAdapter); + myAdapter.notifyDataSetChanged(); } }); if(Integer.parseInt(pQuantity.get(position)) > 1) { @@ -391,7 +433,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver { pImages.remove(position); requestor.deleteObject(pListItemPair.remove(position)); - listView.setAdapter(myAdapter); + myAdapter.notifyDataSetChanged(); } }); diff --git a/Listify/app/src/main/java/com/example/listify/ListPickerDialogFragment.java b/Listify/app/src/main/java/com/example/listify/ListPickerDialogFragment.java index b9c4959..01331c5 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPickerDialogFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ListPickerDialogFragment.java @@ -90,8 +90,13 @@ public class ListPickerDialogFragment extends DialogFragment { btnMinus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + // Set to 1 if it is empty + if (etQuantity.getText().toString().equals("")) { + etQuantity.setText("1"); + } + int curQauntity = Integer.parseInt(etQuantity.getText().toString()); - if (curQauntity > 0) { + if (curQauntity > 1) { curQauntity--; etQuantity.setText(String.format("%d", curQauntity)); } @@ -102,6 +107,11 @@ public class ListPickerDialogFragment extends DialogFragment { btnPlus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + // Set to 1 if it is empty + if (etQuantity.getText().toString().equals("")) { + etQuantity.setText("1"); + } + int curQauntity = Integer.parseInt(etQuantity.getText().toString()); curQauntity++; etQuantity.setText(String.format("%d", curQauntity)); 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 b4864c8..1926776 100644 --- a/Listify/app/src/main/java/com/example/listify/MainActivity.java +++ b/Listify/app/src/main/java/com/example/listify/MainActivity.java @@ -108,6 +108,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF SynchronousReceiver historyReceiver = new SynchronousReceiver<>(); requestor.getObject("N/A", SearchHistory.class, historyReceiver, historyReceiver); try { + requestor.putObject(new List(293, "Java.py", "me!", 1)); System.out.println(historyReceiver.await()); requestor.putObject(new ListReposition(291, 1)); } catch (Exception e) { @@ -155,7 +156,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF DrawerLayout drawer = findViewById(R.id.drawer_layout); NavigationView navigationView = findViewById(R.id.nav_view); mAppBarConfiguration = new AppBarConfiguration.Builder( - R.id.nav_home, R.id.nav_profile) + R.id.nav_home, R.id.nav_profile, R.id.nav_logout) .setDrawerLayout(drawer) .build(); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); @@ -180,20 +181,14 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF } public void onClickSignout(MenuItem m) { - m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - try { - am.signOutUser(); - Intent intent = new Intent(MainActivity.this, com.example.listify.ui.LoginPage.class); - startActivity(intent); - } - catch (Exception e) { - Log.i("Authentication", e.toString()); - } - return false; - } - }); + try { + am.signOutUser(); + Intent intent = new Intent(MainActivity.this, com.example.listify.ui.LoginPage.class); + startActivity(intent); + } + catch (Exception e) { + Log.i("Authentication", e.toString()); + } } @Override 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 7390cb0..379ac8d 100644 --- a/Listify/app/src/main/java/com/example/listify/SearchResults.java +++ b/Listify/app/src/main/java/com/example/listify/SearchResults.java @@ -13,6 +13,8 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.SearchView; +import android.widget.TextView; + import com.example.listify.adapter.SearchResultsListAdapter; import com.example.listify.data.Chain; import com.example.listify.data.ItemSearch; @@ -28,9 +30,10 @@ import java.util.Properties; import static com.example.listify.MainActivity.am; public class SearchResults extends AppCompatActivity implements FilterDialogFragment.OnFilterListener, SortDialogFragment.OnSortListener, Requestor.Receiver { - private ListView listView; + private ListView resultsListView; private MenuItem filterItem; private ProgressBar loadingSearch; + private TextView tvNoResults; private SearchResultsListAdapter searchResultsListAdapter; private List resultsProductList = new ArrayList<>(); private List resultsProductListSorted = new ArrayList<>(); @@ -64,6 +67,7 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag setSupportActionBar(toolbar); loadingSearch = (ProgressBar) findViewById(R.id.progress_loading_search); + tvNoResults = (TextView) findViewById(R.id.tv_search_no_results); // Back button closes this activity and returns to previous activity (MainActivity) ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton); @@ -95,10 +99,10 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag } }); - ListView listView = (ListView) findViewById(R.id.search_results_list); + resultsListView = (ListView) findViewById(R.id.search_results_list); searchResultsListAdapter = new SearchResultsListAdapter(this, resultsProductListSorted); - listView.setAdapter(searchResultsListAdapter); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + resultsListView.setAdapter(searchResultsListAdapter); + resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Intent itemDetailsPage = new Intent(SearchResults.this, ItemDetails.class); @@ -207,13 +211,22 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag requestor.getObject(query, ItemSearch.class, this); } - // TODO: Scroll the list back to the top when a search, sort, or filter is performed // Sorts the search results private void sortResults() { // Reset the filtered list resultsProductListSorted.clear(); resultsProductListSorted.addAll(resultsProductList); + // Scroll the user back to the top of the results + if (resultsListView != null) { + runOnUiThread(new Runnable() { + @Override + public void run() { + resultsListView.smoothScrollToPosition(0); + } + }); + } + // Sort Modes // 0 default (no sorting) // 1 itemName @@ -311,10 +324,22 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag } // 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; + + // Display "no results" message if the search returns none + runOnUiThread(new Runnable() { + @Override + public void run() { + if (results.getResults().size() == 0) { + tvNoResults.setVisibility(View.VISIBLE); + } else { + tvNoResults.setVisibility(View.GONE); + } + } + }); + try { HashMap chainNameMap = new HashMap<>(); for (int i = 0; i < results.getResults().size(); i++) { 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 5fa13ec..2f17836 100644 --- a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java +++ b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java @@ -35,7 +35,6 @@ public class SortDialogFragment extends DialogFragment { } - // TODO: Sorting should scroll the user back to the top of the page @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); diff --git a/Listify/app/src/main/java/com/example/listify/adapter/SearchResultsListAdapter.java b/Listify/app/src/main/java/com/example/listify/adapter/SearchResultsListAdapter.java index bc02c73..9b3ddf7 100644 --- a/Listify/app/src/main/java/com/example/listify/adapter/SearchResultsListAdapter.java +++ b/Listify/app/src/main/java/com/example/listify/adapter/SearchResultsListAdapter.java @@ -10,6 +10,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; import com.example.listify.model.Product; import com.example.listify.R; @@ -55,8 +56,12 @@ public class SearchResultsListAdapter extends BaseAdapter { TextView itemStore = (TextView) convertView.findViewById(R.id.item_store); Product product = productList.get(position); - // TODO: If image url is broken, display @drawable/ic_baseline_broken_image_600.xml - Glide.with(activity).load(product.getImageUrl()).into(productImage); + + Glide.with(activity) + .applyDefaultRequestOptions(new RequestOptions().placeholder(R.drawable.ic_baseline_image_600).error(R.drawable.ic_baseline_broken_image_600)) + .load(product.getImageUrl()) + .into(productImage); + if (product.getItemName().length() >= 60) { itemName.setText(product.getItemName().substring(0, 60) + "..."); } else { diff --git a/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java b/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java index 8fa0d6a..fd13b79 100644 --- a/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java +++ b/Listify/app/src/main/java/com/example/listify/adapter/ShoppingListsSwipeableAdapter.java @@ -80,7 +80,8 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { holder.frontView = convertView.findViewById(R.id.front_layout); holder.deleteList = convertView.findViewById(R.id.delete_list); holder.shareList = convertView.findViewById(R.id.share_list); - holder.textView = (TextView) convertView.findViewById(R.id.shopping_list_name); + holder.listName = (TextView) convertView.findViewById(R.id.shopping_list_name); + holder.itemCount = (TextView) convertView.findViewById(R.id.shopping_list_item_count); convertView.setTag(holder); } else { @@ -90,19 +91,22 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { final List curList = lists.get(position); // Bind the view to the unique list ID - binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getItemID())); + binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getListID())); if(curList.isShared()) { - holder.textView.setText(curList.getName() + " (shared)"); + holder.listName.setText(curList.getName() + " (shared)"); } else { - holder.textView.setText(curList.getName()); + holder.listName.setText(curList.getName()); } + + holder.itemCount.setText(String.format("%d items", curList.getEntries().length)); + holder.deleteList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { - requestor.deleteObject(Integer.toString(curList.getItemID()), List.class); + requestor.deleteObject(Integer.toString(curList.getListID()), List.class); } catch(Exception e) { e.printStackTrace(); @@ -129,7 +133,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { public void onClick(DialogInterface dialog, int which) { EditText sharedEmailText = (EditText) codeView.findViewById(R.id.editTextTextSharedEmail); String sharedEmail = sharedEmailText.getText().toString(); - ListShare listShare = new ListShare(curList.getItemID(), sharedEmail, "Read, Write, Delete, Share"); + ListShare listShare = new ListShare(curList.getListID(), sharedEmail, "Read, Write, Delete, Share"); try { requestor.putObject(listShare); } @@ -148,7 +152,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { Toast.makeText(activity, String.format("Share %s", curList.getName()), Toast.LENGTH_SHORT).show(); // Close the layout - binderHelper.closeLayout(Integer.toString(curList.getItemID())); + binderHelper.closeLayout(Integer.toString(curList.getListID())); } }); @@ -157,8 +161,10 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { public void onClick(View v) { Intent listPage = new Intent(activity, ListPage.class); - // Send the list ID - listPage.putExtra("listID", curList.getItemID()); + // Send the list ID and list name + listPage.putExtra("listID", curList.getListID()); + listPage.putExtra("listName", curList.getName()); + activity.startActivity(listPage); } }); @@ -171,6 +177,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter { View frontView; View deleteList; View shareList; - TextView textView; + TextView listName; + TextView itemCount; } } diff --git a/Listify/app/src/main/java/com/example/listify/data/List.java b/Listify/app/src/main/java/com/example/listify/data/List.java index 0c4388b..a52a122 100644 --- a/Listify/app/src/main/java/com/example/listify/data/List.java +++ b/Listify/app/src/main/java/com/example/listify/data/List.java @@ -3,7 +3,7 @@ package com.example.listify.data; import java.util.Arrays; public class List { - Integer itemID; + Integer listID; String name; String owner; long lastUpdated; @@ -11,8 +11,8 @@ public class List { boolean shared; Integer uiPosition; - public List(Integer itemID, String name, String owner, long lastUpdated, ListEntry[] entries, boolean shared, Integer uiPosition) { - this.itemID = itemID; + public List(Integer listID, String name, String owner, long lastUpdated, ListEntry[] entries, boolean shared, Integer uiPosition) { + this.listID = listID; this.name = name; this.owner = owner; this.lastUpdated = lastUpdated; @@ -21,14 +21,14 @@ public class List { this.uiPosition = uiPosition; } - public List(Integer itemID, String name, String owner, long lastUpdated, Integer uiPosition) { - this(itemID, name, owner, lastUpdated, null, false, uiPosition); + public List(Integer listID, String name, String owner, long lastUpdated, Integer uiPosition) { + this(listID, name, owner, lastUpdated, null, false, uiPosition); } @Override public String toString() { return "List{" + - "itemID=" + itemID + + "listID=" + listID + ", name='" + name + '\'' + ", owner='" + owner + '\'' + ", lastUpdated=" + lastUpdated + @@ -38,12 +38,12 @@ public class List { '}'; } - public Integer getItemID() { - return itemID; + public Integer getListID() { + return listID; } - public void setItemID(Integer itemID) { - this.itemID = itemID; + public void setListID(Integer listID) { + this.listID = listID; } public String getName() { 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 77b7739..3a93463 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 @@ -6,11 +6,14 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ListView; import android.widget.ProgressBar; +import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + import com.example.listify.AuthManager; import com.example.listify.CreateListDialogFragment; import com.example.listify.LoadingCircleDialog; @@ -37,6 +40,7 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O ListView shoppingListsView; ProgressBar loadingLists; TextView emptyMessage; + SwipeRefreshLayout refreshLists; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_home, container, false); @@ -44,6 +48,7 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O loadingLists = (ProgressBar) root.findViewById(R.id.progress_loading_lists); loadingLists.setVisibility(View.VISIBLE); emptyMessage = (TextView) root.findViewById(R.id.textViewEmpty); + refreshLists = (SwipeRefreshLayout) root.findViewById(R.id.refresh_lists); Properties configs = new Properties(); try { @@ -55,8 +60,8 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O requestor = new Requestor(am, configs.getProperty("apiKey")); SynchronousReceiver listIdsReceiver = new SynchronousReceiver<>(); - final Requestor.Receiver recv = this; - requestor.getListOfIds(List.class, recv, null); +// final Requestor.Receiver recv = this; + requestor.getListOfIds(List.class, this, null); FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.new_list_fab); @@ -70,6 +75,23 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O } }); + refreshLists.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + + requestor = new Requestor(am, configs.getProperty("apiKey")); + SynchronousReceiver listIdsReceiver = new SynchronousReceiver<>(); + + requestor.getListOfIds(List.class, HomeFragment.this, null); + } + }); + return root; } @@ -101,7 +123,7 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O @Override public void run() { try { - newList.setItemID(idReceiver.await()); + newList.setListID(idReceiver.await()); } catch (Exception e) { getActivity().runOnUiThread(new Runnable() { @Override @@ -130,6 +152,9 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O @Override public void acceptDelivery(Object delivered) { + // Remove old lists on refresh + shoppingLists.clear(); + Integer[] listIds = (Integer[]) delivered; // Create threads and add them to a list Thread[] threads = new Thread[listIds.length]; @@ -169,16 +194,6 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O @Override public void run() { shoppingListsView.setAdapter(shoppingListsSwipeableAdapter); -// 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); if(listIds.length == 0) { @@ -187,5 +202,6 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O } }); + refreshLists.setRefreshing(false); } } \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/ui/home/HomeViewModel.java b/Listify/app/src/main/java/com/example/listify/ui/home/HomeViewModel.java deleted file mode 100644 index 22e1280..0000000 --- a/Listify/app/src/main/java/com/example/listify/ui/home/HomeViewModel.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.example.listify.ui.home; - -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; - -public class HomeViewModel extends ViewModel { - - private MutableLiveData mText; - - public HomeViewModel() { - mText = new MutableLiveData<>(); - mText.setValue("This is home fragment"); - } - - public LiveData getText() { - return mText; - } -} \ No newline at end of file diff --git a/Listify/app/src/main/res/drawable/ic_baseline_exit_to_app_24.xml b/Listify/app/src/main/res/drawable/ic_baseline_exit_to_app_24.xml new file mode 100644 index 0000000..83cdf05 --- /dev/null +++ b/Listify/app/src/main/res/drawable/ic_baseline_exit_to_app_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/Listify/app/src/main/res/drawable/ic_baseline_image_600.xml b/Listify/app/src/main/res/drawable/ic_baseline_image_600.xml new file mode 100644 index 0000000..1f1ec73 --- /dev/null +++ b/Listify/app/src/main/res/drawable/ic_baseline_image_600.xml @@ -0,0 +1,5 @@ + + + diff --git a/Listify/app/src/main/res/layout/activity_list.xml b/Listify/app/src/main/res/layout/activity_list.xml index 94d1b61..7ecaabf 100644 --- a/Listify/app/src/main/res/layout/activity_list.xml +++ b/Listify/app/src/main/res/layout/activity_list.xml @@ -37,12 +37,19 @@ - + android:layout_height="wrap_content"> + + + + + + \ No newline at end of file diff --git a/Listify/app/src/main/res/layout/dialog_add_to_list.xml b/Listify/app/src/main/res/layout/dialog_add_to_list.xml index 5e255f9..4273676 100644 --- a/Listify/app/src/main/res/layout/dialog_add_to_list.xml +++ b/Listify/app/src/main/res/layout/dialog_add_to_list.xml @@ -38,6 +38,7 @@ android:layout_width="60dp" android:layout_height="50dp" android:text="@string/_1" + android:digits="0123456789" android:inputType="number"/>