NetworkResponse

public class NetworkResponse<E>

Class to store responses after attempting networking tasks

Constructors

NetworkResponse

public NetworkResponse(NetworkResponse<?> toConvert)

Create a new NetworkResponse of the type designated in <> 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.

Parameters:
  • toConvert – Source to create new object from. All properties except payload will be copied.

NetworkResponse

public NetworkResponse(boolean inFail)

Constructor that creates a generic message based on “inFail”

Parameters:
  • inFail – Failure state provided by user (true if failed)

NetworkResponse

public NetworkResponse(boolean inFail, int inMessageID)

Constructor that sets message and failures state based on arguments

Parameters:
  • inFail – Failure state provided by user (true if failed)
  • inMessageID – ID for string resource containing message

NetworkResponse

public NetworkResponse(E inPayload)

Constructor that stores a payload and sets the failure state to false

Parameters:
  • inPayload – Payload returned by networking request

NetworkResponse

public NetworkResponse(boolean inFail, E inPayload)

Constructor that both stores a payload and sets the failure state from parameters

Parameters:
  • inFail – Whether or not the network operation failed
  • inPayload – Payload returned by networking request

NetworkResponse

public NetworkResponse(boolean inFail, E inPayload, int messageID)

Constructor that both stores a payload and sets the failure state from parameters

Parameters:
  • inFail – Whether or not the network operation failed
  • inPayload – Payload returned by networking request

Methods

fail

public boolean fail()

Check whether the network request failed

Returns:true if the request failed, false if it succeeded

genErrorDialog

public static AlertDialog genErrorDialog(Context context, int messageID)

Get an error dialog that can be displayed to the user

Parameters:
  • context – Context upon which to display error dialog (Should be someClass.this)
  • messageID – String resource ID of message to display
Returns:

AlertDialog with specified alert message.

genErrorDialog

public static AlertDialog genErrorDialog(Context context, int messageID, boolean authFail)

Get an error dialog that can be displayed to the user

Parameters:
  • context – Context upon which to display error dialog (Should be someClass.this)
  • messageID – String resource ID of message to display
  • authFail – Whether or not the user should be directed to LoginActivity upon dismissing the dialog
Returns:

AlertDialog with specified alert message and which directs the user to LoginActivity upon dismissal if authFail is true.

genSuccessDialog

public static AlertDialog genSuccessDialog(Context context, int messageID)

Get a confirmation dialog that can be displayed to the user to reflect a successful operation

Parameters:
  • context – Context upon which to display dialog (Should be someClass.this)
  • messageID – String resource ID of message to display
Returns:

AlertDialog with specified alert message

getAuthFailed

public static NetworkResponse<API.Get.LoginResponse> getAuthFailed(int messageID)

Get a NetworkResponse object with NetworkResponse.isAuthFailed is true. This means that when the user dismisses the error dialog generated by NetworkResponse.getErrorDialog(Context) or NetworkResponse.showErrorDialog(Context), LoginActivity will be launched.

Parameters:
  • messageID – String reference to the message describing the error. Will be shown to user
Returns:

NetworkResponse object to describe an authentication failure.

getErrorDialog

public AlertDialog getErrorDialog(Context context)

Get an error dialog that can be displayed to show message from messageID to user

Parameters:
  • context – Context upon which to display error dialog (Should be someClass.this)
Returns:

Dialog that can be shown

getMessageID

public int getMessageID()

Get the resource ID of the message to display to the user

Returns:Resource ID of message

getPayload

public E getPayload()

Get the payload returned by the network operation

Returns:Payload returned by network operation

isAuthFailed

public boolean isAuthFailed()

Get whether the current object represents a failed authentication

Returns:true if object represents an authentication failure, false otherwise

setAuthFailed

public void setAuthFailed(boolean isAuthFailed)

Set whether the current object represents a failed authentication

Parameters:
  • isAuthFailedtrue if object represents an authentication failure, false otherwise

showErrorDialog

public void showErrorDialog(Context context)

Show an error dialog that can be displayed to show message from messageID to user

Parameters:
  • context – Context upon which to display error dialog

toString

public String toString()

Get a String representation of the object that conveys the current state of all instance fields

Returns:String representation of the form NetworkResponse<?>[field1=value1, ...]