Merge branch 'master' into aaron-branch-2

This commit is contained in:
Aaron Sun
2020-11-15 17:36:31 -08:00
committed by GitHub
34 changed files with 580 additions and 92 deletions

View File

@@ -3,25 +3,16 @@ package com.example.listify;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.*;
import android.widget.*;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.bumptech.glide.Glide;
import com.example.listify.data.Chain;
import com.example.listify.data.Item;
import com.example.listify.data.List;
import com.example.listify.data.ListEntry;
import com.example.listify.data.ListShare;
import com.example.listify.ui.SignupPage;
import com.example.listify.data.*;
import org.json.JSONException;
import java.io.IOException;
import java.text.DecimalFormat;
@@ -30,8 +21,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.json.JSONException;
import static com.example.listify.MainActivity.am;
public class ListPage extends AppCompatActivity implements Requestor.Receiver {
@@ -125,9 +114,9 @@ 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);
ListShare listShare = new ListShare(listID, sharedEmail, "Read, Write, Delete, Share");
try {
requestor.postObject(listShare);
requestor.putObject(listShare);
}
catch(Exception e) {
e.printStackTrace();
@@ -144,6 +133,51 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.list, menu);
// return super.onCreateOptionsMenu(menu);
MenuItem renameItem = menu.findItem(R.id.action_rename_list);
renameItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(ListPage.this, "Rename List", Toast.LENGTH_SHORT).show();
return false;
}
});
MenuItem shareItem = menu.findItem(R.id.action_share_list);
shareItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(ListPage.this, "Share List", Toast.LENGTH_SHORT).show();
return false;
}
});
MenuItem duplicateItem = menu.findItem(R.id.action_duplicate_list);
duplicateItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(ListPage.this, "Duplicate List", Toast.LENGTH_SHORT).show();
return false;
}
});
MenuItem exportItem = menu.findItem(R.id.action_export_list);
exportItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(ListPage.this, "Export List", Toast.LENGTH_SHORT).show();
return false;
}
});
return true;
}
@Override
public void acceptDelivery(Object delivered) {
List list = (List) delivered;

View File

@@ -16,19 +16,15 @@ import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.amplifyframework.auth.AuthException;
import com.example.listify.data.Item;
import com.example.listify.data.ItemSearch;
import com.example.listify.data.List;
import com.example.listify.data.ListEntry;
import com.example.listify.data.SearchHistory;
import com.example.listify.ui.LoginPage;
import com.google.android.material.navigation.NavigationView;
import org.json.JSONException;
import java.io.IOException;
import java.time.Instant;
import java.util.Arrays;
import java.util.Properties;
import java.util.Random;
import static com.example.listify.SplashActivity.showSplash;
@@ -108,7 +104,14 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
}
Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey"));
SynchronousReceiver<SearchHistory> historyReceiver = new SynchronousReceiver<>();
requestor.getObject("N/A", SearchHistory.class, historyReceiver, historyReceiver);
try {
System.out.println(historyReceiver.await());
} catch (Exception e) {
e.printStackTrace();
}
/*
List testList = new List(-1, "New List", "user filled by lambda", Instant.now().toEpochMilli());
ListEntry entry = new ListEntry(1, 4, Math.abs(new Random().nextInt()), Instant.now().toEpochMilli(),false);
@@ -139,6 +142,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
} catch (Exception receiverError) {
receiverError.printStackTrace();
}
*/
}
//------------------------------------------------------------------------------------------//

View File

@@ -60,6 +60,25 @@ public class Requestor {
launchCall(deleteRequest, null, classType, failureHandler);
}
public void putObject(Object toPost) throws JSONException {
putObject(toPost, (RequestErrorHandler) null);
}
public void putObject(Object toPost, RequestErrorHandler failureHandler) throws JSONException {
putObject(toPost, null, failureHandler);
}
public void putObject(Object toPost, Receiver<Integer> idReceiver) throws JSONException {
putObject(toPost, idReceiver, null);
}
public void putObject(Object toPut, Receiver<Integer> idReceiver, RequestErrorHandler failureHandler) throws JSONException {
String putURL = DEV_BASEURL + "/" + toPut.getClass().getSimpleName();
Request putRequest = buildBaseRequest(putURL, "PUT", new Gson().toJson(toPut));
launchCall(putRequest, idReceiver, Integer.class, failureHandler);
}
public void postObject(Object toPost) throws JSONException {
postObject(toPost, (RequestErrorHandler) null);
}
@@ -85,7 +104,7 @@ public class Requestor {
String responseString = response.body().string();
if (receiver != null) {
if (classType == null) {
Log.e("Requestor Contract Error", "classType while receiver populated");
Log.e("Requestor Contract Error", "no/null classType while receiver populated");
}
try {
receiver.acceptDelivery(new Gson().fromJson(responseString, classType));

View File

@@ -129,9 +129,9 @@ 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);
ListShare listShare = new ListShare(curList.getItemID(), sharedEmail, "Read, Write, Delete, Share");
try {
requestor.postObject(listShare);
requestor.putObject(listShare);
}
catch(Exception e) {
e.printStackTrace();

View File

@@ -1,20 +1,71 @@
package com.example.listify.data;
import com.example.listify.BuildConfig;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class ListShare {
Integer listID;
String shareWithEmail;
final ListShare[] other;
public ListShare(Integer listID, String shareWithEmail, ListShare[] other) {
Integer permissionLevel;
private static final Map<Integer, String> keysToPerms;
static {
//All keys should be a prime number > 1
//All keys need to be maintained here and in List module->ListPermissions class on the Lambda side
HashMap<Integer, String> keysToPermsTemp = new HashMap<>();
keysToPermsTemp.put(2, "read");
keysToPermsTemp.put(3, "write");
keysToPermsTemp.put(5, "delete");
keysToPermsTemp.put(7, "share");
keysToPerms = Collections.unmodifiableMap(keysToPermsTemp);
}
public ListShare(Integer listID, String shareWithEmail, Integer permissionLevel, ListShare[] other) {
this.listID = listID;
this.shareWithEmail = shareWithEmail;
this.other = other;
this.permissionLevel = permissionLevel;
this.other = other
}
public ListShare(Integer listID, String shareWithEmail) {
public ListShare(Integer listID, String shareWithEmail, String permissionsRaw, ListShare[] other) {
String permissions = permissionsRaw.toLowerCase();
this.listID = listID;
this.shareWithEmail = shareWithEmail;
this.other = null;
permissionLevel = 1;
this.other = other;
for (Map.Entry<Integer, String> keytoPermEntry: keysToPerms.entrySet()) {
if (permissions.contains(keytoPermEntry.getValue())) {
permissionLevel *= keytoPermEntry.getKey();
}
}
}
@Override
public String toString() {
StringBuilder toReturn = new StringBuilder("ListShare{" +
"listID=" + listID +
", shareWithEmail='" + shareWithEmail + '\'' +
", permissionLevel=" + permissionLevel +
" [Permissions: ");
int permissionLevelCopy = permissionLevel;
for (Integer permissionObject : keysToPerms.keySet()) {
Integer permissionInteger = permissionObject;
if (permissionLevelCopy % permissionInteger == 0) {
permissionLevelCopy /= permissionInteger;
toReturn.append(keysToPerms.get(permissionInteger)).append(",");
}
}
if (BuildConfig.DEBUG && permissionLevelCopy != 1) {
throw new AssertionError("Assertion failed");
}
toReturn.append("]}");
return toReturn.toString();
}
public Integer getListID() {
@@ -32,8 +83,16 @@ public class ListShare {
public void setShareWithEmail(String shareWithEmail) {
this.shareWithEmail = shareWithEmail;
}
public ListShare[] getEntries() {
return other;
}
public Integer getPermissionLevel() {
return permissionLevel;
}
public void setPermissionLevel(Integer permissionLevel) {
this.permissionLevel = permissionLevel;
}
}

View File

@@ -0,0 +1,30 @@
package com.example.listify.data;
import java.util.ArrayList;
public class SearchHistory {
ArrayList<String> searches;
public SearchHistory(ArrayList<String> searches) {
this.searches = searches;
}
public ArrayList<String> getSearches() {
return searches;
}
public void setSearches(ArrayList<String> searches) {
this.searches = searches;
}
public void addSearch(String newSearch) {
searches.add(newSearch);
}
@Override
public String toString() {
return "SearchHistory{" +
"searches=" + searches +
'}';
}
}

View File

@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#000000">
<path
android:fillColor="@android:color/white"
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM15,5l6,6v10c0,1.1 -0.9,2 -2,2L7.99,23C6.89,23 6,22.1 6,21l0.01,-14c0,-1.1 0.89,-2 1.99,-2h7zM14,12h5.5L14,6.5L14,12z"/>
</vector>

View File

@@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="28dp"
android:height="28dp"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
android:tint="#000000">
<path
android:fillColor="@android:color/white"
android:pathData="M10,18h4v-2h-4v2zM3,6v2h18L21,6L3,6zM6,13h12v-2L6,11v2z"/>

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#000000">
<path
android:fillColor="@android:color/white"
android:pathData="M9,3L5,6.99h3L8,14h2L10,6.99h3L9,3zM16,17.01L16,10h-2v7.01h-3L15,21l4,-3.99h-3z"/>
</vector>

View File

@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>

View File

@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#FFFFFF"
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#000000">
<path
android:fillColor="@android:color/white"
android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/>
</vector>

View File

@@ -1,5 +0,0 @@
<vector android:height="28dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="28dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z"/>
</vector>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_more"
android:icon="@drawable/ic_baseline_more_vert_24"
android:title=""
app:showAsAction="always">
<menu>
<item
android:id="@+id/action_rename_list"
android:icon="@drawable/ic_baseline_edit_24"
android:title="Rename List"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_share_list"
android:icon="@drawable/ic_baseline_share_24"
android:title="Share List"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_duplicate_list"
android:icon="@drawable/ic_baseline_file_copy_24"
android:title="Duplicate"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_export_list"
android:icon="@drawable/ic_baseline_import_export_24"
android:title="Export"
app:showAsAction="ifRoom" />
</menu>
</item>
</menu>

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_create_list"
android:orderInCategory="101"
android:title="Create List"
app:showAsAction="never" />
</menu>

View File

@@ -2,13 +2,22 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_sort"
android:orderInCategory="101"
android:title="Sort"
app:showAsAction="never" />
<item
android:id="@+id/action_filter"
android:orderInCategory="101"
android:title="Filter"
app:showAsAction="never" />
android:id="@+id/action_more"
android:icon="@drawable/ic_baseline_more_vert_24"
android:title=""
app:showAsAction="always">
<menu>
<item
android:id="@+id/action_sort"
android:icon="@drawable/ic_baseline_sort_24"
android:title="Sort"
app:showAsAction="never" />
<item
android:id="@+id/action_filter"
android:icon="@drawable/ic_baseline_filter_list_24"
android:title="Filter"
app:showAsAction="never" />
</menu>
</item>
</menu>