use of com.zype.android.zypeapi.ZypeApiResponse 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);
}
use of com.zype.android.zypeapi.ZypeApiResponse in project zype-android by zype.
the class GalleryViewModel method loadRowVideos.
private void loadRowVideos(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) {
VideosResponse videosResponse = (VideosResponse) response.data;
if (response.isSuccessful && videosResponse != null) {
List<Video> result = new ArrayList<>();
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));
}
}
repo.insertVideos(result);
if (videosResponse.pagination.current == 1) {
repo.deletePlaylistVideos(row.playlist.id);
}
repo.insertPlaylistVideos(result, row.playlist);
row.videos = repo.getPlaylistVideosSync(row.playlist.id);
if (videosResponse.pagination.current >= videosResponse.pagination.pages) {
row.pageToLoad = -1;
row.state = UPDATED;
} else {
row.pageToLoad = videosResponse.pagination.next;
row.state = READY;
api.getPlaylistVideos(row.playlist.id, row.pageToLoad, parameters, this);
Logger.d("loadRowVideos(): page=" + videosResponse.pagination.next);
}
updateGalleryRows(null);
} else {
// TODO: Handle api response error
if (videosResponse != null) {
// errorMessage.setValue(videosResponse.message);
} else {
// errorMessage.setValue(getApplication().getString(R.string.videos_error));
}
}
}
};
api.getPlaylistVideos(row.playlist.id, row.pageToLoad, parameters, listener);
Logger.d("loadRowVideos(): page=" + row.pageToLoad);
}
Aggregations