Class ImageDB

java.lang.Object
com.example.breeze_seas.ImageDB

public class ImageDB extends Object
Provides Firestore database operations for image documents.

This class is responsible for managing image records stored in the images collection. It supports generating new image document IDs, saving image data, loading image data, deleting images, and listening for real-time updates from Firestore.

All methods are static because this class acts as a utility-style database access layer for image-related operations.

  • Method Details

    • genNewId

      public static String genNewId()
      Generates a new document ID from the Firestore images collection.
      Returns:
      the newly generated document ID
    • saveImage

      public static void saveImage(Image image, ImageDB.ImageMutationCallback callback)
      Saves an image into images/{imageDocId}.

      The image data is stored under the data field, and the current timestamp is stored under updatedTimestamp. Existing fields are preserved because the write uses merge semantics.

      Parameters:
      image - the image object to save
      callback - the callback to invoke after the Firestore write succeeds or fails
    • loadImage

      public static void loadImage(String imageDocId, ImageDB.LoadImageCallback callback)
      Loads a Base64 image string from images/{imageDocId} and constructs an Image object from the retrieved data.
      Parameters:
      imageDocId - the document ID in the images collection
      callback - the callback that receives the loaded image or an error
    • startImagesListen

      public static void startImagesListen(ImageDB.ImagesChangedCallback callback)
      Attaches a real-time listener to the images collection.

      For each document change received from Firestore, the corresponding callback method is invoked based on whether the image was added, modified, or removed.

      Parameters:
      callback - receives individual change events or listener errors
    • stopImagesListen

      public static void stopImagesListen()
      Detaches the real-time images listener if one is currently active.

      This should be called when the associated screen or component is being torn down in order to avoid memory leaks and unnecessary Firestore updates.

    • deleteImage

      public static void deleteImage(String imageDocId, ImageDB.ImageMutationCallback callback)
      Deletes images/{imageDocId} from the Firestore images collection.
      Parameters:
      imageDocId - the document ID in the images collection
      callback - the callback to invoke after the delete succeeds or fails