Merge pull request #133 from ClaytonWWilson/duplicate-lists

Duplicate lists
This commit is contained in:
Clayton Wilson 2020-11-29 12:53:12 -05:00 committed by GitHub
commit 6feef0ef22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 213 additions and 68 deletions

View File

@ -1,15 +1,16 @@
package com.example.listify;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.*;
import android.widget.*;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@ -27,7 +28,7 @@ import java.util.Properties;
import static com.example.listify.MainActivity.am;
public class ListPage extends AppCompatActivity implements Requestor.Receiver {
public class ListPage extends AppCompatActivity implements Requestor.Receiver, RenameListDialogFragment.OnRenameListListener {
ListView listView;
MyAdapter myAdapter;
Requestor requestor;
@ -59,15 +60,15 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
Map<String, Integer> storeHeaderIndex = new HashMap<>();
DecimalFormat df = new DecimalFormat("0.00");
List selectedList;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
final int LIST_ID = (int) getIntent().getSerializableExtra("listID");
final String LIST_NAME = (String) getIntent().getSerializableExtra("listName");
setTitle(LIST_NAME);
selectedList = (List) getIntent().getSerializableExtra("selectedList");
setTitle(selectedList.getName());
Properties configs = new Properties();
try {
@ -76,7 +77,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
e.printStackTrace();
}
requestor = new Requestor(am, configs.getProperty("apiKey"));
requestor.getObject(Integer.toString(LIST_ID), List.class, this);
requestor.getObject(Integer.toString(selectedList.getListID()), List.class, this);
listView = findViewById(R.id.listView);
myAdapter = new MyAdapter(this, pNames, pStores, pPrices, pQuantity, pImages);
@ -158,7 +159,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
}
requestor = new Requestor(am, configs.getProperty("apiKey"));
requestor.getObject(Integer.toString(LIST_ID), List.class, ListPage.this);
requestor.getObject(Integer.toString(selectedList.getListID()), List.class, ListPage.this);
}
});
}
@ -166,16 +167,16 @@ 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();
RenameListDialogFragment renameListDialog = new RenameListDialogFragment();
renameListDialog.show(getSupportFragmentManager(), "Rename List");
return false;
}
});
@ -193,7 +194,24 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
duplicateItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(ListPage.this, "Duplicate List", Toast.LENGTH_SHORT).show();
ListDuplicate duplicate = new ListDuplicate(selectedList.getListID(), String.format("%s copy", selectedList.getName()));
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(ListPage.this, "android.resource://" + getPackageName() + "/raw/auths.json");
} catch (IOException | JSONException e) {
e.printStackTrace();
}
requestor = new Requestor(am, configs.getProperty("apiKey"));
try {
requestor.postObject(duplicate);
} catch (JSONException e) {
e.printStackTrace();
}
Toast.makeText(ListPage.this, "List duplicated", Toast.LENGTH_SHORT).show();
return false;
}
});
@ -329,6 +347,34 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
refreshList.setRefreshing(false);
}
@Override
public void sendRenameListName(String name) {
selectedList.setName(name);
Properties configs = new Properties();
try {
configs = AuthManager.loadProperties(ListPage.this, "android.resource://" + getPackageName() + "/raw/auths.json");
} catch (IOException | JSONException e) {
e.printStackTrace();
}
requestor = new Requestor(am, configs.getProperty("apiKey"));
try {
requestor.putObject(selectedList);
} catch (Exception e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
setTitle(name);
Toast.makeText(ListPage.this, "List Renamed", Toast.LENGTH_SHORT).show();
}
});
}
class MyAdapter extends ArrayAdapter<String> {
Context context;
ArrayList<String> pNames;

View File

@ -0,0 +1,71 @@
package com.example.listify;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
public class RenameListDialogFragment extends DialogFragment {
public interface OnRenameListListener {
void sendRenameListName(String name);
}
public OnRenameListListener onRenameListListener;
EditText etRenameListName;
public RenameListDialogFragment() {}
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = requireActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
View root = inflater.inflate(R.layout.dialog_rename_list, null);
builder.setView(root)
// Add action buttons
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
onRenameListListener.sendRenameListName(etRenameListName.getText().toString());
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
RenameListDialogFragment.this.getDialog().cancel();
}
});
etRenameListName = (EditText) root.findViewById(R.id.et_renamed_list_name);
return builder.create();
}
// Required to extend DialogFragment
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
onRenameListListener = (OnRenameListListener) getTargetFragment();
if (onRenameListListener == null) {
onRenameListListener = (OnRenameListListener) getActivity();
}
} catch (ClassCastException e) {
Log.e("CreateListDialogFragment", "onAttach: ClassCastException: " + e.getMessage());
}
}
}

View File

@ -79,7 +79,7 @@ public class ShareeSwipeableAdapter extends BaseAdapter {
holder.swipeLayout = (SwipeRevealLayout)convertView.findViewById(R.id.swipe_layout);
holder.frontView = convertView.findViewById(R.id.front_layout);
holder.deleteList = convertView.findViewById(R.id.delete_list);
holder.shareList = convertView.findViewById(R.id.share_list);
// holder.shareList = convertView.findViewById(R.id.share_list);
holder.textView = (TextView) convertView.findViewById(R.id.shopping_list_name);
convertView.setTag(holder);
@ -101,12 +101,12 @@ public class ShareeSwipeableAdapter extends BaseAdapter {
}
});
holder.shareList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
// holder.shareList.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//
// }
// });
holder.frontView.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -79,7 +79,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
holder.swipeLayout = (SwipeRevealLayout)convertView.findViewById(R.id.swipe_layout);
holder.frontView = convertView.findViewById(R.id.front_layout);
holder.deleteList = convertView.findViewById(R.id.delete_list);
holder.shareList = convertView.findViewById(R.id.share_list);
// holder.shareList = convertView.findViewById(R.id.share_list);
holder.listName = (TextView) convertView.findViewById(R.id.shopping_list_name);
holder.itemCount = (TextView) convertView.findViewById(R.id.shopping_list_item_count);
@ -100,7 +100,11 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
holder.listName.setText(curList.getName());
}
holder.itemCount.setText(String.format("%d items", curList.getEntries().length));
if (curList.getEntries() != null) {
holder.itemCount.setText(String.format("%d items", curList.getEntries().length));
} else {
holder.itemCount.setText("0 items");
}
holder.deleteList.setOnClickListener(new View.OnClickListener() {
@Override
@ -120,50 +124,49 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
}
});
holder.shareList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View codeView = inflater.inflate(R.layout.activity_sharedemail, null);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
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(curList.getListID(), sharedEmail, "Read, Write, Delete, Share", null);
try {
requestor.putObject(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
binderHelper.closeLayout(Integer.toString(curList.getListID()));
}
});
// holder.shareList.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// View codeView = inflater.inflate(R.layout.activity_sharedemail, null);
// AlertDialog.Builder builder = new AlertDialog.Builder(activity);
// 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(curList.getListID(), sharedEmail, "Read, Write, Delete, Share", null);
// try {
// requestor.putObject(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
// binderHelper.closeLayout(Integer.toString(curList.getListID()));
// }
// });
holder.frontView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent listPage = new Intent(activity, ListPage.class);
// Send the list ID and list name
listPage.putExtra("listID", curList.getListID());
listPage.putExtra("listName", curList.getName());
// Send the selected list
listPage.putExtra("selectedList", curList);
activity.startActivity(listPage);
}
@ -176,7 +179,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
SwipeRevealLayout swipeLayout;
View frontView;
View deleteList;
View shareList;
// View shareList;
TextView listName;
TextView itemCount;
}

View File

@ -1,8 +1,9 @@
package com.example.listify.data;
import java.io.Serializable;
import java.util.Arrays;
public class List {
public class List implements Serializable {
Integer listID;
String name;
String owner;

View File

@ -1,6 +1,8 @@
package com.example.listify.data;
public class ListEntry {
import java.io.Serializable;
public class ListEntry implements Serializable {
Integer listID;
Integer productID;
Integer quantity;

View File

@ -0,0 +1,22 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rename List"
android:layout_gravity="center"
android:textSize="20sp"
android:layout_marginTop="5dp"/>
<EditText
android:id="@+id/et_renamed_list_name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginHorizontal="15dp"
android:singleLine="true"
android:hint="@string/new_list_name"/>
</LinearLayout>

View File

@ -17,12 +17,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/share_list"
android:src="@drawable/ic_baseline_share_24"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/colorAccent"/>
<!-- <ImageView-->
<!-- android:id="@+id/share_list"-->
<!-- android:src="@drawable/ic_baseline_share_24"-->
<!-- android:layout_width="50dp"-->
<!-- android:layout_height="50dp"-->
<!-- android:background="@color/colorAccent"/>-->
<ImageView
android:id="@+id/delete_list"