Last active
May 4, 2019 20:50
-
-
Save tpakis/2b1f5f8b43357b83a39770753c1b2709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Which of the android Status class is this?