Search in sources :

Example 1 with VideoDetailViewModel

use of com.zype.android.ui.video_details.VideoDetailViewModel in project zype-android by zype.

the class PlayerFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // 
    // IMA SDK
    // 
    // Create an AdsLoader.
    sdkFactory = ImaSdkFactory.getInstance();
    adsLoader = sdkFactory.createAdsLoader(this.getActivity());
    // Add listeners for when ads are loaded and for errors.
    adsLoader.addAdErrorListener(this);
    adsLoader.addAdsLoadedListener(new AdsLoader.AdsLoadedListener() {

        @Override
        public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {
            // Ads were successfully loaded, so get the AdsManager instance. AdsManager has
            // events for ad playback and errors.
            adsManager = adsManagerLoadedEvent.getAdsManager();
            // Attach event and error event listeners.
            adsManager.addAdErrorListener(PlayerFragment.this);
            adsManager.addAdEventListener(PlayerFragment.this);
            adsManager.init();
        }
    });
    sensorViewModel = ViewModelProviders.of(getActivity()).get(SensorViewModel.class);
    videoDetailViewModel = ViewModelProviders.of(getActivity()).get(VideoDetailViewModel.class);
    if (playerViewModel.isTrailer().getValue()) {
        ImageButton buttonCloseTrailer = getView().findViewById(R.id.buttonCloseTrailer);
        buttonCloseTrailer.setVisibility(View.VISIBLE);
        buttonCloseTrailer.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                stop();
                videoDetailViewModel.onVideoFinished(true);
                playerViewModel.setTrailerVideoId(null);
            }
        });
    }
    setHasOptionsMenu(true);
}
Also used : ImageButton(android.widget.ImageButton) AdsManagerLoadedEvent(com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent) VideoDetailViewModel(com.zype.android.ui.video_details.VideoDetailViewModel) ImageView(android.widget.ImageView) SurfaceView(android.view.SurfaceView) View(android.view.View) AdsLoader(com.google.ads.interactivemedia.v3.api.AdsLoader)

Aggregations

SurfaceView (android.view.SurfaceView)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 AdsLoader (com.google.ads.interactivemedia.v3.api.AdsLoader)1 AdsManagerLoadedEvent (com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent)1 VideoDetailViewModel (com.zype.android.ui.video_details.VideoDetailViewModel)1