-
-
Notifications
You must be signed in to change notification settings - Fork 692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom actions to notifications #179
Comments
@hendrawd if you need help with the implementation, let me know here |
It's ok for marshal and un-marshal PendingIntent, but i think it is better if we can add more than 1 actions there, so i work on List instead of just 1 PendingIntent. I have tried with more than 1 action, and 3 is the best(visible). What do you think? |
@hendrawd Yes. When |
Hi guys, |
@mnaswin3 not yet, but you can send a PR! |
…otificationConfig class was needed, to have a better structure, less method count and easier code readability. Updated demo app.
Implemented actions for notifications. Major refactor to Read the code example below, which is taken from the demo app's BaseActivity, in which I have implemented an example of how you can cancel an upload from an action.
protected UploadNotificationConfig getNotificationConfig(@StringRes int title) {
return new UploadNotificationConfig()
.setIcon(R.drawable.ic_upload)
.setCompletedIcon(R.drawable.ic_upload_success)
.setErrorIcon(R.drawable.ic_upload_error)
.setCancelledIcon(R.drawable.ic_cancelled)
.setIconColor(Color.BLUE)
.setCompletedIconColor(Color.GREEN)
.setErrorIconColor(Color.RED)
.setCancelledIconColor(Color.YELLOW)
.setTitle(getString(title))
.setInProgressMessage(getString(R.string.uploading))
.setCompletedMessage(getString(R.string.upload_success))
.setErrorMessage(getString(R.string.upload_error))
.setCancelledMessage(getString(R.string.upload_cancelled))
.setClickIntent(new Intent(this, MainActivity.class))
.setClearOnAction(true)
.setRingToneEnabled(true);
} In protected UploadNotificationConfig getNotificationConfig(String uploadId,
@StringRes int title){
UploadNotificationConfig config = new UploadNotificationConfig();
PendingIntent clickIntent = PendingIntent.getActivity(
this, 1, new Intent(this, MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT);
config.setTitleForAllStatuses(getString(title))
.setRingToneEnabled(true)
.setClickIntentForAllStatuses(clickIntent)
.setClearOnActionForAllStatuses(true);
config.getProgress().message = getString(R.string.uploading);
config.getProgress().iconResourceID = R.drawable.ic_upload;
config.getProgress().iconColorResourceID = Color.BLUE;
// this is how you add an action to a specific notification status
config.getProgress().actions.add(new UploadNotificationAction(
R.drawable.ic_cancelled,
getString(R.string.cancel_upload),
NotificationActions.getCancelUploadAction(this, 1, uploadId)));
config.getCompleted().message = getString(R.string.upload_success);
config.getCompleted().iconResourceID = R.drawable.ic_upload_success;
config.getCompleted().iconColorResourceID = Color.GREEN;
config.getError().message = getString(R.string.upload_error);
config.getError().iconResourceID = R.drawable.ic_upload_error;
config.getError().iconColorResourceID = Color.RED;
config.getCancelled().message = getString(R.string.upload_cancelled);
config.getCancelled().iconResourceID = R.drawable.ic_cancelled;
config.getCancelled().iconColorResourceID = Color.YELLOW;
return config;
} It's more verbose now, but you can finely tune every aspect of every notification, in a way which was not possible before (#293), and it's easier to read. Check out the new utility functions in |
3.3 released and this feature is now available! |
This coding style is horrible and not appropriate for Java or any other lang as far as I can tell. |
@vsg24 Fine. If you implemented that part, how would you do it instead? I have reasons for that kind of implementation, but I want to hear your feedback and suggestions |
@vsg24 Do you want to use setter and getter for message? |
@vsg24 Ok but no value added with your comments yet and it's a pity. I like to discuss about software design a lot! A part the obvious, what do you suggest? It's open source, everything can be changed for the better 😃 |
It will be useful to be able to add custom actions to
UploadNotificationConfig
, like this:addAction should have the following signature:
This explains how to marshal and unmarshal
PendingIntents
to/fromParcelable
The text was updated successfully, but these errors were encountered: