Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag view bug #119

Merged
merged 3 commits into from
Dec 4, 2023
Merged
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
13 changes: 12 additions & 1 deletion app/src/main/java/com/example/househomey/SelectFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.ListenerRegistration;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import com.google.firebase.firestore.WriteBatch;
Expand All @@ -50,6 +51,7 @@ public class SelectFragment extends Fragment implements DeleteItemsFragment.Dele
private ItemAdapter itemAdapter;
private CollectionReference tagRef;
private Map<String, Item> itemIdMap = new HashMap<>();
private ListenerRegistration tagListener;

/**
*
Expand Down Expand Up @@ -88,7 +90,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
itemAdapter.setSelectState(true);

tagRef = ((MainActivity) requireActivity()).getTagRef();
tagRef.addSnapshotListener(this::setupTagListener);
tagListener = tagRef.addSnapshotListener(this::setupTagListener);

final Button cancelButton = rootView.findViewById(R.id.cancel_select_button);
cancelButton.setOnClickListener(v -> {
Expand Down Expand Up @@ -220,4 +222,13 @@ private void unselectAllItems() {
}
itemAdapter.notifyDataSetChanged();
}

/**
* Remove the tag listener when the fragment is stopped
*/
@Override
public void onStop() {
super.onStop();
tagListener.remove();
}
}
13 changes: 12 additions & 1 deletion app/src/main/java/com/example/househomey/ViewItemFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.android.material.chip.ChipGroup;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.ListenerRegistration;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;

Expand All @@ -45,6 +46,7 @@ public class ViewItemFragment extends Fragment implements EditItemFragment.OnIte
protected ViewPhotoAdapter viewPhotoAdapter;
private CollectionReference tagRef;
private ChipGroup chipGroup;
private ListenerRegistration tagListener;

/**
*
Expand All @@ -62,7 +64,7 @@ public class ViewItemFragment extends Fragment implements EditItemFragment.OnIte
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_view_item, container, false);
tagRef = ((MainActivity) requireActivity()).getTagRef();
tagRef.addSnapshotListener(this::setupTagListener);
tagListener = tagRef.addSnapshotListener(this::setupTagListener);
// Initialize TextViews
TextView title = rootView.findViewById(R.id.view_item_title);
TextView make = rootView.findViewById(R.id.view_item_make);
Expand Down Expand Up @@ -132,6 +134,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
return rootView;
}

/**
* Remove the tag listener when the fragment is stopped
*/
@Override
public void onStop() {
super.onStop();
tagListener.remove();
}

/**
* Whenever an item is updated (in Edit Item), this listener method adds the updated item
* to View Item's bundle arguments and displays the updated item information upon view creation
Expand Down
Loading