use of com.zype.android.zypeapi.model.VideosResponse 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);
}
use of com.zype.android.zypeapi.model.VideosResponse in project zype-android by zype.
the class PlaylistVideosViewModel method loadVideos.
private void loadVideos(final String playlistId) {
updateVideos(new StatefulData<>(null, null, DataState.LOADING));
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) {
repo.insertVideos(result);
repo.deletePlaylistVideos(playlistId);
repo.insertPlaylistVideos(DbHelper.videosToPlaylistVideos(result, playlistId));
updateVideos(new StatefulData<>(repo.getPlaylistVideosSync(playlistId), null, DataState.READY));
} else {
api.getPlaylistVideos(playlistId, videosResponse.pagination.next, this);
}
} else {
if (videosResponse != null) {
updateVideos(new StatefulData<>(null, videosResponse.message, DataState.ERROR));
// errorMessage.setValue(videosResponse.message);
} else {
updateVideos(new StatefulData<>(null, getApplication().getString(R.string.videos_error), DataState.ERROR));
// errorMessage.setValue(getApplication().getString(R.string.videos_error));
}
}
}
};
api.getPlaylistVideos(playlistId, 1, listener);
}
use of com.zype.android.zypeapi.model.VideosResponse 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