Dependency Injection Setup

Overview

The **Dependency Injection Setup** module organizes and provides the core components required for media playback, ad integration, and UI control within a scoped lifecycle using Dagger 2. It enables modularity, testability, and clear separation of concerns by defining how key objects — such as the finite state machine (FSM) player, controllers, monitors, and ad interfaces — are instantiated and injected across the application.

This setup is crucial for managing the complex dependencies between playback states, user interface controllers, ad retrieval mechanisms, and VPAID clients, ensuring each part is provided consistently with appropriate lifecycle management.


Core Concepts

Purpose


Key Components

1. Custom Scope Annotation: @ActicityScope


2. Dagger Modules

Modules define how to construct and provide dependencies.

a. PlayerModuleDefault

b. FSMModuleReal


3. Dagger Components

Components tie modules to injection targets and define the scope of provided dependencies.

a. FsmComonent

b. FsmComonentReal


Dependency Interactions and Workflow

  1. Activity Initialization:
    An activity (e.g., RealActivity or DoubleViewTubiPlayerActivity) requests injection from the Dagger component (FsmComonentReal or FsmComonent).

  2. Component Provides Dependencies:
    The component creates or returns cached instances according to the @ActicityScope lifecycle, using the bound module to provide each dependency.

  3. FSM Player Setup:
    The FsmPlayerImperial instance is provided with a StateFactory that creates playback states. It starts in the FetchCuePointState to retrieve cue points before playback.

  4. Controllers Injection:
    UI controllers (PlayerUIController, PlayerAdLogicController) are injected, managing the UI and ad playback logic respectively.

  5. Ad Retrieval and Cue Points:
    The AdInterface provided by the module fetches ads and cue points asynchronously (real or stubbed), triggering FSM state transitions.

  6. Monitors Setup:
    AdPlayingMonitor and CuePointMonitor listen to the FSM player and playback progress, coordinating ad insertion and playback.

  7. VPAID Client:
    A VpaidClient implementation (TubiVPAID) is injected to handle VPAID ads via WebView when necessary.


Code Snippets Illustrating Key Concepts


Mermaid Diagram: Dependency Injection Component Structure

classDiagram
    class FsmComonent {
        +inject(DoubleViewTubiPlayerActivity)
        +getStateFactory()
    }
    class FsmComonentReal {
        +inject(RealActivity)
    }
    class FSMModuleReal {
        +provideFsmPlayer()
        +provideController()
        +provideComponentController()
        +provideAdRetriever()
        +provideCuePointsRetriever()
        +provideAdPlayingMonitor()
        +provideCuePointMonitor()
        +provideAdInterfaceNoPreroll()
        +provideVpaidClient()
    }
    class PlayerModuleDefault {
        +provideFsmPlayer()
        +provideController()
        +provideComponentController()
        +provideAdRetriever()
        +provideCuePointsRetriever()
        +provideAdPlayingMonitor()
        +provideCuePointMonitor()
        +provideAdInterfaceNoPreroll()
        +provideVpaidClient()
    }
    class ActicityScope

    FsmComonent --> PlayerModuleDefault : uses
    FsmComonentReal --> FSMModuleReal : uses
    FSMModuleReal ..> ActicityScope : annotates providers
    PlayerModuleDefault ..> ActicityScope : annotates providers

Summary of Relationships


This setup ensures that the complex stateful playback system, including ads and UI controls, is managed with clear boundaries and lifecycle control, facilitating maintainability and extensibility of the media player system.