FsmComonentReal.java
Overview
`FsmComonentReal.java` defines a **Dagger 2 Component** interface named `FsmComonentReal` that serves as a dependency injection bridge for the `RealActivity` class within the Tubitv media player demo application. It specifies that dependencies provided by the `FSMModuleReal` module are to be injected into `RealActivity`.
Purpose and Functionality
This file declares a Dagger component scoped with a custom
@ActicityScopeannotation, indicating that all dependencies created and injected by this component share the lifecycle of an activity.It binds the
FSMModuleRealmodule, which provides concrete implementations for the finite state machine (FSM) player, UI controllers, ad retrieval logic, and VPAID client integrations using real or simulated network operations.The component exposes a single injection method
inject(RealActivity activity)that enablesRealActivityto receive all necessary dependencies automatically.
Code Breakdown
@ActicityScope
@Component(modules = FSMModuleReal.class)
public interface FsmComonentReal {
void inject(RealActivity activity);
}
@ActicityScope
A custom scope annotation (defined elsewhere) that scopes the lifespan of provided dependencies to the lifecycle of the activity.
Ensures single instances of dependencies per activity injection.
@Component(modules = FSMModuleReal.class)
Declares this interface as a Dagger component.
Specifies
FSMModuleRealas the module that supplies dependency instances.
Interface: FsmComonentReal
Method:
void inject(RealActivity activity)
Injects all required dependencies into theRealActivityinstance. The method is called typically in the activity's lifecycle (e.g.,onCreateor a dedicated injection method).
Usage Example
In `RealActivity`, dependency injection is triggered like this:
@Override
protected void injectDependency() {
DaggerFsmComonentReal.builder()
.fSMModuleReal(new FSMModuleReal(vpaidWebView, mTubiPlayerView))
.build()
.inject(this);
}
DaggerFsmComonentRealis the Dagger-generated implementation of this component.FSMModuleRealis instantiated with necessary UI components such as theWebViewfor VPAID ads and the player root view.The built component injects all scoped dependencies into
RealActivity.
Important Implementation Details
This component does not expose any dependencies publicly; it only provides an injection method.
It relies on
FSMModuleRealto provide:The FSM player (
FsmPlayerImperial) starting in theFetchCuePointState.UI controllers (
PlayerUIController,PlayerAdLogicController).Ad retrieval and cue point fetching with simulated network delays.
Monitors for ad playing and cue points.
A VPAID client (
TubiVPAID) integrated with aWebViewfor interactive ads.
The component and its dependencies are scoped to the lifecycle of the activity to prevent leaks and redundant instantiations.
Interaction with Other Parts of the System
RealActivity: The primary injection target. This activity manages the media player UI and playback logic.
FSMModuleReal: The module providing real implementations of services and controllers used by the FSM player.
Dependency Injection Setup: This component is part of a larger DI setup that includes other components like
FsmComonent(for demo or default usage).FSM Player and Controllers: Injected into
RealActivityto manage dual ExoPlayer instances, ad playback, and UI coordination.Ad and Cue Point Retrieval: Asynchronous operations simulated in
FSMModuleRealallow the FSM player to fetch ads and cue points dynamically.VPAID Ads: The
TubiVPAIDclient injected handles VPAID interactive ads via the WebView passed into the module/component.
Visual Diagram: Component Structure and Injection
classDiagram
class FsmComonentReal {
+inject(activity: RealActivity)
}
class FSMModuleReal {
+provideFsmPlayer()
+providePlayerUIController()
+providePlayerAdLogicController()
+provideAdRetriever()
+provideCuePointsRetriever()
+provideAdPlayingMonitor()
+provideCuePointMonitor()
+provideAdInterface()
+provideVpaidClient()
}
class RealActivity
FsmComonentReal --> FSMModuleReal : uses/provides dependencies
FsmComonentReal --> RealActivity : injects dependencies
Summary
`FsmComonentReal.java` defines a scoped Dagger component for injecting real implementations of FSM playback and ad-related dependencies into the `RealActivity`. It leverages the `FSMModuleReal` module to provide all necessary services for managing playback states, UI, ads, and VPAID integration, ensuring a clean and maintainable setup for dependency management within the activity lifecycle.
Additional Context (for clarity)
This file is a single interface with no classes or methods beyond
inject().The heavy lifting is done in
FSMModuleRealand the injected classes.The component is crucial for establishing the dependency graph for
RealActivity.It supports the modular architecture by decoupling dependency provision from usage.
If you need documentation on related files like [FSMModuleReal.java](/projects/288/68274) or the `RealActivity` usage, I can provide that as well.