Skip to content
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

Improving group mode #33

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Improving group mode #33

wants to merge 10 commits into from

Conversation

noaoh
Copy link

@noaoh noaoh commented Jan 9, 2019

As of Android KitKat (7.0) the notes can be bundled together in a group. Each note within this group is expandable, and their full contents can be viewed.

@khuttun
Copy link
Owner

khuttun commented Jan 12, 2019

Hi, thank you for the PR! Unfortunately it breaks the app on API level 15 (creating a grouped notification with 2 notes makes the app crash). This is a nice feature, but I think we should make the code paths for Nougat and pre-Nougat completely separate to avoid triggering functions that are not available on older Android.

external.system.module.version="unspecified"
type="JAVA_MODULE"
version="4">
<module external.linked.project.id="NotificationNotes" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are changes in this file necessary?

this.notificationBuilder.setOngoing(true);
this.notificationBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
this.notificationBuilder.setContentIntent(PendingIntent
public NotificationCompat.Builder getNotificationBuilder()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for changing the builder to not be a member anymore?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been unable to get the notification that shows how many notes there (the top notification) to work using the builder as a member variable. In general, having a new builder each time makes the building of notifications a bit easier to reason about.

}
}

clearAllNotifications();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling clearAllNotifications() here doesn't seem right. Would it make more sense to only call this when setting the Nougat+ group notifications, if this is needed for them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function clearAllNotifications is now called in displayGroupNotifications.

@@ -90,43 +85,158 @@ public void setGroupNotification(ArrayList<NotificationNote> notes)
break;

default:
this.notificationManager.notify(GROUP_NOTIF_ID, createGroupNotification(visibleNotes));
if (groupAPI)
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be clearer to put the code for creating the grouped notifications to a function so that both if and else branches here could be one-liners.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created the displayGroupNotifications function to do this.

{
id = findNotificationID(notes, title, text);
}
this.notificationManager.notify("note", id, note);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for taking the tag parameter in use in the notify() call?

break;
}
}

private int findNotificationID(ArrayList<NotificationNote> notes, String title, String text)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't really work right if you happen to have two notes with identical title and text. Would it be possible to restructure code so that function like this wouldn't be needed?

groupedNotes.add(newNote);
}

if (groupAPI)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check necessary here? Is this function ever called if groupAPI is false?

}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems you have removed the NotificationChannel. It's needed for Oreo and newer.

}
}

clearAllNotifications();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearAllNotifications() is still called here?

* Creates the group of notifications that will be bundled together into one notification.
* Used for Android Nougat (7.0) and beyond.
*/
private ArrayList<Notification> createGroupNotifications(ArrayList<NotificationNote> notes)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wouldn't use this function, but rather called createGroupNotification() directly from displayGroupNotifications() while looping through visibleNotes, you wouldn't need the whole "note.id" Bundle, right?

@@ -202,6 +202,7 @@ private void setNotification(NotificationNote n)
if (PreferenceManager.getDefaultSharedPreferences(this.context).getBoolean(this.context
.getString(R.string.group_notif_pref_key), false))
{
this.notificationMgr.checkNotification(n);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this would be needed? Changing the group notes setting should update the notifications to reflect the current state (see SettingsActivity).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now multiple notifications with unique ids are created, so when one is unchecked, it does not go away when the notifications are remade.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Would it work if you rather called clearAllNotifications in the beginning of displayGroupNotifications? That would seem like a more robust approach.

}
}

ArrayList<NotificationNote> visibleNotes = getVisibleNotes(notes);
if (Globals.LOG) Log.d(Globals.TAG, "Group notification: visible notes " + visibleNotes.size());

switch (visibleNotes.size())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "case 0" and "case 1" don't really work when using the grouped notifications. Would it make sense to leave this switch-case to be used only when groupAPI == false, and always call displayGroupNotifications when it's true?

Also, now you are using GROUP_NOTIF_ID in cases 0 and 1, and SUMMARY_NOTIF_ID in default case. That will not work. Consider should you just remove GROUP_NOTIF_ID?

@@ -202,6 +202,7 @@ private void setNotification(NotificationNote n)
if (PreferenceManager.getDefaultSharedPreferences(this.context).getBoolean(this.context
.getString(R.string.group_notif_pref_key), false))
{
this.notificationMgr.checkNotification(n);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Would it work if you rather called clearAllNotifications in the beginning of displayGroupNotifications? That would seem like a more robust approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants