mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-15 18:28:47 +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;
|
||||
ArrayList<ItemEntry> entries;
|
||||
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");
|
||||
name = listRow.getString("name");
|
||||
owner = listRow.getString("owner");
|
||||
lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli();
|
||||
entries = new ArrayList<>();
|
||||
this.shared = shared;
|
||||
this.uiPosition = uiPosition;
|
||||
}
|
||||
|
||||
public void addItemEntry(ItemEntry entry) {
|
||||
@ -31,6 +33,8 @@ public class List {
|
||||
", owner='" + owner + '\'' +
|
||||
", lastUpdated=" + lastUpdated +
|
||||
", entries=" + entries +
|
||||
", shared=" + shared +
|
||||
", uiPosition=" + uiPosition +
|
||||
'}';
|
||||
}
|
||||
|
||||
@ -77,4 +81,12 @@ public class List {
|
||||
public void setShared(boolean 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 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) {
|
||||
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 {
|
||||
PreparedStatement statement = connection.prepareStatement(LIST_CREATE, Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
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(2, cognitoID);
|
||||
statement.setTimestamp(3, Timestamp.from(Instant.now()));
|
||||
@ -32,6 +41,7 @@ public class ListAdder implements CallHandler {
|
||||
accessGrant.setInt(1, newID);
|
||||
accessGrant.setString(2, cognitoID);
|
||||
accessGrant.setInt(3, ListPermissions.getAll());
|
||||
accessGrant.setInt(4, nextPosition);
|
||||
System.out.println(accessGrant);
|
||||
accessGrant.executeUpdate();
|
||||
connection.commit();
|
||||
|
||||
@ -12,7 +12,7 @@ public class ListGetter implements CallHandler{
|
||||
private final String cognitoID;
|
||||
|
||||
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 GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;";
|
||||
|
||||
@ -42,12 +42,14 @@ public class ListGetter implements CallHandler{
|
||||
ResultSet accessResults = checkAccess.executeQuery();
|
||||
int sharees = 0;
|
||||
boolean verifiedAccess = false;
|
||||
int uiPosition = 1;
|
||||
while ((sharees < 2 && accessResults.next()) || !verifiedAccess) {
|
||||
if (accessResults.getString("userID").equals(cognitoID)) {
|
||||
verifiedAccess = true;
|
||||
if (!ListPermissions.hasPermission(accessResults.getInt("permissionLevel"), "Read")) {
|
||||
throw new AccessControlException("User " + cognitoID + " does not have permission to read list " + id);
|
||||
}
|
||||
uiPosition = accessResults.getInt("uiPosition");
|
||||
}
|
||||
sharees++;
|
||||
}
|
||||
@ -61,7 +63,7 @@ public class ListGetter implements CallHandler{
|
||||
ResultSet getListResults = getList.executeQuery();
|
||||
getListResults.first();
|
||||
System.out.println(getListResults);
|
||||
List retrievedList = new List(getListResults, shared);
|
||||
List retrievedList = new List(getListResults, shared, uiPosition);
|
||||
System.out.println(retrievedList);
|
||||
PreparedStatement getListEntries = connection.prepareStatement(GET_ENTRIES);
|
||||
getListEntries.setInt(1, id);
|
||||
|
||||
@ -1,27 +1,15 @@
|
||||
package com.example.listify;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.amplifyframework.auth.AuthException;
|
||||
import android.view.View;
|
||||
import android.widget.*;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.listify.data.List;
|
||||
import com.example.listify.data.ListEntry;
|
||||
import com.example.listify.model.Product;
|
||||
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 java.io.IOException;
|
||||
@ -239,7 +227,7 @@ public class ItemDetails extends AppCompatActivity implements ListPickerDialogFr
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
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() {
|
||||
@Override
|
||||
|
||||
@ -205,7 +205,7 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
|
||||
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
|
||||
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 {
|
||||
requestor.postObject(newList, idReceiver, idReceiver);
|
||||
|
||||
@ -9,18 +9,20 @@ public class List {
|
||||
long lastUpdated;
|
||||
final ListEntry[] entries;
|
||||
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.name = name;
|
||||
this.owner = owner;
|
||||
this.lastUpdated = lastUpdated;
|
||||
this.entries = entries;
|
||||
this.shared = false;
|
||||
this.uiPosition = uiPosition;
|
||||
}
|
||||
|
||||
public List(Integer itemID, String name, String owner, long lastUpdated) {
|
||||
this(itemID, name, owner, lastUpdated, null, false);
|
||||
public List(Integer itemID, String name, String owner, long lastUpdated, Integer uiPosition) {
|
||||
this(itemID, name, owner, lastUpdated, null, false, uiPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -32,6 +34,7 @@ public class List {
|
||||
", lastUpdated=" + lastUpdated +
|
||||
", entries=" + Arrays.toString(entries) +
|
||||
", shared=" + shared +
|
||||
", uiPosition=" + uiPosition +
|
||||
'}';
|
||||
}
|
||||
|
||||
@ -78,4 +81,12 @@ public class List {
|
||||
public void setShared(boolean 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"));
|
||||
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 {
|
||||
requestor.postObject(newList, idReceiver, idReceiver);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user