Search in sources :

Example 1 with VideoResponse

use of com.zype.android.zypeapi.model.VideoResponse in project zype-android by zype.

the class VideoDetailViewModel method loadVideo.

// Zype API
/**
 * Make API request for video
 *
 * @param videoId Video id
 */
private void loadVideo(String videoId) {
    Logger.d("loadVideo(): videoId=" + videoId);
    final IZypeApiListener listener = new IZypeApiListener() {

        @Override
        public void onCompleted(ZypeApiResponse response) {
            VideoResponse videoResponse = (VideoResponse) response.data;
            if (response.isSuccessful) {
                Video video = repo.getVideoSync(videoId);
                if (video != null) {
                    video = DbHelper.videoUpdateEntityByApi(video, videoResponse.videoData);
                } else {
                    video = DbHelper.videoApiToEntity(videoResponse.videoData);
                }
                repo.updateVideo(video);
            } else {
            // TODO: Add error handling
            }
        }
    };
    api.getVideo(videoId, false, listener);
// VideoParamsBuilder builder = new VideoParamsBuilder()
// .addVideoId(videoId);
// oldApi.executeRequest(WebApiManager.Request.VIDEO, builder.build());
}
Also used : ZypeApiResponse(com.zype.android.zypeapi.ZypeApiResponse) VideoResponse(com.zype.android.zypeapi.model.VideoResponse) IZypeApiListener(com.zype.android.zypeapi.IZypeApiListener) Video(com.zype.android.Db.Entity.Video)

Example 2 with VideoResponse

use of com.zype.android.zypeapi.model.VideoResponse in project zype-android by zype.

the class MainActivity method switchToLiveVideo.

private void switchToLiveVideo() {
    // show loader
    ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress);
    progressBar.setVisibility(View.VISIBLE);
    ZypeApi zypeApi = ZypeApi.getInstance();
    zypeApi.getVideo(ZypeSettings.LIVE_VIDEO_ID, false, response -> {
        progressBar.setVisibility(View.GONE);
        if (response.isSuccessful) {
            VideoResponse videoResponse = (VideoResponse) response.data;
            DataRepository repo = DataRepository.getInstance(getApplication());
            Video video = repo.getVideoSync(ZypeSettings.LIVE_VIDEO_ID);
            if (video != null) {
                video = DbHelper.videoUpdateEntityByApi(video, videoResponse.videoData);
                repo.updateVideo(video);
            } else {
                video = DbHelper.videoApiToEntity(videoResponse.videoData);
                List<Video> videos = new ArrayList<>();
                videos.add(video);
                repo.insertVideos(videos);
            }
            NavigationHelper.getInstance(this).switchToVideoDetailsScreen(this, video.id, null, false);
        } else {
            UiUtils.showErrorSnackbar(findViewById(R.id.root_view), getString(R.string.live_video_load_error_message));
            if (refreshTab) {
                bottomNavigationView.setSelectedItemId(lastSelectedTabId);
            }
        }
    });
}
Also used : ZypeApi(com.zype.android.zypeapi.ZypeApi) VideoResponse(com.zype.android.zypeapi.model.VideoResponse) Video(com.zype.android.Db.Entity.Video) ArrayList(java.util.ArrayList) DataRepository(com.zype.android.DataRepository) ProgressBar(android.widget.ProgressBar)

Aggregations

Video (com.zype.android.Db.Entity.Video)2 VideoResponse (com.zype.android.zypeapi.model.VideoResponse)2 ProgressBar (android.widget.ProgressBar)1 DataRepository (com.zype.android.DataRepository)1 IZypeApiListener (com.zype.android.zypeapi.IZypeApiListener)1 ZypeApi (com.zype.android.zypeapi.ZypeApi)1 ZypeApiResponse (com.zype.android.zypeapi.ZypeApiResponse)1 ArrayList (java.util.ArrayList)1