1 package com.moiseum.wolnelektury.base;
3 import android.util.Log;
5 import com.moiseum.wolnelektury.connection.RestClientCallback;
7 import javax.annotation.Nullable;
15 public abstract class DataProvider<T, S> extends RestClientCallback<T, S> {
17 private final static String TAG = DataProvider.class.getSimpleName();
19 protected DataObserver<T> dataObserver;
20 protected String lastKeySlug = null;
23 public DataProvider() {
26 public void setDataObserver(DataObserver<T> dataObserver) {
27 this.dataObserver = dataObserver;
31 public void onSuccess(T data) {
32 if (dataObserver != null) {
33 dataObserver.onLoadSuccess(data);
38 public void onFailure(Exception e) {
39 Log.e(TAG, "Failed to load data", e);
40 if (dataObserver != null) {
41 dataObserver.onLoadFailed(e);
46 public void onCancel() {
51 * Invoked in order to load data.
52 * @param lastKey Last book slug for pagination. Can be null if there is no pagination.
54 public void load(@Nullable String lastKey) {
56 lastKeySlug = lastKey;
57 call = WLApplication.getInstance().getRestClient().call(this, getServiceClass());
58 if (dataObserver != null) {
59 dataObserver.onLoadStarted();
63 public void cancel() {
70 public void release() {
74 protected abstract Class<S> getServiceClass();