Hi all,
I'm using the NB6 library to notify the user once a day when todays date has arrived at a specific time and for tomorrow as well.
The notification is for up-coming birthdays.
EDIT: I just noticed on the notification on my tablet, that there is a little v character next to the title. If I touch on that, it expands down the notification content to display each line separately as expected. It seems the initial content ignores any CRLF and displays all content on one line - very disappointing.
The names and birthdays are fetched from the SQLite database on the mobile device (phone or tablet).
A function (CheckBirthdays) is called to find and fetch the names and birthdays from the database. They are formed into a List.
There are 2 Lists - one for today and one for tomorrow.
For each list, a function (SendNotifications) is called.
In this function the code adds a CRLF at the beginning and the end of the name line, so that if more than one person has the same birthdate, they are added to the notification on separate lines. Except the CRLF is never recognized in the JoinNames function, as each name is on the same line.
What needs to be added/changed for the CRLF to be recognized in the JoinNames function when there are more than one line of text?
Here's the code:
SendNotifications:
JoinNames:
I've added a numbering system to the names, in the JoinNames function. See below. It better recognizes each name when the names text is displayed on one line in the initial display of the notification. When expanded, it shows the names on each line with the numbering. eg:
1. First Name
2. Second Name
I'm using the NB6 library to notify the user once a day when todays date has arrived at a specific time and for tomorrow as well.
The notification is for up-coming birthdays.
EDIT: I just noticed on the notification on my tablet, that there is a little v character next to the title. If I touch on that, it expands down the notification content to display each line separately as expected. It seems the initial content ignores any CRLF and displays all content on one line - very disappointing.
The names and birthdays are fetched from the SQLite database on the mobile device (phone or tablet).
A function (CheckBirthdays) is called to find and fetch the names and birthdays from the database. They are formed into a List.
There are 2 Lists - one for today and one for tomorrow.
For each list, a function (SendNotifications) is called.
In this function the code adds a CRLF at the beginning and the end of the name line, so that if more than one person has the same birthdate, they are added to the notification on separate lines. Except the CRLF is never recognized in the JoinNames function, as each name is on the same line.
What needs to be added/changed for the CRLF to be recognized in the JoinNames function when there are more than one line of text?
Here's the code:
Code:
Sub CheckBirthdays
Log("CheckBirthdays triggered...")
Dim MMDD As String
'Todays birthdays:
Dim today As String = DateTime.Date(DateTime.Now)
Log("Checking birthdays for: " & today)
MMDD = today.SubString2(0,5)
Dim birthdaysToday As List = DBModule.GetPeopleForDate(MMDD)
If birthdaysToday.Size > 0 Then
SendNotifications(birthdaysToday, today)
End If
Log("===========================================")
'Tomorrows birthdays:
Dim tomorrow As String = DateTime.Date(DateTime.Add(DateTime.Now,0,0,1))
Log("Checking birthdays for: " & tomorrow)
MMDD = tomorrow.SubString2(0,5)
Dim birthdaysTomorrow As List = DBModule.GetPeopleForDate(MMDD)
If birthdaysTomorrow.Size > 0 Then
SendNotifications(birthdaysTomorrow, tomorrow)
End If
Log("===========================================")
End Sub
SendNotifications:
SendNotifications:
Sub SendNotifications(names As List, when As String)
Log("SendNotifications triggered...")
Log("names.size: " & names.Size)
Log("when: " & when)
Dim n As NB6
Dim channelId As String = "birthday_channel"
Dim channelName As String = Application.LabelName
Dim icon As Bitmap = LoadBitmap(File.DirAssets, "birthday_icon.png")
Dim showWhen As Long = DateTime.Now
Dim title As String = "🎉 Birthday Reminder for: " & when
Dim content As String = JoinNames(names)
'initialize
n.Initialize(channelId, channelName, "DEFAULT")
n.AutoCancel(True)
n.ShowWhen(showWhen)
n.SetDefaults(True,True,True)
n.SmallIcon(icon)
n.Build(title,content,"birthday_tag",Main).Notify(Rnd(1000,9999))
End Sub
JoinNames:
JoinNames:
Sub JoinNames(names As List) As String
Dim s As String
For Each person As Map In names
Dim name As String = person.Get("name")
s = s & CRLF & name.Trim & CRLF
Next
Log(s)
Return s
End Sub
I've added a numbering system to the names, in the JoinNames function. See below. It better recognizes each name when the names text is displayed on one line in the initial display of the notification. When expanded, it shows the names on each line with the numbering. eg:
1. First Name
2. Second Name
B4X:
Sub JoinNames(names As List) As String
Dim s As String
Dim counter As Int = 0
For Each person As Map In names
Dim name As String = person.Get("name")
counter = counter + 1 '<-- set the numbering of each name
s = s & counter & ". " & name.Trim & CRLF
Next
Log("persons: " & s)
Return s
End Sub
Last edited: