Class RecentlyViewedManager

java.lang.Object
org.troy.capstone.managers.RecentlyViewedManager
All Implemented Interfaces:
SearchedItemPanelInteractor

public class RecentlyViewedManager extends Object implements SearchedItemPanelInteractor
Manager for recently viewed items, bridges RecentlyViewedQueue and RecentlyViewedWindow. Handles adding items to the recently viewed queue and updating the window content accordingly without the window and queue depending on each other. Implements SearchedItemPanelInteractor to listen for item selection events from the searched item panels, allowing it to update the recently viewed content based on user interactions with the search results.
  • Field Details

    • recentlyViewedQueue

      private final RecentlyViewedQueue recentlyViewedQueue
      Queue to manage recently viewed items.
    • recentlyViewedWindow

      private final RecentlyViewedWindow recentlyViewedWindow
      Window to display recently viewed items.
  • Constructor Details

    • RecentlyViewedManager

      private RecentlyViewedManager(ItemRepo itemRepo, RecentlyViewedWindow recentlyViewedWindow)
      Constructor for the RecentlyViewedManager.
      Parameters:
      itemRepo - The ItemRepo to use for retrieving item details.
      recentlyViewedWindow - The RecentlyViewedWindow to use for displaying recently viewed items.
  • Method Details

    • create

      static RecentlyViewedManager create(ItemRepo itemRepo, SearchedItemPanelDestinationUI destinationUI, SearchedItemPanelSourceUI panelSourceUI)
      Factory method to create a RecentlyViewedManager and attach it as a listener to the given SearchedItemPanelSourceUI, allowing to receive item selection events from within the SearchedItemPanelSourceUI.
      Parameters:
      itemRepo - The ItemRepo to use for retrieving item details.
      destinationUI - The SearchedItemPanelDestinationUI to use for displaying recently viewed items, should be the same instance as recentlyViewedWindow but typed as the interface it implements.
      panelSourceUI - The SearchedItemPanelSourceUI to register as a listener to receive item selection events from the searched item panels, should be the same instance as the SearchedItemPagination but typed as the interface it implements.
      Returns:
      A new instance of RecentlyViewedManager with the given parameters, and registered as a listener to the panelSourceUI.
      Preconditions:
      itemRepo, recentlyViewedWindow, and panelSourceUI are not null. destinationUI is an instance of RecentlyViewedWindow and panelSourceUI is an instance of SearchedItemPagination.
    • onItemSelected

      public void onItemSelected(String itemId)
      Called when an item is selected in the searched item panel. Adds the selected item to the recently viewed queue and updates the recently viewed window content accordingly.
      Specified by:
      onItemSelected in interface SearchedItemPanelInteractor
      Parameters:
      itemId - The ID of the selected item.
      Preconditions:
      itemId is not null and corresponds to a valid key in the ItemHashMap.