Search in sources :

Example 11 with Playlist

use of com.zype.android.Db.Entity.Playlist in project zype-android by zype.

the class GalleryRowItemsAdapter method loadThumbnail.

private void loadThumbnail(ViewHolder holder) {
    if (holder.item instanceof Video) {
        Video video = (Video) holder.item;
        boolean thumbnailAssigned = false;
        if (usePoster && video.images != null) {
            Image posterThumbnail = VideoHelper.getPosterThumbnail(video);
            if (posterThumbnail != null) {
                thumbnailAssigned = true;
                UiUtils.loadImage(posterThumbnail.getUrl(), R.drawable.placeholder_video, holder.imageThumbnail);
            }
        }
        if (video.thumbnails != null && !thumbnailAssigned) {
            Thumbnail thumbnail = VideoHelper.getThumbnailByHeight(video, 240);
            if (thumbnail != null) {
                UiUtils.loadImage(thumbnail.getUrl(), R.drawable.placeholder_video, holder.imageThumbnail);
            } else {
                holder.imageThumbnail.setImageDrawable(ContextCompat.getDrawable(holder.view.getContext(), R.drawable.placeholder_video));
            }
        }
    } else if (holder.item instanceof Playlist) {
        Playlist playlist = (Playlist) holder.item;
        boolean thumbnailAssigned = false;
        if (usePoster && playlist.images != null) {
            Image posterThumbnail = VideoHelper.getPosterThumbnail(playlist);
            if (posterThumbnail != null) {
                thumbnailAssigned = true;
                UiUtils.loadImage(posterThumbnail.getUrl(), R.drawable.outline_video_library_white_48, holder.imageThumbnail);
            }
        }
        if (playlist.thumbnails != null && !thumbnailAssigned) {
            Type thumbnailType = new TypeToken<List<Thumbnail>>() {
            }.getType();
            List<Thumbnail> thumbnails = new Gson().fromJson(playlist.thumbnails, thumbnailType);
            Thumbnail thumbnail = VideoHelper.getThumbnailByHeight(thumbnails, 240);
            if (thumbnail != null) {
                UiUtils.loadImage(thumbnail.getUrl(), R.drawable.outline_video_library_white_48, holder.imageThumbnail);
            } else {
                holder.imageThumbnail.setImageDrawable(ContextCompat.getDrawable(holder.view.getContext(), R.drawable.outline_video_library_white_48));
            }
        }
    }
}
Also used : Playlist(com.zype.android.Db.Entity.Playlist) Type(java.lang.reflect.Type) Video(com.zype.android.Db.Entity.Video) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) ArrayList(java.util.ArrayList) List(java.util.List) Image(com.zype.android.webapi.model.video.Image) Thumbnail(com.zype.android.webapi.model.video.Thumbnail)

Example 12 with Playlist

use of com.zype.android.Db.Entity.Playlist in project zype-android by zype.

the class GalleryViewModel method loadRowPlaylists.

private void loadRowPlaylists(GalleryRow row) {
    row.pageToLoad = 1;
    Map<String, String> parameters = new HashMap<>();
    parameters.put(ZypeApi.PER_PAGE, String.valueOf(10));
    final IZypeApiListener listener = new IZypeApiListener() {

        @Override
        public void onCompleted(ZypeApiResponse response) {
            PlaylistsResponse playlistsResponse = (PlaylistsResponse) response.data;
            if (response.isSuccessful) {
                List<Playlist> result = new ArrayList<>();
                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));
                    }
                }
                repo.insertPlaylists(result);
                row.nestedPlaylists = repo.getPlaylistsSync(row.playlist.id);
                if (playlistsResponse.pagination.current >= playlistsResponse.pagination.pages) {
                    row.pageToLoad = -1;
                    row.state = UPDATED;
                } else {
                    row.pageToLoad = playlistsResponse.pagination.next;
                    row.state = READY;
                    api.getPlaylists(row.playlist.id, row.pageToLoad, parameters, this);
                    Logger.d("loadRowPlaylists(): page=" + playlistsResponse.pagination.next);
                }
                updateGalleryRows(null);
            } else {
                // TODO: Handle api response error
                if (playlistsResponse != null) {
                // errorMessage.setValue(videosResponse.message);
                } else {
                // errorMessage.setValue(getApplication().getString(R.string.videos_error));
                }
            }
        }
    };
    api.getPlaylists(row.playlist.id, row.pageToLoad, parameters, listener);
    Logger.d("loadRowPlaylists(): page=" + row.pageToLoad);
}
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 13 with Playlist

use of com.zype.android.Db.Entity.Playlist in project zype-android by zype.

the class HeroImageFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_hero_image, container, false);
    final NavigationHelper navigationHelper = NavigationHelper.getInstance(getActivity());
    ImageView imageHero = rootView.findViewById(R.id.imageHero);
    UiUtils.loadImage(getActivity(), imageUrl, imageHero);
    imageHero.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(videoId)) {
                Video video = DataRepository.getInstance(getActivity().getApplication()).getVideoSync(videoId);
                if (video == null || video.active != 1) {
                    DialogHelper.showErrorAlert(getActivity(), getString(R.string.gallery_hero_image_error_video));
                } else {
                    navigationHelper.handleVideoClick(getActivity(), video, null, false);
                }
            } else if (!TextUtils.isEmpty(playlistId)) {
                Playlist playlist = DataRepository.getInstance(getActivity().getApplication()).getPlaylistSync(playlistId);
                if (playlist == null || playlist.active != 1) {
                    DialogHelper.showErrorAlert(getActivity(), getString(R.string.gallery_hero_image_error_playlist));
                } else {
                    navigationHelper.handlePlaylistClick(getActivity(), playlist);
                }
            }
        }
    });
    return rootView;
}
Also used : Playlist(com.zype.android.Db.Entity.Playlist) NavigationHelper(com.zype.android.ui.NavigationHelper) Video(com.zype.android.Db.Entity.Video) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View)

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