use of com.zype.android.zypeapi.model.PlaylistsResponse 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.model.PlaylistsResponse 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);
}
Aggregations