use of com.zype.android.Db.Entity.Video in project zype-android by zype.
the class GalleryRowItemsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final GalleryRowItemsAdapter.ViewHolder holder, int position) {
holder.item = items.get(position);
updateTitle(holder);
updateInlineTitle(holder);
loadThumbnail(holder);
updateLockIcon(holder);
holder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NavigationHelper navigationHelper = NavigationHelper.getInstance(holder.view.getContext());
if (holder.item instanceof Video) {
Video video = (Video) holder.item;
navigationHelper.handleVideoClick((Activity) holder.view.getContext(), video, playlistId, false);
} else if (holder.item instanceof Playlist) {
Playlist playlist = (Playlist) holder.item;
navigationHelper.handlePlaylistClick((Activity) holder.view.getContext(), playlist);
}
}
});
}
use of com.zype.android.Db.Entity.Video in project zype-android by zype.
the class GalleryViewModel method getGalleryRows.
public LiveData<List<GalleryRow>> getGalleryRows(String parentPlaylistId) {
if (data == null) {
this.parentPlaylistId = parentPlaylistId;
data = new MediatorLiveData<>();
liveDataPlaylists = getPlaylists(parentPlaylistId);
liveDataVideos = new HashMap<>();
liveDataNestedPlaylists = new HashMap<>();
data.addSource(liveDataPlaylists, new Observer<List<Playlist>>() {
@Override
public void onChanged(@Nullable List<Playlist> playlists) {
Logger.d("onChanged(): Playlists, size=" + playlists.size());
if (!playlists.isEmpty()) {
data.removeSource(liveDataPlaylists);
}
final List<GalleryRow> galleryRows = new ArrayList<>();
for (final Playlist playlist : playlists) {
final GalleryRow row = new GalleryRow(playlist);
// Add video items to the row if playlist contains any video
if (playlist.playlistItemCount > 0) {
LiveData<List<Video>> playlistVideos = liveDataVideos.get(playlist.id);
if (playlistVideos == null) {
playlistVideos = getPlaylistVideos(playlist.id);
liveDataVideos.put(playlist.id, playlistVideos);
data.addSource(playlistVideos, new Observer<List<Video>>() {
@Override
public void onChanged(@Nullable List<Video> videos) {
Logger.d("onChanged(): Videos (" + playlist.title + "), size=" + videos.size());
row.videos = videos;
if (allDataLoaded(galleryRows)) {
data.setValue(galleryRows);
ZypeApp.needToLoadData = false;
}
}
});
}
} else // Otherwise add nested playlists
{
LiveData<List<Playlist>> nestedPlaylists = liveDataNestedPlaylists.get(playlist.id);
if (nestedPlaylists == null) {
nestedPlaylists = getPlaylists(playlist.id);
liveDataNestedPlaylists.put(playlist.id, nestedPlaylists);
data.addSource(nestedPlaylists, new Observer<List<Playlist>>() {
@Override
public void onChanged(@Nullable List<Playlist> playlists) {
Logger.d("onChanged(): Nested playlists (" + playlist.title + "), size=" + playlists.size());
if (playlists.isEmpty()) {
if (playlistApiRequests.containsKey(playlist.id)) {
if (playlistApiRequests.get(playlist.id)) {
Logger.d("onChanged(): Nested playlists (" + playlist.title + "), wait for API response");
} else {
Logger.d("onChanged(): Nested playlists (" + playlist.title + "), row removed");
galleryRows.remove(row);
}
} else {
Logger.d("onChanged(): Nested playlists (" + playlist.title + "), row removed");
galleryRows.remove(row);
}
} else {
row.nestedPlaylists = playlists;
playlistApiRequests.remove(playlist.id);
}
if (allDataLoaded(galleryRows)) {
data.setValue(galleryRows);
ZypeApp.needToLoadData = false;
}
}
});
}
}
galleryRows.add(row);
}
data.setValue(galleryRows);
}
});
}
return data;
}
use of com.zype.android.Db.Entity.Video in project zype-android by zype.
the class HeroImagesViewModel method handleVideo.
/**
* Handles API request for playlist
*
* @param event Response event
*/
@Subscribe
public void handleVideo(VideoEvent event) {
Logger.d("handleVideo()");
VideoData data = event.getEventData().getModelData().getVideoData();
Video video = DbHelper.videoDataToVideoEntity(data);
if (video != null) {
List<Video> videosList = Arrays.asList(video);
repo.insertVideos(videosList);
}
}
use of com.zype.android.Db.Entity.Video in project zype-android by zype.
the class NavigationHelper method handleNotAuthorizedVideo.
public void handleNotAuthorizedVideo(Activity activity, String videoId, String playlistId) {
Video video = DataRepository.getInstance((Application) context.getApplicationContext()).getVideoSync(videoId);
Bundle extras = new Bundle();
extras.putString(BundleConstants.VIDEO_ID, videoId);
extras.putString(BundleConstants.PLAYLIST_ID, playlistId);
if (video == null) {
Logger.e("handleNotAuthorizedVideo(): Error get video, videoId=" + videoId);
return;
}
if (Integer.valueOf(video.subscriptionRequired) == 1) {
if (ZypeConfiguration.isNativeSubscriptionEnabled(activity)) {
switchToSubscriptionScreen(activity, extras);
} else if (ZypeConfiguration.isUniversalSubscriptionEnabled(activity)) {
if (AuthHelper.isLoggedIn()) {
DialogHelper.showSubscriptionAlertIssue(activity);
} else {
DialogHelper.showLoginAlert(activity);
}
} else if (ZypeConfiguration.isNativeToUniversalSubscriptionEnabled(activity)) {
if (AuthHelper.isLoggedIn()) {
List<Purchase> purchases = ZypeApp.marketplaceGateway.getBillingManager().getPurchases();
if (purchases != null && purchases.size() > 0) {
switchToSubscribeOrLoginScreen(activity, extras);
} else {
switchToSubscriptionScreen(activity, extras);
}
} else {
switchToSubscribeOrLoginScreen(activity, extras);
}
} else {
DialogHelper.showAlert(activity, context.getString(R.string.dialog_update_app_title), context.getString(R.string.dialog_update_app_message));
}
} else if (video.registrationRequired == 1) {
if (!AuthHelper.isLoggedIn()) {
switchToUnauthorizedUserScreen(activity, extras);
}
}
}
use of com.zype.android.Db.Entity.Video 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;
}
Aggregations