Delete list now works

This commit is contained in:
Aaron Sun 2020-11-01 11:41:58 -08:00
parent e35ef127ff
commit 8744b99cb5
2 changed files with 52 additions and 12 deletions

View File

@ -114,16 +114,6 @@ 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();
//String[] sharedEmailList = sharedEmails.split(", ");
//for(String email : sharedEmailList) {
//Properties configs = new Properties();
//try {
// configs = AuthManager.loadProperties(ListPage.this, "android.resource://" + getPackageName() + "/raw/auths.json");
//} catch (IOException | JSONException e) {
// e.printStackTrace();
//}
//Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
//SynchronousReceiver<Integer> ls = new SynchronousReceiver<>();
ListShare listShare = new ListShare(listID, sharedEmail);
try {
requestor.postObject(listShare);
@ -131,7 +121,6 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
catch(Exception e) {
e.printStackTrace();
}
//}
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

View File

@ -1,22 +1,34 @@
package com.example.listify.adapter;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.chauthai.swipereveallayout.SwipeRevealLayout;
import com.chauthai.swipereveallayout.ViewBinderHelper;
import com.example.listify.AuthManager;
import com.example.listify.ListPage;
import com.example.listify.R;
import com.example.listify.Requestor;
import com.example.listify.data.List;
import com.example.listify.data.ListShare;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;
import static com.example.listify.MainActivity.am;
public class ShoppingListsSwipeableAdapter extends BaseAdapter {
private Activity activity;
@ -77,7 +89,20 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
@Override
public void onClick(View v) {
// TODO: Add database call to delete the list on the server
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(activity, "android.resource://" + activity.getPackageName() + "/raw/auths.json");
} catch (IOException | JSONException e) {
e.printStackTrace();
}
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
try {
requestor.deleteObject(Integer.toString(curList.getItemID()), List.class);
}
catch(Exception e) {
e.printStackTrace();
}
Toast.makeText(activity, String.format("%s deleted", curList.getName()), Toast.LENGTH_SHORT).show();
lists.remove(position);
@ -92,6 +117,32 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
public void onClick(View v) {
// TODO: Add database call to share list
/*View codeView = getLayoutInflater().inflate(R.layout.activity_sharedemail, null);
AlertDialog.Builder builder = new AlertDialog.Builder(ListPage.this);
builder.setView(codeView);
builder.setTitle("Share list");
builder.setMessage("Please enter the email of the user who you want to share the list with.");
builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
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);
try {
requestor.postObject(listShare);
}
catch(Exception e) {
e.printStackTrace();
}
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
});
AlertDialog dialog = builder.create();
dialog.show();*/
Toast.makeText(activity, String.format("Share %s", curList.getName()), Toast.LENGTH_SHORT).show();
// Close the layout