public class NetworkResponse<E>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
NetworkResponse.DialogTapListener |
Modifier and Type | Field and Description |
---|---|
private boolean |
fail
Whether or not the network task failed.
|
private boolean |
isAuthFailed
Indicates that the operation failed due to an authentication issue.
|
private int |
messageID
String reference ID of message describing the error.
|
private E |
payload
Object returned by the network task.
|
private static java.lang.String |
TAG
Tag to use for log statements.
|
Constructor and Description |
---|
NetworkResponse(boolean inFail)
Constructor that creates a generic message based on "inFail"
|
NetworkResponse(boolean inFail,
E inPayload)
Constructor that both stores a payload and sets the failure state from parameters
|
NetworkResponse(boolean inFail,
E inPayload,
int messageID)
Constructor that both stores a payload and sets the failure state from parameters
|
NetworkResponse(boolean inFail,
int inMessageID)
Constructor that sets message and failures state based on arguments
|
NetworkResponse(E inPayload)
Constructor that stores a payload and sets the failure state to false
|
NetworkResponse(NetworkResponse<?> toConvert)
Create a new NetworkResponse of the type designated in
<> from another NetworkResponse
of any other type. |
Modifier and Type | Method and Description |
---|---|
boolean |
fail()
Check whether the network request failed
|
static AlertDialog |
genErrorDialog(android.content.Context context,
int messageID)
Get an error dialog that can be displayed to the user
|
static AlertDialog |
genErrorDialog(android.content.Context context,
int messageID,
boolean authFail,
NetworkResponse.DialogTapListener mListener)
Get an error dialog that can be displayed to the user
|
static AlertDialog |
genErrorDialog(android.content.Context context,
int messageID,
NetworkResponse.DialogTapListener listener)
Get an error dialog that can be displayed to the user
|
static AlertDialog |
genSuccessDialog(android.content.Context context,
int messageID)
Get a confirmation dialog that can be displayed to the user to reflect a successful operation
|
static NetworkResponse<API.Get.LoginResponse> |
getAuthFailed(int messageID)
Get a NetworkResponse object with
isAuthFailed is true . |
AlertDialog |
getErrorDialog(android.content.Context context,
NetworkResponse.DialogTapListener listener)
Get an error dialog that can be displayed to show message from messageID to user
|
int |
getMessageID()
Get the resource ID of the message to display to the user
|
E |
getPayload()
Get the payload returned by the network operation
|
boolean |
isAuthFailed()
Get whether the current object represents a failed authentication
|
private java.lang.String |
payloadName(E payload)
Get a
String describing the provided payload |
private java.lang.String |
payloadType(E payload)
Get a
String describing the type of the provided payload |
void |
setAuthFailed(boolean isAuthFailed)
Set whether the current object represents a failed authentication
|
void |
showErrorDialog(android.content.Context context)
Show an error dialog that can be displayed to show message from messageID to user
|
void |
showErrorDialog(android.content.Context context,
NetworkResponse.DialogTapListener listener)
Show an error dialog that can be displayed to show message from messageID to user
|
java.lang.String |
toString()
Get a String representation of the object that conveys the current state of all instance fields
|
private static final java.lang.String TAG
private boolean fail
private int messageID
private E payload
private boolean isAuthFailed
public NetworkResponse(NetworkResponse<?> toConvert)
<>
from another NetworkResponse
of any other type. Any payload in the source object will not be transferred to the created one.
All other fields are copied.toConvert
- Source to create new object from. All properties except payload will be
copied.public NetworkResponse(boolean inFail)
inFail
- Failure state provided by user (true if failed)public NetworkResponse(boolean inFail, int inMessageID)
inFail
- Failure state provided by user (true if failed)inMessageID
- ID for string resource containing messagepublic NetworkResponse(E inPayload)
inPayload
- Payload returned by networking requestpublic NetworkResponse(boolean inFail, E inPayload)
inFail
- Whether or not the network operation failedinPayload
- Payload returned by networking requestpublic NetworkResponse(boolean inFail, E inPayload, int messageID)
inFail
- Whether or not the network operation failedinPayload
- Payload returned by networking requestprivate java.lang.String payloadType(E payload)
String
describing the type of the provided payloadpayload
- Payload whose type will be described. Can be null.null
if the payload is null, the name of the payload's class otherwiseprivate java.lang.String payloadName(E payload)
String
describing the provided payloadpayload
- Payload which will be described. Can be null.null
if the payload is null, the payload.toString()
otherwise.public static NetworkResponse<API.Get.LoginResponse> getAuthFailed(int messageID)
isAuthFailed
is true
. This
means that when the user dismisses the error dialog generated by
getErrorDialog(Context, DialogTapListener)
or
showErrorDialog(Context)
, LoginActivity
will be launched.messageID
- String reference to the message describing the error. Will be shown to userpublic boolean isAuthFailed()
true
if object represents an authentication failure, false
otherwisepublic void setAuthFailed(boolean isAuthFailed)
isAuthFailed
- true
if object represents an authentication failure, false
otherwisepublic boolean fail()
public int getMessageID()
public AlertDialog getErrorDialog(android.content.Context context, NetworkResponse.DialogTapListener listener)
context
- Context upon which to display error dialog (Should be someClass.this
)listener
- A NetworkResponse.DialogTapListener
to be called when they dismiss the dialog.public static AlertDialog genErrorDialog(android.content.Context context, int messageID)
context
- Context upon which to display error dialog (Should be someClass.this
)messageID
- String resource ID of message to displayAlertDialog
with specified alert message.public static AlertDialog genErrorDialog(android.content.Context context, int messageID, NetworkResponse.DialogTapListener listener)
context
- Context upon which to display error dialog (Should be someClass.this
)messageID
- String resource ID of message to displaylistener
- A NetworkResponse.DialogTapListener
for when the user dismisses the dialog.AlertDialog
with specified alert message.public static AlertDialog genErrorDialog(android.content.Context context, int messageID, boolean authFail, NetworkResponse.DialogTapListener mListener)
context
- Context upon which to display error dialog (Should be someClass.this
)messageID
- String resource ID of message to displayauthFail
- Whether or not the user should be directed to LoginActivity
upon
dismissing the dialogmListener
- A NetworkResponse.DialogTapListener
for when the user dismisses the dialog.AlertDialog
with specified alert message and which directs the user to
LoginActivity
upon dismissal if authFail
is true.public static AlertDialog genSuccessDialog(android.content.Context context, int messageID)
context
- Context upon which to display dialog (Should be someClass.this
)messageID
- String resource ID of message to displayAlertDialog
with specified alert messagepublic void showErrorDialog(android.content.Context context, NetworkResponse.DialogTapListener listener)
context
- Context upon which to display error dialoglistener
- A NetworkResponse.DialogTapListener
object which allows you control behavior
after they dismiss the dialog.public void showErrorDialog(android.content.Context context)
context
- Context upon which to display error dialogpublic E getPayload()
public java.lang.String toString()
toString
in class java.lang.Object
NetworkResponse<?>[field1=value1, ...]