Skip to content

Commit

Permalink
ItemViewModel javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimin15 committed Apr 27, 2024
1 parent 129819f commit 3f786da
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/src/main/java/com/example/proj2/Classes/ItemViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;

/**
* The ItemViewModel class is a ViewModel responsible for managing item data.
* It provides methods to fetch item data from Firestore, select items.
*/
public class ItemViewModel extends ViewModel {
private MutableLiveData<Item> selectedItem = new MutableLiveData<>();
private MutableLiveData<String> itemName = new MutableLiveData<>();
private FirebaseFirestore db = FirebaseFirestore.getInstance();

/**
* Fetches item data from Firestore based on the given item name.
*
* @param itemName The name of the item to fetch
*/
public void fetchItemData(String itemName) {
DocumentReference docRef = db.collection("Items").document(itemName);
docRef.get().addOnCompleteListener(task -> {
Expand All @@ -25,19 +34,40 @@ public void fetchItemData(String itemName) {
}
});
}

/**
* Gets the LiveData object representing the selected item.
*
* @return The LiveData object representing the selected item
*/
public LiveData<Item> getSelectedItem() {
return selectedItem;
}

/**
* Sets the selected item.
*
* @param item The item to be selected
*/
public void selectItem(Item item) {
Log.d("Posted","Yes");
selectedItem.postValue(item);
}

/**
* Gets the LiveData object representing the item name.
*
* @return The LiveData object representing the item name
*/
public LiveData<String> getItemName() {
return itemName;
}

/**
* Sets the item name.
*
* @param info The name of the item to set
*/
public void setItemName(String info) {
itemName.setValue(info);
}
Expand Down

0 comments on commit 3f786da

Please sign in to comment.