Skip to content

Commit

Permalink
do not wrap notification config constructor anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
gotev committed Nov 30, 2015
1 parent 4d6c116 commit 25b2591
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@ public BinaryUploadRequest setFileToUpload(String path) throws FileNotFoundExcep
}

@Override
public BinaryUploadRequest setNotificationConfig(int iconResourceID, String title,
String message, String completed,
String error, boolean autoClearOnSuccess,
boolean autoClearOnAction) {
super.setNotificationConfig(iconResourceID, title, message, completed, error,
autoClearOnSuccess, autoClearOnAction);
public BinaryUploadRequest setNotificationConfig(UploadNotificationConfig config) {
super.setNotificationConfig(config);
return this;
}

Expand All @@ -93,12 +89,6 @@ public BinaryUploadRequest setCustomUserAgent(String customUserAgent) {
return this;
}

@Override
public BinaryUploadRequest setNotificationClickIntent(Intent intent) {
super.setNotificationClickIntent(intent);
return this;
}

@Override
public BinaryUploadRequest setMaxRetries(int maxRetries) {
super.setMaxRetries(maxRetries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public HttpUploadRequest(final Context context, final String uploadId, final Str
this.uploadId = uploadId;
notificationConfig = new UploadNotificationConfig();
url = serverUrl;
headers = new ArrayList<NameValue>();
headers = new ArrayList<>();
maxRetries = 0;
}

Expand Down Expand Up @@ -75,23 +75,10 @@ protected void initializeIntent(Intent intent) {
/**
* Sets custom notification configuration.
*
* @param iconResourceID ID of the notification icon.
* You can use your own app's R.drawable.your_resource
* @param title Notification title
* @param message Text displayed in the notification when the upload is in progress
* @param completed Text displayed in the notification when the upload is completed successfully
* @param error Text displayed in the notification when an error occurs
* @param autoClearOnSuccess true if you want to automatically clear the notification when
* the upload gets completed successfully
* @param autoClearOnAction true if you want to automatically clear the notification when
* the user taps on it
*/
public HttpUploadRequest setNotificationConfig(final int iconResourceID, final String title,
final String message, final String completed,
final String error, final boolean autoClearOnSuccess,
final boolean autoClearOnAction) {
notificationConfig = new UploadNotificationConfig(iconResourceID, title, message, completed, error,
autoClearOnSuccess, autoClearOnAction);
* @param config the upload configuration object
*/
public HttpUploadRequest setNotificationConfig(UploadNotificationConfig config) {
notificationConfig = config;
return this;
}

Expand Down Expand Up @@ -203,14 +190,6 @@ public HttpUploadRequest setCustomUserAgent(String customUserAgent) {
return this;
}

/**
* @param intent Sets the intent to be executed when the user taps on the upload progress notification.
*/
public HttpUploadRequest setNotificationClickIntent(Intent intent) {
notificationConfig.setClickIntent(intent);
return this;
}

/**
* @return Get the maximum number of retries that the library will do if an error occurs,
* before returning an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,8 @@ public MultipartUploadRequest addArrayParameter(final String paramName, final Li
}

@Override
public MultipartUploadRequest setNotificationConfig(int iconResourceID, String title,
String message, String completed,
String error, boolean autoClearOnSuccess,
boolean autoClearOnAction) {
super.setNotificationConfig(iconResourceID, title, message, completed, error,
autoClearOnSuccess, autoClearOnAction);
public MultipartUploadRequest setNotificationConfig(UploadNotificationConfig config) {
super.setNotificationConfig(config);
return this;
}

Expand All @@ -146,12 +142,6 @@ public MultipartUploadRequest setCustomUserAgent(String customUserAgent) {
return this;
}

@Override
public MultipartUploadRequest setNotificationClickIntent(Intent intent) {
super.setNotificationClickIntent(intent);
return this;
}

@Override
public MultipartUploadRequest setMaxRetries(int maxRetries) {
super.setMaxRetries(maxRetries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,97 +11,162 @@
*
* @author alexbbb (Alex Gotev)
*/
class UploadNotificationConfig implements Parcelable {

private final int iconResourceID;
private final String title;
private final String message;
private final String completed;
private final String error;
private final boolean autoClearOnSuccess;
private final boolean autoClearOnAction;
private boolean ringTone;
public class UploadNotificationConfig implements Parcelable {

private int iconResourceID;
private String title;
private String inProgress;
private String completed;
private String error;
private boolean autoClearOnSuccess;
private boolean clearOnAction;
private boolean ringToneEnabled;
private Intent clickIntent;

public UploadNotificationConfig() {
iconResourceID = android.R.drawable.ic_menu_upload;
title = "File Upload";
message = "uploading in progress";
inProgress = "uploading in progress";
completed = "upload completed successfully!";
error = "error during upload";
autoClearOnSuccess = false;
autoClearOnAction = false;
clearOnAction = false;
clickIntent = null;
ringTone = false;
ringToneEnabled = false;
}

public UploadNotificationConfig(final int iconResourceID, final String title,
final String message, final String completed,
final String error, final boolean autoClearOnSuccess,
final boolean autoClearOnAction)
throws IllegalArgumentException {

if (title == null || message == null || completed == null || error == null) {
throw new IllegalArgumentException("You can't provide null parameters");
}
/**
* Sets the notification icon.
* @param resourceID Resource ID of the icon to use
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setIcon(int resourceID) {
this.iconResourceID = resourceID;
return this;
}

this.iconResourceID = iconResourceID;
/**
* Sets the notification title.
* @param title Title to show in the notification icon
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setTitle(String title) {
this.title = title;
this.message = message;
this.completed = completed;
this.error = error;
this.autoClearOnSuccess = autoClearOnSuccess;
this.autoClearOnAction = autoClearOnAction;
return this;
}

/**
* Sets the message to be shown while upload is in progress.
* @param message Message to show
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setInProgressMessage(String message) {
inProgress = message;
return this;
}

/**
* Sets the message to be shown if an error occurs.
* @param message Message to show
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setErrorMessage(String message) {
error = message;
return this;
}

/**
* Sets the message to be shown when the upload is completed.
* @param message Message to show
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setCompletedMessage(String message) {
completed = message;
return this;
}

/**
* Sets whether or not to auto clear the notification when the upload is completed successfully.
* @param clear true to automatically clear the notification, otherwise false
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setAutoClearOnSuccess(boolean clear) {
autoClearOnSuccess = clear;
return this;
}

/**
* Sets whether or not to clear the notification when the user taps on it.
* @param clear true to clear the notification, otherwise false
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setClearOnAction(boolean clear) {
clearOnAction = clear;
return this;
}

/**
* Sets the intent to be executed when the user taps on the notification.
* @param clickIntent {@link android.content.Intent}.
* For example: new Intent(context, YourActivity.class)
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setClickIntent(Intent clickIntent) {
this.clickIntent = clickIntent;
return this;
}

/**
* Sets whether or not to enable the notification sound when the upload gets completed with
* success or error
* @param enabled true to enable the default ringtone
* @return {@link UploadNotificationConfig}
*/
public final UploadNotificationConfig setRingToneEnabled(Boolean enabled) {
this.ringToneEnabled = enabled;
return this;
}

public final int getIconResourceID() {
final int getIconResourceID() {
return iconResourceID;
}

public final String getTitle() {
final String getTitle() {
return title;
}

public final String getMessage() {
return message;
final String getInProgressMessage() {
return inProgress;
}

public final String getCompleted() {
final String getCompletedMessage() {
return completed;
}

public final String getError() {
final String getErrorMessage() {
return error;
}

public final boolean isAutoClearOnSuccess() {
final boolean isAutoClearOnSuccess() {
return autoClearOnSuccess;
}

public final boolean isAutoClearOnAction() {
return autoClearOnAction;
final boolean isClearOnAction() {
return clearOnAction;
}

public final boolean isRingTone() {
return ringTone;
final boolean isRingToneEnabled() {
return ringToneEnabled;
}

public final PendingIntent getPendingIntent(Context context) {
final PendingIntent getPendingIntent(Context context) {
if (clickIntent == null) {
return PendingIntent.getBroadcast(context, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
}

return PendingIntent.getActivity(context, 1, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

public final void setClickIntent(Intent clickIntent) {
this.clickIntent = clickIntent;
}
public final void enableRingTone(Boolean tone) {
this.ringTone = tone;
}


// This is used to regenerate the object.
// All Parcelables must have a CREATOR that implements these two methods
public static final Parcelable.Creator<UploadNotificationConfig> CREATOR =
Expand All @@ -126,24 +191,24 @@ public int describeContents() {
public void writeToParcel(Parcel parcel, int arg1) {
parcel.writeInt(iconResourceID);
parcel.writeString(title);
parcel.writeString(message);
parcel.writeString(inProgress);
parcel.writeString(completed);
parcel.writeString(error);
parcel.writeByte((byte) (autoClearOnSuccess ? 1 : 0));
parcel.writeByte((byte) (autoClearOnAction ? 1 : 0));
parcel.writeByte((byte) (ringTone ? 1 : 0));
parcel.writeByte((byte) (clearOnAction ? 1 : 0));
parcel.writeByte((byte) (ringToneEnabled ? 1 : 0));
parcel.writeParcelable(clickIntent, 0);
}

private UploadNotificationConfig(Parcel in) {
iconResourceID = in.readInt();
title = in.readString();
message = in.readString();
inProgress = in.readString();
completed = in.readString();
error = in.readString();
autoClearOnSuccess = in.readByte() == 1;
autoClearOnAction = in.readByte() == 1;
ringTone = in.readByte() == 1;
clearOnAction = in.readByte() == 1;
ringToneEnabled = in.readByte() == 1;
clickIntent = in.readParcelable(Intent.class.getClassLoader());
}
}
Loading

0 comments on commit 25b2591

Please sign in to comment.