-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
New streams notifications #2335
Conversation
cool! |
Ok, I'll do it. Also I have a question to the community: how is better to mark, which streams are already "known" at channel? |
I think a video should be marked as "known" after it has been opened (in any way: background, info, popup...). An option to manually mark a video as known would be useful, too, then. |
This comment has been minimized.
This comment has been minimized.
Ahh.. Waiting for live stream notifications for so long.. Edit: |
Definitely would love to see this feature as the next big thing as well :) |
What about merging this PR? I`ll resolve conflicts and migrate to androidx WorkManager |
@nv95: That's good. Please use vector drawables for the new icons though (and test that it doesn't cause a crash on Android API 19). Note that there were some major changes to the subscriptions in v0.19.0. Imho the notifications should be opt-in though. |
112b084
to
e396cb8
Compare
This comment has been minimized.
This comment has been minimized.
I don't know if it was the case but it's now opt-in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen you have to subscribe to notifications via settings -> notification -> channels
Please add the notification button in channel header too, it's way more user-friendly.
And add a subscribe to all button in notification settings.
Also, why is it leading to channel info instead of video info? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some icons unfortunately can't be converted to vector drawables because they are used in notifications, which require bitmaps. But there are still some issues with icons.
Btw @wb9688 how were you able to rebase this while being sure not to create problems even in mid commits? I tried a while ago, but there were so many conflicting commits that trying to understand what the author was doing in each one of them (i.e. the purpose of every piece of code) seemed impossible
@@ -532,4 +591,10 @@ public void setTitle(final String title) { | |||
headerTitleView.setText(title); | |||
} | |||
} | |||
|
|||
private boolean isNotificationsEnabled() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to put this in the NotificationHelper
class, so that is can then be accessed from anywhere. In the future we could e.g. want to long-press on a subscription to see the option for notifications and this function would be needed.
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, | ||
context.getString(R.string.streams_notification_channel_id)); | ||
builder.setContentTitle(String.format("%s • %s", data.getName(), summary)); | ||
builder.setContentText(data.getText()); | ||
builder.setNumber(data.getSize()); | ||
builder.setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE); | ||
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT); | ||
builder.setSmallIcon(R.drawable.ic_stat_newpipe); | ||
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), | ||
R.drawable.ic_newpipe_triangle_white)); | ||
builder.setColor(ContextCompat.getColor(context, R.color.ic_launcher_background)); | ||
builder.setColorized(true); | ||
builder.setAutoCancel(true); | ||
builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a Builder
, can't you do this? Also, maybe create the style beforehand, so that you can add the .setStyle()
and .setContentIntent()
at the end
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, | |
context.getString(R.string.streams_notification_channel_id)); | |
builder.setContentTitle(String.format("%s • %s", data.getName(), summary)); | |
builder.setContentText(data.getText()); | |
builder.setNumber(data.getSize()); | |
builder.setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE); | |
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT); | |
builder.setSmallIcon(R.drawable.ic_stat_newpipe); | |
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), | |
R.drawable.ic_newpipe_triangle_white)); | |
builder.setColor(ContextCompat.getColor(context, R.color.ic_launcher_background)); | |
builder.setColorized(true); | |
builder.setAutoCancel(true); | |
builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); | |
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, | |
context.getString(R.string.streams_notification_channel_id)) | |
.setContentTitle(String.format("%s • %s", data.getName(), summary)) | |
.setContentText(data.getText()) | |
.setNumber(data.getSize()) | |
.setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE) | |
.setPriority(NotificationCompat.PRIORITY_DEFAULT) | |
.setSmallIcon(R.drawable.ic_stat_newpipe) | |
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), | |
R.drawable.ic_newpipe_triangle_white)) | |
.setColor(ContextCompat.getColor(context, R.color.ic_launcher_background)) | |
.setColorized(true) | |
.setAutoCancel(true) | |
.setCategory(NotificationCompat.CATEGORY_SOCIAL); |
builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); | ||
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); | ||
for (StreamInfoItem o : data.getStreams()) { | ||
style.addLine(o.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: why are stream names shown both in builder.setContentText(data.getText());
and here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builder.setContentText
is used for collapsed notification, style applied for expanded
app/src/main/java/org/schabi/newpipe/notifications/SubscriptionUpdates.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { | ||
val ctx = context ?: return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This usage of ctx
looks a bit strange, though I don't know if this piece of code can be reworded
|
||
private fun updateSubscriptions(list: List<SubscriptionEntity>) { | ||
var notified = 0 | ||
for (o in list) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of calling it o
and list
, I think subscription
and subscriptions
would be better names
|
||
fun update(newData: List<SubscriptionEntity>?) { | ||
dataSet.clear() | ||
dataSet.addAll(newData!!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make it nullable and then assert it is not null?
val icon = AnimatedVectorDrawableCompat.create( | ||
itemView.context, | ||
if (mode == NotificationMode.DISABLED) { | ||
R.drawable.av_notification_off | ||
} else { | ||
R.drawable.av_notification_on | ||
} | ||
) ?: return null | ||
icon.setTint(ThemeHelper.resolveColorFromAttr( | ||
itemView.context, android.R.attr.textColorPrimary | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use an attr
icon here, so that it can be styled according to themes automatically. Also, why is the name of those icons not ic_notification_on_white_24dp
? So, in the end you should have 4 icons (ic_notification_on_white_24dp
, ic_notification_on_black_24dp
, ic_notification_off_white_24dp
, ic_notification_off_black_24dp
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What reasons to use different icons if we can use one icon with tint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a commit making some small changes. The code looks good, now it just needs testing. I will be leaving notifications on on my phone with my subscriptions database for a while.
app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt
Outdated
Show resolved
Hide resolved
After two days everything still seems to be up and running |
Removed some non-translatable strings and just hardcoded them in the code, like it's being done for other string separators. This also deduplicates some code by using Localization. Used some Kotlin feature to reduce code.
8ffcb16
to
5fea12d
Compare
It never kicked in since we are never returning a retry() Result, but always either success() or failure() (see createWork() function). Also, there is already a default (exponential backoff starting from 30 seconds), so no need to override it.
cb83d33
to
6e8c9f9
Compare
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Merged and fixed conflicts
- Added a commit removing the backoff criteria completely
- Added a commit that makes the "Player notification" entry searchable in settings. I don't mean the settings contained within player notification, as those were already searchable, but rather just the button in appearance settings that brings you to player notification settings: it is now searchable.
- I tested for a few days on my phone (a couple of weeks ago) and notifications worked fine.
- I tested again now on the API 19 and API 30 emulators and notifications worked. Also other things this PR touched worked, such as settings, subscribing to channels, feed, etc.
- Code was reviewed by all of us and now looks good.
I would merge this, finally :-D
Note for after this is merged: create a PR that removes both the ic_notifications
and ic_pin
icons in the drawable-night folders, as the way icons work has been changed. I will not do this in this PR since ic_pin
is unrelated.
@TobiGr or @litetex could you take care of that? I don't know what should be updated (just the screenshot of an inspected database?) |
I think you can view it if you inspect the app's database of a running app, but I never did that |
@TiA4f8R could you point out here the issues you found with new streams notifications? |
These are not really issues but improvements (I didn't test deeply the feature):
|
I created the follwoing database-diagramm with https://dbeaver.io/ (FOSS): Feel free to update the wiki if you feel like this is correct. |
@litetex done, thanks |
Checking and notifying about new streams from subscriptions
Closes #719 closes #1086