use of com.zype.android.Db.Entity.Playlist 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.Playlist in project zype-android by zype.
the class GalleryViewModel method loadRootPlaylists.
private void loadRootPlaylists() {
Logger.d("loadRootPlaylists(): parentPlaylistId=" + parentPlaylistId);
final List<Playlist> result = new ArrayList<>();
Map<String, String> parameters = new HashMap<>();
parameters.put(ZypeApi.PER_PAGE, String.valueOf(100));
final IZypeApiListener listener = new IZypeApiListener() {
@Override
public void onCompleted(ZypeApiResponse response) {
PlaylistsResponse playlistsResponse = (PlaylistsResponse) response.data;
if (playlistsResponse != null && response.isSuccessful) {
for (com.zype.android.zypeapi.model.PlaylistData item : playlistsResponse.response) {
Playlist playlist = repo.getPlaylistSync(item.id);
if (playlist != null) {
result.add(DbHelper.playlistUpdateEntityByApi(playlist, item));
} else {
result.add(DbHelper.playlistApiToEntity(item));
}
}
if (playlistsResponse.pagination.current >= playlistsResponse.pagination.pages) {
repo.insertPlaylists(result);
createGalleryRows();
Logger.d("loadRootPlaylists(): size=" + result.size());
} else {
api.getPlaylists(parentPlaylistId, playlistsResponse.pagination.next, parameters, this);
Logger.d("loadRootPlaylists(): page=" + playlistsResponse.pagination.next);
}
} else {
// TODO: Handle api response error
if (playlistsResponse != null) {
// errorMessage.setValue(videosResponse.message);
} else {
// errorMessage.setValue(getApplication().getString(R.string.videos_error));
}
}
}
};
api.getPlaylists(parentPlaylistId, 1, parameters, listener);
Logger.d("loadRootPlaylists(): page=1");
}
use of com.zype.android.Db.Entity.Playlist 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.Playlist in project zype-android by zype.
the class GalleryViewModel method createGalleryRows.
private void createGalleryRows() {
List<GalleryRow> rows = new ArrayList<>();
List<Playlist> rootPlaylists = repo.getPlaylistsSync(parentPlaylistId);
for (Playlist playlist : rootPlaylists) {
GalleryRow row = new GalleryRow(playlist);
if (playlist.playlistItemCount > 0) {
row.videos = repo.getPlaylistVideosSync(playlist.id);
if (row.videos.isEmpty()) {
row.state = LOADING;
} else {
row.state = READY;
}
loadRowVideos(row);
} else {
row.nestedPlaylists = repo.getPlaylistsSync(playlist.id);
if (row.nestedPlaylists.isEmpty()) {
row.state = LOADING;
} else {
row.state = READY;
}
loadRowPlaylists(row);
}
rows.add(row);
}
galleryRowsState = CREATED;
updateGalleryRows(rows);
}
use of com.zype.android.Db.Entity.Playlist 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