Search in sources :

Example 1 with DataRepository

use of com.zype.android.DataRepository in project zype-android by zype.

the class AuthHelper method isVideoUnlocked.

public static boolean isVideoUnlocked(Context context, String videoId, String playlistId) {
    boolean result = true;
    DataRepository repo = DataRepository.getInstance((Application) context.getApplicationContext());
    Video video = repo.getVideoSync(videoId);
    if (video == null) {
        return false;
    }
    List<Playlist> playlists = new ArrayList<>();
    if (TextUtils.isEmpty(playlistId)) {
        Type type = new TypeToken<List<String>>() {
        }.getType();
        List<String> playlistIds = new Gson().fromJson(video.serializedPlaylistIds, type);
        if (playlistIds != null) {
            for (String id : playlistIds) {
                Playlist playlist = repo.getPlaylistSync(id);
                if (playlist != null) {
                    playlists.add(playlist);
                }
            }
        }
    } else {
        Playlist playlist = repo.getPlaylistSync(playlistId);
        if (playlist != null) {
            playlists.add(playlist);
        }
    }
    for (Playlist playlist : playlists) {
        if (playlist.purchaseRequired == 1) {
            if (ZypeConfiguration.isNativeTvodEnabled(context) || ZypeConfiguration.isUniversalTVODEnabled(context)) {
                if (isLoggedIn() && video.isEntitled != null && video.isEntitled == 1) {
                    return true;
                } else {
                    return false;
                }
            } else {
                // Playlist requires purchase, but TVOD monetization options ares turned off in the app configuration
                Logger.w("Playlist " + playlist.id + " requires purchase, but TVOD monetization features " + "are turned off in the app configuration.");
                result = false;
            }
        }
    }
    if (video.registrationRequired == 1) {
        if (!isLoggedIn()) {
            return false;
        }
    }
    if (Integer.valueOf(video.purchaseRequired) == 1) {
        if (ZypeConfiguration.isNativeTvodEnabled(context) || ZypeConfiguration.isUniversalTVODEnabled(context)) {
            if (isLoggedIn() && video.isEntitled != null && Integer.valueOf(video.isEntitled) == 1) {
                return true;
            } else {
                return false;
            }
        } else {
            // Video requires purchase, but TVOD monetization options are turned off in the app configuration
            Logger.w("Video " + videoId + " requires purchase, but TVOD monetization features " + "are turned off in the app configuration.");
            result = false;
        }
    }
    if (Integer.valueOf(video.subscriptionRequired) == 1) {
        if (ZypeConfiguration.isNativeSubscriptionEnabled(context)) {
            if (SubscriptionHelper.hasSubscription()) {
                return true;
            } else {
                return false;
            }
        } else if (ZypeConfiguration.isNativeToUniversalSubscriptionEnabled(context)) {
            if (SubscriptionHelper.hasSubscription()) {
                return true;
            } else {
                return false;
            }
        } else if (ZypeConfiguration.isUniversalSubscriptionEnabled(context)) {
            if (isLoggedIn()) {
                if (SubscriptionHelper.hasSubscription()) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            // Video requires subscription, but NSVOD and USVOD options are turned off
            // in the app configuration
            Logger.w("Video " + videoId + " requires subscription, but subscription features " + "are turned off the app configuration.");
            result = false;
        }
    }
    return result;
}
Also used : Playlist(com.zype.android.Db.Entity.Playlist) Type(java.lang.reflect.Type) Video(com.zype.android.Db.Entity.Video) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) DataRepository(com.zype.android.DataRepository) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with DataRepository

use of com.zype.android.DataRepository 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)

Example 3 with DataRepository

use of com.zype.android.DataRepository in project zype-android by zype.

the class VideoActionsHelper method updateVideoFavorite.

private static void updateVideoFavorite(Application application, Video video, String videoFavoriteId, boolean isFavorite, IVideoActionCallback listener) {
    DataRepository repo = DataRepository.getInstance(application);
    video.isFavorite = (isFavorite) ? 1 : 0;
    repo.updateVideo(video);
    if (isFavorite) {
        if (videoFavoriteId != null) {
            FavoriteVideo favoriteVideo = new FavoriteVideo();
            favoriteVideo.id = videoFavoriteId;
            favoriteVideo.videoId = video.id;
            repo.addVideoFavorite(favoriteVideo);
        }
    } else {
        repo.deleteVideoFavoriteByVideoId(video.id);
    }
    if (listener != null) {
        listener.onActionCompleted(true);
    }
}
Also used : DataRepository(com.zype.android.DataRepository) FavoriteVideo(com.zype.android.Db.Entity.FavoriteVideo)

Aggregations

DataRepository (com.zype.android.DataRepository)3 Video (com.zype.android.Db.Entity.Video)2 ArrayList (java.util.ArrayList)2 ProgressBar (android.widget.ProgressBar)1 Gson (com.google.gson.Gson)1 FavoriteVideo (com.zype.android.Db.Entity.FavoriteVideo)1 Playlist (com.zype.android.Db.Entity.Playlist)1 ZypeApi (com.zype.android.zypeapi.ZypeApi)1 VideoResponse (com.zype.android.zypeapi.model.VideoResponse)1 Type (java.lang.reflect.Type)1 List (java.util.List)1