Search in sources :

Example 1 with VideoFavoritesResponse

use of com.zype.android.zypeapi.model.VideoFavoritesResponse in project zype-android by zype.

the class DataRepository method loadVideoFavorites.

// Video favorites
public void loadVideoFavorites(IDataLoading listener) {
    deleteVideoFavorites();
    String accessToken = AuthHelper.getAccessToken();
    String consumerId = SettingsProvider.getInstance().getConsumerId();
    ZypeApi.getInstance().getVideoFavorites(accessToken, consumerId, (IZypeApiListener<VideoFavoritesResponse>) response -> {
        if (response.isSuccessful) {
            for (VideoFavoriteData item : response.data.videoFavorites) {
                Video video = getVideoSync(item.videoId);
                if (video == null) {
                    loadVideo(item.videoId, response1 -> {
                        if (response.isSuccessful) {
                            Video dbVideo = getVideoSync(item.videoId);
                            if (dbVideo != null) {
                                dbVideo.isFavorite = 1;
                                updateVideo(dbVideo);
                                FavoriteVideo favoriteVideo = new FavoriteVideo();
                                favoriteVideo.id = item.id;
                                favoriteVideo.videoId = item.videoId;
                                addVideoFavorite(favoriteVideo);
                            }
                        }
                    });
                } else {
                    video.isFavorite = 1;
                    updateVideo(video);
                    FavoriteVideo favoriteVideo = new FavoriteVideo();
                    favoriteVideo.id = item.id;
                    favoriteVideo.videoId = item.videoId;
                    addVideoFavorite(favoriteVideo);
                }
            }
            if (listener != null) {
                listener.onLoadingCompleted(true);
            }
        } else {
            if (listener != null) {
                listener.onLoadingCompleted(false);
            }
        }
    });
}
Also used : VideoFavoritesResponse(com.zype.android.zypeapi.model.VideoFavoritesResponse) LiveData(androidx.lifecycle.LiveData) AdSchedule(com.zype.android.Db.Entity.AdSchedule) TextUtils(android.text.TextUtils) AuthHelper(com.zype.android.Auth.AuthHelper) ZypeDb(com.zype.android.Db.ZypeDb) SettingsProvider(com.zype.android.core.settings.SettingsProvider) VideoResponse(com.zype.android.zypeapi.model.VideoResponse) IZypeApiListener(com.zype.android.zypeapi.IZypeApiListener) ArrayList(java.util.ArrayList) AnalyticBeacon(com.zype.android.Db.Entity.AnalyticBeacon) List(java.util.List) Application(android.app.Application) VideoFavoriteData(com.zype.android.zypeapi.model.VideoFavoriteData) Playlist(com.zype.android.Db.Entity.Playlist) PlaylistVideo(com.zype.android.Db.Entity.PlaylistVideo) VideoEntitlementsResponse(com.zype.android.zypeapi.model.VideoEntitlementsResponse) DbHelper(com.zype.android.Db.DbHelper) Video(com.zype.android.Db.Entity.Video) VideoEntitlementData(com.zype.android.zypeapi.model.VideoEntitlementData) FavoriteVideo(com.zype.android.Db.Entity.FavoriteVideo) ZypeApiResponse(com.zype.android.zypeapi.ZypeApiResponse) ZypeApi(com.zype.android.zypeapi.ZypeApi) VideoFavoriteData(com.zype.android.zypeapi.model.VideoFavoriteData) VideoFavoritesResponse(com.zype.android.zypeapi.model.VideoFavoritesResponse) PlaylistVideo(com.zype.android.Db.Entity.PlaylistVideo) Video(com.zype.android.Db.Entity.Video) FavoriteVideo(com.zype.android.Db.Entity.FavoriteVideo) FavoriteVideo(com.zype.android.Db.Entity.FavoriteVideo)

Aggregations

Application (android.app.Application)1 TextUtils (android.text.TextUtils)1 LiveData (androidx.lifecycle.LiveData)1 AuthHelper (com.zype.android.Auth.AuthHelper)1 DbHelper (com.zype.android.Db.DbHelper)1 AdSchedule (com.zype.android.Db.Entity.AdSchedule)1 AnalyticBeacon (com.zype.android.Db.Entity.AnalyticBeacon)1 FavoriteVideo (com.zype.android.Db.Entity.FavoriteVideo)1 Playlist (com.zype.android.Db.Entity.Playlist)1 PlaylistVideo (com.zype.android.Db.Entity.PlaylistVideo)1 Video (com.zype.android.Db.Entity.Video)1 ZypeDb (com.zype.android.Db.ZypeDb)1 SettingsProvider (com.zype.android.core.settings.SettingsProvider)1 IZypeApiListener (com.zype.android.zypeapi.IZypeApiListener)1 ZypeApi (com.zype.android.zypeapi.ZypeApi)1 ZypeApiResponse (com.zype.android.zypeapi.ZypeApiResponse)1 VideoEntitlementData (com.zype.android.zypeapi.model.VideoEntitlementData)1 VideoEntitlementsResponse (com.zype.android.zypeapi.model.VideoEntitlementsResponse)1 VideoFavoriteData (com.zype.android.zypeapi.model.VideoFavoriteData)1 VideoFavoritesResponse (com.zype.android.zypeapi.model.VideoFavoritesResponse)1