Search in sources :

Example 1 with FavoriteVideo

use of com.zype.android.Db.Entity.FavoriteVideo 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)

Example 2 with FavoriteVideo

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

the class VideoActionsHelper method onUnfavorite.

public static void onUnfavorite(Video video, Application application, IVideoActionCallback listener) {
    if (AuthHelper.isLoggedIn()) {
        String accessToken = AuthHelper.getAccessToken();
        String consumerId = SettingsProvider.getInstance().getConsumerId();
        FavoriteVideo favoriteVideo = DataRepository.getInstance(application).getVideoFavoriteByVideoId(video.id);
        if (favoriteVideo != null) {
            ZypeApi.getInstance().removeVideoFavorite(accessToken, consumerId, favoriteVideo.id, new IZypeApiListener() {

                @Override
                public void onCompleted(ZypeApiResponse response) {
                    if (response.isSuccessful) {
                        updateVideoFavorite(application, video, favoriteVideo.id, false, listener);
                    }
                }
            });
        } else {
            updateVideoFavorite(application, video, null, false, listener);
        }
    } else {
        if (ZypeApp.get(application).getAppConfiguration().hideFavoritesActionWhenSignedOut) {
            if (listener != null) {
                listener.onActionCompleted(false);
            }
        // NavigationHelper.getInstance(activity).switchToLoginScreen(activity);
        } else {
            updateVideoFavorite(application, video, null, false, listener);
        }
    }
}
Also used : ZypeApiResponse(com.zype.android.zypeapi.ZypeApiResponse) IZypeApiListener(com.zype.android.zypeapi.IZypeApiListener) FavoriteVideo(com.zype.android.Db.Entity.FavoriteVideo)

Example 3 with FavoriteVideo

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

the class VideoActionsHelper method updateVideoFavorite.

private static void updateVideoFavorite(Application application, Video video, String videoFavoriteId, boolean isFavorite, IVideoActionCallback listener) {
    DataRepository repo = DataRepository.getInstance(application);
    video.isFavorite = (isFavorite) ? 1 : 0;
    repo.updateVideo(video);
    if (isFavorite) {
        if (videoFavoriteId != null) {
            FavoriteVideo favoriteVideo = new FavoriteVideo();
            favoriteVideo.id = videoFavoriteId;
            favoriteVideo.videoId = video.id;
            repo.addVideoFavorite(favoriteVideo);
        }
    } else {
        repo.deleteVideoFavoriteByVideoId(video.id);
    }
    if (listener != null) {
        listener.onActionCompleted(true);
    }
}
Also used : DataRepository(com.zype.android.DataRepository) FavoriteVideo(com.zype.android.Db.Entity.FavoriteVideo)

Example 4 with FavoriteVideo

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

the class DataRepository method deleteVideoFavorites.

public void deleteVideoFavorites() {
    List<FavoriteVideo> favoriteVideos = db.zypeDao().getVideoFavorites();
    for (FavoriteVideo item : favoriteVideos) {
        Video video = getVideoSync(item.videoId);
        if (video != null) {
            video.isFavorite = 0;
            updateVideo(video);
        }
    }
    db.zypeDao().deleteVideoFavorites();
}
Also used : 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

FavoriteVideo (com.zype.android.Db.Entity.FavoriteVideo)4 PlaylistVideo (com.zype.android.Db.Entity.PlaylistVideo)2 Video (com.zype.android.Db.Entity.Video)2 IZypeApiListener (com.zype.android.zypeapi.IZypeApiListener)2 ZypeApiResponse (com.zype.android.zypeapi.ZypeApiResponse)2 Application (android.app.Application)1 TextUtils (android.text.TextUtils)1 LiveData (androidx.lifecycle.LiveData)1 AuthHelper (com.zype.android.Auth.AuthHelper)1 DataRepository (com.zype.android.DataRepository)1 DbHelper (com.zype.android.Db.DbHelper)1 AdSchedule (com.zype.android.Db.Entity.AdSchedule)1 AnalyticBeacon (com.zype.android.Db.Entity.AnalyticBeacon)1 Playlist (com.zype.android.Db.Entity.Playlist)1 ZypeDb (com.zype.android.Db.ZypeDb)1 SettingsProvider (com.zype.android.core.settings.SettingsProvider)1 ZypeApi (com.zype.android.zypeapi.ZypeApi)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