Merge pull request #136 from ClaytonWWilson/aaron-branch-2

Aaron branch 2
This commit is contained in:
Aaron Sun
2020-11-29 13:00:49 -08:00
committed by GitHub
6 changed files with 121 additions and 71 deletions

View File

@@ -55,6 +55,7 @@
<activity android:name="com.example.listify.ui.LoginPage" /> <activity android:name="com.example.listify.ui.LoginPage" />
<activity android:name="com.example.listify.ui.ForgotPasswordPage" /> <activity android:name="com.example.listify.ui.ForgotPasswordPage" />
<activity android:name="com.example.listify.ListPage" /> <activity android:name="com.example.listify.ListPage" />
<activity android:name="com.example.listify.ListSharees" />
</application> </application>
</manifest> </manifest>

View File

@@ -41,14 +41,14 @@ import androidx.appcompat.app.AppCompatActivity;
import static com.example.listify.MainActivity.am; import static com.example.listify.MainActivity.am;
public class ListSharees extends AppCompatActivity implements Requestor.Receiver { public class ListSharees extends AppCompatActivity implements Requestor.Receiver {
ShareeSwipeableAdapter myAdapter; ListView listView;
MyAdapter myAdapter;
Requestor requestor; Requestor requestor;
ProgressBar loadingListItems;
Button removeSharee;
DecimalFormat df = new DecimalFormat("0.00"); ArrayList<String> lShareeEmails = new ArrayList<>();
// TODO: Display a message if their list is empty
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -65,8 +65,9 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver
requestor = new Requestor(am, configs.getProperty("apiKey")); requestor = new Requestor(am, configs.getProperty("apiKey"));
requestor.getObject(Integer.toString(listID), ListShare.class, this); requestor.getObject(Integer.toString(listID), ListShare.class, this);
loadingListItems = findViewById(R.id.progress_loading_list_items); listView = findViewById(R.id.listOfSharees);
loadingListItems.setVisibility(View.VISIBLE); myAdapter = new MyAdapter(this, lShareeEmails);
listView.setAdapter(myAdapter);
} }
@Override @Override
@@ -74,29 +75,54 @@ public class ListSharees extends AppCompatActivity implements Requestor.Receiver
ListShare sharee = (ListShare) delivered; ListShare sharee = (ListShare) delivered;
if(sharee != null) { if(sharee != null) {
SynchronousReceiver<ListShare> listShareReceiver = new SynchronousReceiver<>(); lShareeEmails.add("sharee.getShareWithEmail()");
requestor.getObject(Integer.toString(sharee.getListID()), ListShare.class, listShareReceiver, listShareReceiver);
ArrayList<ListShare> resultList = new ArrayList<>(); if(sharee.getEntries() != null) {
ListShare result; for(ListShare ls : sharee.getEntries()) {
lShareeEmails.add(ls.getShareWithEmail());
try {
result = listShareReceiver.await();
}
catch (Exception e) {
e.printStackTrace();
result = null;
}
if(result != null) {
resultList.add(result);
for(ListShare r : result.getEntries()) {
resultList.add(r);
} }
myAdapter = new ShareeSwipeableAdapter(this, resultList);
} }
runOnUiThread(new Runnable() {
@Override
public void run() {
myAdapter.notifyDataSetChanged();
}
});
}
}
class MyAdapter extends ArrayAdapter<String> {
Context context;
ArrayList<String> lShareeEmails;
MyAdapter (Context c, ArrayList<String> shareeEmails) {
super(c, R.layout.shopping_list_sharee_entry, R.id.textView14, shareeEmails);
context = c;
lShareeEmails = shareeEmails;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View listproduct = layoutInflater.inflate(R.layout.shopping_list_sharee_entry, parent,false);
TextView shareeEmail = listproduct.findViewById(R.id.textView14);
if(!lShareeEmails.isEmpty()) {
shareeEmail.setText(lShareeEmails.get(position));
}
removeSharee = (Button) listproduct.findViewById(R.id.button4);
removeSharee.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lShareeEmails.remove(position);
myAdapter.notifyDataSetChanged();
}
});
return listproduct;
} }
} }
} }

View File

@@ -49,7 +49,7 @@ public class ShoppingListsAdapter extends BaseAdapter {
TextView tvListName = (TextView) convertView.findViewById(R.id.shopping_list_name); TextView tvListName = (TextView) convertView.findViewById(R.id.shopping_list_name);
if(curList.isShared()) { if(curList.isShared()) {
tvListName.setText(curList.getName() + " (shared)"); tvListName.setText(curList.getName() + " (shared by " + curList.getOwner() + ")");
} }
else { else {
tvListName.setText(curList.getName()); tvListName.setText(curList.getName());

View File

@@ -17,6 +17,7 @@ import com.chauthai.swipereveallayout.SwipeRevealLayout;
import com.chauthai.swipereveallayout.ViewBinderHelper; import com.chauthai.swipereveallayout.ViewBinderHelper;
import com.example.listify.AuthManager; import com.example.listify.AuthManager;
import com.example.listify.ListPage; import com.example.listify.ListPage;
import com.example.listify.ListSharees;
import com.example.listify.R; import com.example.listify.R;
import com.example.listify.Requestor; import com.example.listify.Requestor;
import com.example.listify.data.List; import com.example.listify.data.List;
@@ -94,7 +95,7 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getListID())); binderHelper.bind(holder.swipeLayout, Integer.toString(curList.getListID()));
if(curList.isShared()) { if(curList.isShared()) {
holder.listName.setText(curList.getName() + " (shared)"); holder.listName.setText(curList.getName() + " (shared by " + curList.getOwner() + ")");
} }
else { else {
holder.listName.setText(curList.getName()); holder.listName.setText(curList.getName());
@@ -124,41 +125,18 @@ public class ShoppingListsSwipeableAdapter extends BaseAdapter {
} }
}); });
// holder.shareList.setOnClickListener(new View.OnClickListener() { holder.shareList.setOnClickListener(new View.OnClickListener() {
// @Override @Override
// public void onClick(View v) { public void onClick(View v) {
// View codeView = inflater.inflate(R.layout.activity_sharedemail, null); Intent listSharees = new Intent(activity, ListSharees.class);
// AlertDialog.Builder builder = new AlertDialog.Builder(activity);
// builder.setView(codeView); // Send the list ID and list name
// builder.setTitle("Share list"); listSharees.putExtra("listID", curList.getListID());
// builder.setMessage("Please enter the email of the user who you want to share the list with."); //listPage.putExtra("listName", curList.getName());
// builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
// @Override activity.startActivity(listSharees);
// 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() { holder.frontView.setOnClickListener(new View.OnClickListener() {
@Override @Override

View File

@@ -3,20 +3,36 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<ProgressBar <TextView
android:id="@+id/progress_loading_list_items" android:id="@+id/textView15"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:text="Enter the email of the user you want to share the list with."
android:layout_centerVertical="true" android:layout_marginTop="10dp"
android:indeterminate="true" android:layout_marginLeft="13dp"/>
android:visibility="gone"/>
<EditText
android:id="@+id/editTextShareeEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="17"
android:inputType="textPersonName"
android:hint="Sharee's email"
android:layout_marginTop="30dp"
android:layout_marginLeft="10dp"/>
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:layout_marginTop="100dp"
android:layout_marginLeft="10dp"/>
<ListView <ListView
android:id="@+id/listOfSharees" android:id="@+id/listOfSharees"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="0dp" /> android:layout_marginTop="175dp"/>
</RelativeLayout> </RelativeLayout>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:text="Stop sharing"
android:textSize="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="30dp"
android:text="Sharee's email"
android:textSize="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>