Search in sources :

Example 1 with ZypeApi

use of com.zype.android.zypeapi.ZypeApi 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

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