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