Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void addMeal(View view) {
*/
public void removeList() {
/* Create an instance of the dialog fragment and show it */
DialogFragment dialog = RemoveListDialogFragment.newInstance(mShoppingList);
DialogFragment dialog = RemoveListDialogFragment.newInstance(mShoppingList, mListId);
dialog.show(getFragmentManager(), "RemoveListDialogFragment");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
import android.os.Bundle;
import android.support.v7.app.AlertDialog;

import com.firebase.client.Firebase;
import com.udacity.firebase.shoppinglistplusplus.R;
import com.udacity.firebase.shoppinglistplusplus.model.ShoppingList;
import com.udacity.firebase.shoppinglistplusplus.utils.Constants;

/**
* Lets the user remove active shopping list
*/
public class RemoveListDialogFragment extends DialogFragment {
String mListId;
final static String LOG_TAG = RemoveListDialogFragment.class.getSimpleName();

/**
* Public static constructor that creates fragment and passes a bundle with data into it when adapter is created
*/
public static RemoveListDialogFragment newInstance(ShoppingList shoppingList) {
public static RemoveListDialogFragment newInstance(ShoppingList shoppingList, String listId) {
RemoveListDialogFragment removeListDialogFragment = new RemoveListDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(Constants.KEY_LIST_ID, listId);
removeListDialogFragment.setArguments(bundle);
return removeListDialogFragment;
}
Expand All @@ -31,6 +35,7 @@ public static RemoveListDialogFragment newInstance(ShoppingList shoppingList) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mListId = getArguments().getString(Constants.KEY_LIST_ID);
}

@Override
Expand All @@ -57,7 +62,10 @@ public void onClick(DialogInterface dialog, int which) {
}

private void removeList() {

/* Get the location to remove from */
Firebase listToRemoveRef = new Firebase(Constants.FIREBASE_URL_ACTIVE_LISTS).child(mListId);
/* Remove the value */
listToRemoveRef.removeValue();
}

}