Hi, did anyone there made their `NotificationCompa...
# android
l
Hi, did anyone there made their
NotificationCompat
Kotlin extensions? I personally made some, and I'm looking for folks to discuss API design regarding extensions for these APIs. I'm looking forward exchanging inspiration to get to a DSL that is the lest error-prone and forget-prone possible, and very readable (can't stand these
NotificationCompat.PRIORITY_
and similar prefixes). Right, this is what I have, and I know I can make improvements, but I'd like to bounce off improvement ideas.
Copy code
val notification = buildNotification(ChannelIds.Something) {
    priority = NotificationCompat.PRIORITY_MAX
    category = NotificationCompat.CATEGORY_STATUS
    visibility = Public
    contentText = "Some content text"
    smallIcon = R.drawable.ic_some_icon_white_24dp
}
d
contentText can also get a res id? Also, what about some combination of res id and formatting as a function?
I currently also have a wrapper for updating progress
l
@dave08 With #splitties Resources, you just have to do
txt(R.string.some_text)
, that problem is already resolved :)
d
Not bad 🙂 where are you getting the context from? Notifying progress is also a headache, since if you send too many updates the UI can get stuck, so my wrapper has some kind of debounce logic inside... might also be a point to consider. In general, with the DSL you're planning, how would an already built notification be updated?
l
@dave08 Throttling notification update is out of the scope of such a DSL IMO, because different use cases would want different refresh rates, and
Flow
from #coroutines can already handle that perfectly. About the
Context
, I stopped minding about that for a while. I can either use it as a receiver in the function calling the
buildNotification
function, or use
appTxt
which will use the application context.
d
So without throttling, updating an existing notification would mean using buildNotification with rthe same id, or is there another dsl for that?
l
Yes, that's how it's handled by Android: provide another
Notification
with same id (and tag if used)