https://kotlinlang.org logo
#android
Title
# android
l

louiscad

03/09/2020, 11:47 AM
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

dave08

03/10/2020, 6:00 AM
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

louiscad

03/10/2020, 8:12 AM
@dave08 With #splitties Resources, you just have to do
txt(R.string.some_text)
, that problem is already resolved :)
d

dave08

03/11/2020, 6:04 AM
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

louiscad

03/11/2020, 8:20 AM
@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

dave08

03/11/2020, 8:31 AM
So without throttling, updating an existing notification would mean using buildNotification with rthe same id, or is there another dsl for that?
l

louiscad

03/11/2020, 1:59 PM
Yes, that's how it's handled by Android: provide another
Notification
with same id (and tag if used)
7 Views