private void subscribeToModel()

in LeanbackShowcase/app/src/main/java/androidx/leanback/leanbackshowcase/app/room/controller/detail/LiveDataDetailViewWithVideoBackgroundFragment.java [195:254]


    private void subscribeToModel(final VideosViewModel model) {
        // Update video Id (live data) and the ui will be updated automatically.
        model.setVideoId(mSelectedVideoId);

        model.getVideoById().observe((LifecycleOwner) getActivity(), new Observer<VideoEntity>() {
            @Override
            public void onChanged(@Nullable VideoEntity videoEntity) {
                if (videoEntity != null) {

                    mObservedVideo = videoEntity;
                    mDetailsBgController.setupVideoPlayback(mVideoGlue);

                    // different loading strategy based on whether the video is rented or not
                    if (!videoEntity.isRented()) {
                        mActionAdapter.clear();
                        mActionAdapter.add(mActionRent);
                        mActionAdapter.add(mActionPreview);

                        mVideoGlue.setTitle(mObservedVideo.getTitle().concat(TRAILER_VIDEO));
                        mVideoGlue.setVideoUrl(findLocalContentUriOrNetworkUrl(TRAILER));
                    } else {
                        getActivity().findViewById(R.id.renting_progressbar)
                                .setVisibility(View.GONE);
                        getActivity().findViewById(R.id.loading_renting).setVisibility(View.GONE);

                        mActionAdapter.clear();
                        mActionAdapter.add(mActionPlay);

                        mVideoGlue.setTitle(mObservedVideo.getTitle().concat(RENTED_VIDEO));
                        mVideoGlue.setVideoUrl(findLocalContentUriOrNetworkUrl(VIDEO));
                    }

                    mDescriptionOverviewRow.setItem(mObservedVideo);
                    loadAndSetVideoCardImage();
                    model.setCategory(mObservedVideo.getCategory());
                }
            }
        });

        model.getVideosInSameCategory()
                .observe((LifecycleOwner) getActivity(), new Observer<List<VideoEntity>>() {
                    @Override
                    public void onChanged(@Nullable List<VideoEntity> videoEntities) {
                        if (videoEntities != null) {
                            mRelatedRowAdapter
                                    .setItems(videoEntities, new Comparator<VideoEntity>() {
                                        @Override
                                        public int compare(VideoEntity o1, VideoEntity o2) {
                                            return o1.getId() == o2.getId() ? 0 : -1;
                                        }
                                    }, new Comparator<VideoEntity>() {
                                        @Override
                                        public int compare(VideoEntity o1, VideoEntity o2) {
                                            return o1.equals(o2) ? 0 : -1;
                                        }
                                    });
                        }
                    }
                });
    }