mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-17 02:58:48 +00:00
Store uiPosition
This will later be changeable and can then be used to sort lists received by the UI controller
This commit is contained in:
parent
7cb9639f9a
commit
421fceb364
@ -9,14 +9,16 @@ public class List {
|
|||||||
long lastUpdated;
|
long lastUpdated;
|
||||||
ArrayList<ItemEntry> entries;
|
ArrayList<ItemEntry> entries;
|
||||||
boolean shared;
|
boolean shared;
|
||||||
|
Integer uiPosition;
|
||||||
|
|
||||||
public List(ResultSet listRow, boolean shared) throws SQLException {
|
public List(ResultSet listRow, boolean shared, Integer uiPosition) throws SQLException {
|
||||||
itemID = listRow.getInt("listID");
|
itemID = listRow.getInt("listID");
|
||||||
name = listRow.getString("name");
|
name = listRow.getString("name");
|
||||||
owner = listRow.getString("owner");
|
owner = listRow.getString("owner");
|
||||||
lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli();
|
lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli();
|
||||||
entries = new ArrayList<>();
|
entries = new ArrayList<>();
|
||||||
this.shared = shared;
|
this.shared = shared;
|
||||||
|
this.uiPosition = uiPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addItemEntry(ItemEntry entry) {
|
public void addItemEntry(ItemEntry entry) {
|
||||||
@ -31,6 +33,8 @@ public class List {
|
|||||||
", owner='" + owner + '\'' +
|
", owner='" + owner + '\'' +
|
||||||
", lastUpdated=" + lastUpdated +
|
", lastUpdated=" + lastUpdated +
|
||||||
", entries=" + entries +
|
", entries=" + entries +
|
||||||
|
", shared=" + shared +
|
||||||
|
", uiPosition=" + uiPosition +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,4 +81,12 @@ public class List {
|
|||||||
public void setShared(boolean shared) {
|
public void setShared(boolean shared) {
|
||||||
this.shared = shared;
|
this.shared = shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getUiPosition() {
|
||||||
|
return uiPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUiPosition(Integer uiPosition) {
|
||||||
|
this.uiPosition = uiPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,8 @@ public class ListAdder implements CallHandler {
|
|||||||
private String cognitoID;
|
private String cognitoID;
|
||||||
|
|
||||||
private final String LIST_CREATE = "INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);";
|
private final String LIST_CREATE = "INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);";
|
||||||
private final String LIST_ACCESS_GRANT = "INSERT INTO ListSharee(listID, userID, permissionLevel) VALUES(?, ?, ?);";
|
private final String LIST_ACCESS_GRANT = "INSERT INTO ListSharee(listID, userID, permissionLevel, uiPosition) VALUES(?, ?, ?, ?);";
|
||||||
|
private final String UI_POSITION_CHECK = "SELECT Max(uiPosition) as maxUIPosition FROM ListSharee WHERE userID = ?;";
|
||||||
|
|
||||||
public ListAdder(Connection connection, String cognitoID) {
|
public ListAdder(Connection connection, String cognitoID) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
@ -17,9 +18,17 @@ public class ListAdder implements CallHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||||
PreparedStatement statement = connection.prepareStatement(LIST_CREATE, Statement.RETURN_GENERATED_KEYS);
|
|
||||||
|
|
||||||
String listName = bodyMap.get("name").toString();//Needs safe checking
|
String listName = bodyMap.get("name").toString();//Needs safe checking
|
||||||
|
|
||||||
|
PreparedStatement uiPositionCheck = connection.prepareStatement(UI_POSITION_CHECK);
|
||||||
|
uiPositionCheck.setString(1, cognitoID);
|
||||||
|
ResultSet uiPositionCheckRS = uiPositionCheck.executeQuery();
|
||||||
|
int nextPosition = 1;
|
||||||
|
if (uiPositionCheckRS.next()) {
|
||||||
|
nextPosition = uiPositionCheckRS.getInt("maxUIPosition") + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
PreparedStatement statement = connection.prepareStatement(LIST_CREATE, Statement.RETURN_GENERATED_KEYS);
|
||||||
statement.setString(1, listName);
|
statement.setString(1, listName);
|
||||||
statement.setString(2, cognitoID);
|
statement.setString(2, cognitoID);
|
||||||
statement.setTimestamp(3, Timestamp.from(Instant.now()));
|
statement.setTimestamp(3, Timestamp.from(Instant.now()));
|
||||||
@ -32,6 +41,7 @@ public class ListAdder implements CallHandler {
|
|||||||
accessGrant.setInt(1, newID);
|
accessGrant.setInt(1, newID);
|
||||||
accessGrant.setString(2, cognitoID);
|
accessGrant.setString(2, cognitoID);
|
||||||
accessGrant.setInt(3, ListPermissions.getAll());
|
accessGrant.setInt(3, ListPermissions.getAll());
|
||||||
|
accessGrant.setInt(4, nextPosition);
|
||||||
System.out.println(accessGrant);
|
System.out.println(accessGrant);
|
||||||
accessGrant.executeUpdate();
|
accessGrant.executeUpdate();
|
||||||
connection.commit();
|
connection.commit();
|
||||||
|
|||||||
@ -12,7 +12,7 @@ public class ListGetter implements CallHandler{
|
|||||||
private final String cognitoID;
|
private final String cognitoID;
|
||||||
|
|
||||||
private final String GET_LIST = "SELECT * FROM List WHERE listID = ?;";
|
private final String GET_LIST = "SELECT * FROM List WHERE listID = ?;";
|
||||||
private final String GET_LISTS = "SELECT listID FROM ListSharee WHERE userID = ?;";
|
private final String GET_LISTS = "SELECT listID FROM ListSharee WHERE userID = ? ORDER BY uiPosition;";
|
||||||
private final String SHARE_CHECK = "SELECT * FROM ListSharee WHERE listID = ?;";
|
private final String SHARE_CHECK = "SELECT * FROM ListSharee WHERE listID = ?;";
|
||||||
private final String GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;";
|
private final String GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;";
|
||||||
|
|
||||||
@ -42,12 +42,14 @@ public class ListGetter implements CallHandler{
|
|||||||
ResultSet accessResults = checkAccess.executeQuery();
|
ResultSet accessResults = checkAccess.executeQuery();
|
||||||
int sharees = 0;
|
int sharees = 0;
|
||||||
boolean verifiedAccess = false;
|
boolean verifiedAccess = false;
|
||||||
|
int uiPosition = 1;
|
||||||
while ((sharees < 2 && accessResults.next()) || !verifiedAccess) {
|
while ((sharees < 2 && accessResults.next()) || !verifiedAccess) {
|
||||||
if (accessResults.getString("userID").equals(cognitoID)) {
|
if (accessResults.getString("userID").equals(cognitoID)) {
|
||||||
verifiedAccess = true;
|
verifiedAccess = true;
|
||||||
if (!ListPermissions.hasPermission(accessResults.getInt("permissionLevel"), "Read")) {
|
if (!ListPermissions.hasPermission(accessResults.getInt("permissionLevel"), "Read")) {
|
||||||
throw new AccessControlException("User " + cognitoID + " does not have permission to read list " + id);
|
throw new AccessControlException("User " + cognitoID + " does not have permission to read list " + id);
|
||||||
}
|
}
|
||||||
|
uiPosition = accessResults.getInt("uiPosition");
|
||||||
}
|
}
|
||||||
sharees++;
|
sharees++;
|
||||||
}
|
}
|
||||||
@ -61,7 +63,7 @@ public class ListGetter implements CallHandler{
|
|||||||
ResultSet getListResults = getList.executeQuery();
|
ResultSet getListResults = getList.executeQuery();
|
||||||
getListResults.first();
|
getListResults.first();
|
||||||
System.out.println(getListResults);
|
System.out.println(getListResults);
|
||||||
List retrievedList = new List(getListResults, shared);
|
List retrievedList = new List(getListResults, shared, uiPosition);
|
||||||
System.out.println(retrievedList);
|
System.out.println(retrievedList);
|
||||||
PreparedStatement getListEntries = connection.prepareStatement(GET_ENTRIES);
|
PreparedStatement getListEntries = connection.prepareStatement(GET_ENTRIES);
|
||||||
getListEntries.setInt(1, id);
|
getListEntries.setInt(1, id);
|
||||||
|
|||||||
@ -1,27 +1,15 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
import com.amplifyframework.auth.AuthException;
|
import android.widget.*;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.example.listify.data.List;
|
import com.example.listify.data.List;
|
||||||
import com.example.listify.data.ListEntry;
|
import com.example.listify.data.ListEntry;
|
||||||
import com.example.listify.model.Product;
|
import com.example.listify.model.Product;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
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;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -239,7 +227,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
|
|||||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||||
|
|
||||||
com.example.listify.data.List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli());
|
com.example.listify.data.List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli(), -1);
|
||||||
|
|
||||||
Thread t = new Thread(new Runnable() {
|
Thread t = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -205,7 +205,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
|||||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||||
|
|
||||||
List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli());
|
List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli(), -1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
requestor.postObject(newList, idReceiver, idReceiver);
|
requestor.postObject(newList, idReceiver, idReceiver);
|
||||||
|
|||||||
@ -9,18 +9,20 @@ public class List {
|
|||||||
long lastUpdated;
|
long lastUpdated;
|
||||||
final ListEntry[] entries;
|
final ListEntry[] entries;
|
||||||
boolean shared;
|
boolean shared;
|
||||||
|
Integer uiPosition;
|
||||||
|
|
||||||
public List(Integer itemID, String name, String owner, long lastUpdated, ListEntry[] entries, boolean shared) {
|
public List(Integer itemID, String name, String owner, long lastUpdated, ListEntry[] entries, boolean shared, Integer uiPosition) {
|
||||||
this.itemID = itemID;
|
this.itemID = itemID;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.lastUpdated = lastUpdated;
|
this.lastUpdated = lastUpdated;
|
||||||
this.entries = entries;
|
this.entries = entries;
|
||||||
this.shared = false;
|
this.shared = false;
|
||||||
|
this.uiPosition = uiPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List(Integer itemID, String name, String owner, long lastUpdated) {
|
public List(Integer itemID, String name, String owner, long lastUpdated, Integer uiPosition) {
|
||||||
this(itemID, name, owner, lastUpdated, null, false);
|
this(itemID, name, owner, lastUpdated, null, false, uiPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -32,6 +34,7 @@ public class List {
|
|||||||
", lastUpdated=" + lastUpdated +
|
", lastUpdated=" + lastUpdated +
|
||||||
", entries=" + Arrays.toString(entries) +
|
", entries=" + Arrays.toString(entries) +
|
||||||
", shared=" + shared +
|
", shared=" + shared +
|
||||||
|
", uiPosition=" + uiPosition +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,4 +81,12 @@ public class List {
|
|||||||
public void setShared(boolean shared) {
|
public void setShared(boolean shared) {
|
||||||
this.shared = shared;
|
this.shared = shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getUiPosition() {
|
||||||
|
return uiPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUiPosition(Integer uiPosition) {
|
||||||
|
this.uiPosition = uiPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,7 +88,7 @@ public class HomeFragment extends Fragment implements CreateListDialogFragment.O
|
|||||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||||
|
|
||||||
List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli());
|
List newList = new List(-1, name, "user filled by lambda", Instant.now().toEpochMilli() , -1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
requestor.postObject(newList, idReceiver, idReceiver);
|
requestor.postObject(newList, idReceiver, idReceiver);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user