diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/data/reminders/TaskNotifier.kt b/app/src/main/java/de/jeanlucmakiola/agendula/data/reminders/TaskNotifier.kt index d7f087d..4adc2c5 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/data/reminders/TaskNotifier.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/data/reminders/TaskNotifier.kt @@ -18,6 +18,7 @@ import androidx.core.content.edit import de.jeanlucmakiola.agendula.MainActivity import de.jeanlucmakiola.agendula.R import de.jeanlucmakiola.agendula.data.prefs.Settings +import de.jeanlucmakiola.agendula.domain.readableDescription import de.jeanlucmakiola.agendula.data.prefs.is24Hour import de.jeanlucmakiola.agendula.data.di.ApplicationScope import de.jeanlucmakiola.agendula.data.tasks.ProviderResolver @@ -84,6 +85,7 @@ class TaskNotifier @Inject constructor( ), ) } + val description = task.description?.readableDescription()?.trim()?.takeIf { it.isNotBlank() } val tapIntent = PendingIntent.getActivity( context, task.taskId.toInt(), @@ -93,7 +95,10 @@ class TaskNotifier @Inject constructor( val notification = NotificationCompat.Builder(context, channelId) .setSmallIcon(R.drawable.ic_notification) .setContentTitle(title) - .apply { if (text != null) setContentText(text) } + .apply { (text ?: description)?.let(::setContentText) } + .apply { + expandedText(text, description)?.let { setStyle(NotificationCompat.BigTextStyle().bigText(it)) } + } .setCategory(NotificationCompat.CATEGORY_REMINDER) .setPriority(NotificationCompat.PRIORITY_HIGH) .setAutoCancel(true) @@ -240,3 +245,10 @@ private fun relativeDay(date: LocalDate, today: LocalDate, words: RelativeDays, else -> null } } + +/** The expanded body of a due reminder: the due line, then the task's description. */ +internal fun expandedText(dueLine: String?, description: String?): String? = when { + description == null -> null + dueLine == null -> description + else -> "$dueLine\n\n$description" +} diff --git a/app/src/test/java/de/jeanlucmakiola/agendula/data/reminders/ExpandedTextTest.kt b/app/src/test/java/de/jeanlucmakiola/agendula/data/reminders/ExpandedTextTest.kt new file mode 100644 index 0000000..4ca7d65 --- /dev/null +++ b/app/src/test/java/de/jeanlucmakiola/agendula/data/reminders/ExpandedTextTest.kt @@ -0,0 +1,22 @@ +package de.jeanlucmakiola.agendula.data.reminders + +import com.google.common.truth.Truth.assertThat +import org.junit.jupiter.api.Test + +class ExpandedTextTest { + + @Test + fun `no description means no expanded body`() { + assertThat(expandedText("Due today", null)).isNull() + } + + @Test + fun `description alone when there is no due line`() { + assertThat(expandedText(null, "Buy oat milk")).isEqualTo("Buy oat milk") + } + + @Test + fun `due line comes first, separated by a blank line`() { + assertThat(expandedText("Due today", "Buy oat milk")).isEqualTo("Due today\n\nBuy oat milk") + } +}