Search in sources :

Example 1 with Playlist

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);
            }
        }
    });
}
Also used : Playlist(com.zype.android.Db.Entity.Playlist) NavigationHelper(com.zype.android.ui.NavigationHelper) Video(com.zype.android.Db.Entity.Video) Activity(android.app.Activity) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Example 2 with 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");
}
Also used : HashMap(java.util.HashMap) IZypeApiListener(com.zype.android.zypeapi.IZypeApiListener) ArrayList(java.util.ArrayList) PlaylistsResponse(com.zype.android.zypeapi.model.PlaylistsResponse) ZypeApiResponse(com.zype.android.zypeapi.ZypeApiResponse) Playlist(com.zype.android.Db.Entity.Playlist)

Example 3 with Playlist

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;
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) LiveData(androidx.lifecycle.LiveData) MediatorLiveData(androidx.lifecycle.MediatorLiveData) GalleryRow(com.zype.android.ui.Gallery.Model.GalleryRow) Playlist(com.zype.android.Db.Entity.Playlist) Video(com.zype.android.Db.Entity.Video) Observer(androidx.lifecycle.Observer) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(androidx.annotation.Nullable)

Example 4 with Playlist

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);
}
Also used : Playlist(com.zype.android.Db.Entity.Playlist) ArrayList(java.util.ArrayList) GalleryRow(com.zype.android.ui.Gallery.Model.GalleryRow)

Example 5 with Playlist

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

Aggregations

Playlist (com.zype.android.Db.Entity.Playlist)13 Video (com.zype.android.Db.Entity.Video)7 ArrayList (java.util.ArrayList)7 Gson (com.google.gson.Gson)4 List (java.util.List)4 Type (java.lang.reflect.Type)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 GalleryRow (com.zype.android.ui.Gallery.Model.GalleryRow)2 NavigationHelper (com.zype.android.ui.NavigationHelper)2 IZypeApiListener (com.zype.android.zypeapi.IZypeApiListener)2 ZypeApiResponse (com.zype.android.zypeapi.ZypeApiResponse)2 PlaylistsResponse (com.zype.android.zypeapi.model.PlaylistsResponse)2 HashMap (java.util.HashMap)2 Activity (android.app.Activity)1 Application (android.app.Application)1 TextView (android.widget.TextView)1 Nullable (androidx.annotation.Nullable)1 LiveData (androidx.lifecycle.LiveData)1 MediatorLiveData (androidx.lifecycle.MediatorLiveData)1