use of com.zype.android.zypeapi.IZypeApiListener 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");
}
use of com.zype.android.zypeapi.IZypeApiListener 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.zypeapi.IZypeApiListener in project zype-android by zype.
the class VideoDetailViewModel method loadVideo.
// Zype API
/**
* Make API request for video
*
* @param videoId Video id
*/
private void loadVideo(String videoId) {
Logger.d("loadVideo(): videoId=" + videoId);
final IZypeApiListener listener = new IZypeApiListener() {
@Override
public void onCompleted(ZypeApiResponse response) {
VideoResponse videoResponse = (VideoResponse) response.data;
if (response.isSuccessful) {
Video video = repo.getVideoSync(videoId);
if (video != null) {
video = DbHelper.videoUpdateEntityByApi(video, videoResponse.videoData);
} else {
video = DbHelper.videoApiToEntity(videoResponse.videoData);
}
repo.updateVideo(video);
} else {
// TODO: Add error handling
}
}
};
api.getVideo(videoId, false, listener);
// VideoParamsBuilder builder = new VideoParamsBuilder()
// .addVideoId(videoId);
// oldApi.executeRequest(WebApiManager.Request.VIDEO, builder.build());
}
use of com.zype.android.zypeapi.IZypeApiListener 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.zypeapi.IZypeApiListener in project zype-android by zype.
the class SearchViewModel method loadSearchResult.
private void loadSearchResult(String query, String playlistId) {
final List<Video> result = new ArrayList<>();
final IZypeApiListener listener = new IZypeApiListener() {
@Override
public void onCompleted(ZypeApiResponse response) {
VideosResponse videosResponse = (VideosResponse) response.data;
if (response.isSuccessful) {
for (com.zype.android.zypeapi.model.VideoData item : videosResponse.videoData) {
Video video = repo.getVideoSync(item.id);
if (video != null) {
result.add(DbHelper.videoUpdateEntityByApi(video, item));
} else {
result.add(DbHelper.videoApiToEntity(item));
}
}
if (videosResponse.pagination.current == videosResponse.pagination.pages || videosResponse.pagination.pages == 0) {
repo.insertVideos(result);
updateVideos(new StatefulData<>(result, null, DataState.READY));
} else {
api.searchVideos(query, playlistId, videosResponse.pagination.next, this);
}
} else {
if (videosResponse != null) {
updateVideos(new StatefulData<>(null, videosResponse.message, DataState.ERROR));
} else {
updateVideos(new StatefulData<>(null, getApplication().getString(R.string.videos_error), DataState.ERROR));
}
}
}
};
api.searchVideos(query, playlistId, 1, listener);
}
Aggregations