Permalink
Browse files

Done T7.06-RemoveGuests

  • Loading branch information...
GinaHsu committed Sep 28, 2017
1 parent c74c686 commit b8661b7f86f0daaff1200460eb2b85f3752fda11
@@ -44,13 +44,17 @@ public void onBindViewHolder(GuestViewHolder holder, int position) {
// Update the view holder with the information needed to display
String name = mCursor.getString(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry.COLUMN_GUEST_NAME));
int partySize = mCursor.getInt(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry.COLUMN_PARTY_SIZE));
// TODO (6) Retrieve the id from the cursor and
long id = mCursor.getLong(mCursor.getColumnIndex(WaitlistContract.WaitlistEntry._ID));
// Display the guest name
holder.nameTextView.setText(name);
// Display the party count
holder.partySizeTextView.setText(String.valueOf(partySize));
// TODO (7) Set the tag of the itemview in the holder to the id
holder.itemView.setTag(id);
}
@@ -58,17 +58,31 @@ protected void onCreate(Bundle savedInstanceState) {
//TODO (3) Create a new ItemTouchHelper with a SimpleCallback that handles both LEFT and RIGHT swipe directions
// TODO (4) Override onMove and simply return false inside
// TODO (5) Override onSwiped
// TODO (8) Inside, get the viewHolder's itemView's tag and store in a long variable id
// TODO (9) call removeGuest and pass through that id
// TODO (10) call swapCursor on mAdapter passing in getAllGuests() as the argument
//TODO (11) attach the ItemTouchHelper to the waitlistRecyclerView
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT){
// TODO (4) Override onMove and simply return false inside
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
// TODO (5) Override onSwiped
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
// TODO (8) Inside, get the viewHolder's itemView's tag and store in a long variable id
//get the id of the item being swiped
long id = (long) viewHolder.itemView.getTag();
// TODO (9) call removeGuest and pass through that id
//remove from DB
removeGuest(id);
// TODO (10) call swapCursor on mAdapter passing in getAllGuests() as the argument
//update the list
mAdapter.swapCursor(getAllGuests());
}
//TODO (11) attach the ItemTouchHelper to the waitlistRecyclerView
}).attachToRecyclerView(waitlistRecyclerView);
}
/**
@@ -137,8 +151,13 @@ private long addNewGuest(String name, int partySize) {
// TODO (1) Create a new function called removeGuest that takes long id as input and returns a boolean
public boolean removeGuest(Long id){
// TODO (2) Inside, call mDb.delete to pass in the TABLE_NAME and the condition that WaitlistEntry._ID equals id
return mDb.delete(WaitlistContract.WaitlistEntry.TABLE_NAME,
WaitlistContract.WaitlistEntry._ID+" = " +id, null) > 0;
}
// TODO (2) Inside, call mDb.delete to pass in the TABLE_NAME and the condition that WaitlistEntry._ID equals id
}
@@ -9,24 +9,23 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/person_name_edit_text"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/guest_name_hint"
android:inputType="textPersonName|textCapWords"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
<EditText
android:id="@+id/party_count_edit_text"
android:layout_width="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/party_size_hint"
android:gravity="center"
android:hint="@string/party_size_hint"
android:inputType="number"
android:maxLength="2"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

0 comments on commit b8661b7

Please sign in to comment.