mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Enforce synchronous updates for quanitity
Also added a new delete method to requestor to allow for a receiver.
This commit is contained in:
parent
702a83ff85
commit
a7ac3d6ec9
@ -1,35 +1,25 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.*;
|
||||||
import android.widget.ArrayAdapter;
|
import androidx.annotation.NonNull;
|
||||||
import android.widget.Button;
|
import androidx.annotation.Nullable;
|
||||||
import android.widget.EditText;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.example.listify.data.Item;
|
import com.example.listify.data.Item;
|
||||||
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 static com.example.listify.MainActivity.am;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import static com.example.listify.MainActivity.am;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
public class ListPage extends AppCompatActivity {
|
public class ListPage extends AppCompatActivity {
|
||||||
ListView listView;
|
ListView listView;
|
||||||
@ -155,13 +145,21 @@ public class ListPage extends AppCompatActivity {
|
|||||||
decrQuan.setOnClickListener(new View.OnClickListener() {
|
decrQuan.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//int q = Integer.parseInt(pQuantity.get(position)) - 1;
|
int q = Integer.parseInt(pQuantity.get(position)) - 1;
|
||||||
//pQuantity.set(position, Integer.toString(q));
|
pQuantity.set(position, Integer.toString(q));
|
||||||
ListEntry le = pListItemPair.remove(position);
|
ListEntry le = pListItemPair.remove(position);
|
||||||
le.setQuantity(le.getQuantity() - 1);
|
le.setQuantity(le.getQuantity() - 1);
|
||||||
requestor.deleteObject(le);
|
pListItemPair.add(position, le);
|
||||||
|
SynchronousReceiver<Integer> synchronousenforcer = new SynchronousReceiver<>();
|
||||||
|
requestor.deleteObject(le, synchronousenforcer, synchronousenforcer);
|
||||||
try {
|
try {
|
||||||
requestor.postObject(le);
|
synchronousenforcer.await();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
requestor.postObject(le, synchronousenforcer, synchronousenforcer);
|
||||||
|
synchronousenforcer.await();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Log.i("Authentication", e.toString());
|
Log.i("Authentication", e.toString());
|
||||||
@ -176,13 +174,21 @@ public class ListPage extends AppCompatActivity {
|
|||||||
incrQuan.setOnClickListener(new View.OnClickListener() {
|
incrQuan.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//int q = Integer.parseInt(pQuantity.get(position)) + 1;
|
int q = Integer.parseInt(pQuantity.get(position)) + 1;
|
||||||
//pQuantity.set(position, Integer.toString(q));
|
pQuantity.set(position, Integer.toString(q));
|
||||||
ListEntry le = pListItemPair.remove(position);
|
ListEntry le = pListItemPair.remove(position);
|
||||||
le.setQuantity(le.getQuantity() + 1);
|
le.setQuantity(le.getQuantity() + 1);
|
||||||
requestor.deleteObject(le);
|
pListItemPair.add(position, le);
|
||||||
|
SynchronousReceiver<Integer> synchronousenforcer = new SynchronousReceiver<>();
|
||||||
|
requestor.deleteObject(le, synchronousenforcer, synchronousenforcer);
|
||||||
try {
|
try {
|
||||||
requestor.postObject(le);
|
synchronousenforcer.await();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
requestor.postObject(le, synchronousenforcer, synchronousenforcer);
|
||||||
|
synchronousenforcer.await();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Log.i("Authentication", e.toString());
|
Log.i("Authentication", e.toString());
|
||||||
|
|||||||
@ -45,9 +45,13 @@ public class Requestor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteObject(Object toDelete) {
|
public void deleteObject(Object toDelete) {
|
||||||
|
deleteObject(toDelete, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteObject(Object toDelete, Receiver receiver, RequestErrorHandler errorHandler) {
|
||||||
String deleteURL = DEV_BASEURL + "/" + toDelete.getClass().getSimpleName();
|
String deleteURL = DEV_BASEURL + "/" + toDelete.getClass().getSimpleName();
|
||||||
Request deleteRequest = buildBaseRequest(deleteURL, "DELETE", new Gson().toJson(toDelete));
|
Request deleteRequest = buildBaseRequest(deleteURL, "DELETE", new Gson().toJson(toDelete));
|
||||||
launchCall(deleteRequest, null, toDelete.getClass(), null);
|
launchCall(deleteRequest, receiver, toDelete.getClass(), errorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteObject(String id, Class classType, RequestErrorHandler failureHandler) {
|
public void deleteObject(String id, Class classType, RequestErrorHandler failureHandler) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user