Skip to content

Instantly share code, notes, and snippets.

@tpakis
Last active May 4, 2019 20:50
Show Gist options
  • Save tpakis/2b1f5f8b43357b83a39770753c1b2709 to your computer and use it in GitHub Desktop.
Save tpakis/2b1f5f8b43357b83a39770753c1b2709 to your computer and use it in GitHub Desktop.
/*
* Copyright (C) 2017 The Android Open Source Project
*/
//a generic wrapper class that describes a data with a status
public class Resource<T> {
@NonNull
public final Status status;
@Nullable
public final T data;
@Nullable public final String message;
private Resource(@NonNull Status status, @Nullable T data, @Nullable String message) {
this.status = status;
this.data = data;
this.message = message;
}
public static <T> Resource<T> success(@NonNull T data) {
return new Resource<>(Status.SUCCESS, data, null);
}
public static <T> Resource<T> error(String msg, @Nullable T data) {
return new Resource<>(Status.ERROR, data, msg);
}
public static <T> Resource<T> loading(@Nullable T data) {
return new Resource<>(Status.LOADING, data, null);
}
}
@udoyen
Copy link

udoyen commented May 4, 2019

Which of the android Status class is this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment