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;
}
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);
}
}
});
}
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);
}
}
Aggregations