hope you are not having a bad day.:D
I am retrieving posts from the server with pagination which I have done smoothly using Paging Library
.
The user can like the post or follow the poster, my problem is that I want to handle the 'follow' or 'like' network API calls knowing the data status -loading, success, or error- at each post inside the PagedList
that are viewed by the PagedListAdapter
.
I am using the Resource class from Google App Architecture Guide.
public class Resource<T> {
private final DataStatus status;
private T data;
private ErrorStatus errorStatus;
public Resource(DataStatus status) {
this.status = status;
}
private Resource(DataStatus status, T data) {
this.status = status;
this.data = data;
}
private Resource(DataStatus status, ErrorStatus errorStatus, T data) {
this.status = status;
this.data = data;
this.errorStatus = errorStatus;
}
public T getData() {
return data;
}
public DataStatus getStatus() {
return status;
}
static <T> Resource<T> loading(T data) {
return new Resource<T>(DataStatus.LOADING, data);
}
public static <T> Resource<T> success(T data) {
return new Resource<>(DataStatus.SUCCESS, data);
}
static <T> Resource<T> error(ErrorStatus errorStatus, T data) {
return new Resource<>(DataStatus.ERROR, errorStatus, data);
}
}
Thanks a lot.