Skip to content

Instantly share code, notes, and snippets.

@Oleur
Created June 3, 2021 16:53
Show Gist options
  • Save Oleur/cbbaa6b24c5b75661ea452d4daf21e45 to your computer and use it in GitHub Desktop.
Save Oleur/cbbaa6b24c5b75661ea452d4daf21e45 to your computer and use it in GitHub Desktop.
class TodoProvider : SliceProvider() {
override fun onCreateSliceProvider() = true
override fun onBindSlice(sliceUri: Uri): Slice? {
val context = context ?: return null
val activityAction = createActivityAction() ?: return null
return if (sliceUri.path == "/todo") {
list(context, sliceUri, ListBuilder.INFINITY) {
header {
title = "What's on my Aircall to-do list"
subtitle = "2 tasks"
primaryAction = createActivityAction()
}
row {
setTodoTask("+33 6 66 66 66 66", "Assign to you\nA note was added", Date(1621413900000))
}
row {
setTodoTask("Aircall new account +33 6 66 66 66 66", "Assign to you\nA note was added", Date(1619426700000))
}
}
} else {
// Display error/default slice
}
}
private fun createActivityAction(): SliceAction? {
return SliceAction.create(
PendingIntent.getActivity(context, 0, Intent(context, MyActivity::class.java), 0),
IconCompat.createWithResource(context, R.drawable.ic_logo),
ICON_IMAGE, "Go to to-do"
)
}
private fun RowBuilderDsl.setTodoTask(title: String, desc: String, date: Date) {
setTitle("Call $title")
setSubtitle(desc)
addEndItem(date.time)
addEndItem(IconCompat.createWithResource(context, R.drawable.ic_call), ICON_IMAGE)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment