docs: add comprehensive static daily reminders documentation

- Add static daily reminders to README.md core features and API reference
- Create detailed usage guide in USAGE.md with examples and best practices
- Add version 2.1.0 changelog entry documenting new reminder functionality
- Create examples/static-daily-reminders.ts with complete usage examples
- Update test-apps README to include reminder testing capabilities

The static daily reminder feature provides simple daily notifications
without network content dependency, supporting cross-platform scheduling
with rich customization options.
This commit is contained in:
Matthew Raymer
2025-10-05 05:12:06 +00:00
parent 9ec30974da
commit f9c21d4e5b
21 changed files with 2120 additions and 0 deletions

View File

@@ -94,6 +94,26 @@ class NotifyReceiver : BroadcastReceiver() {
CoroutineScope(Dispatchers.IO).launch {
try {
// Check if this is a static reminder (no content dependency)
val isStaticReminder = intent?.getBooleanExtra("is_static_reminder", false) ?: false
if (isStaticReminder) {
// Handle static reminder without content cache
val title = intent?.getStringExtra("title") ?: "Daily Reminder"
val body = intent?.getStringExtra("body") ?: "Don't forget your daily check-in!"
val sound = intent?.getBooleanExtra("sound", true) ?: true
val vibration = intent?.getBooleanExtra("vibration", true) ?: true
val priority = intent?.getStringExtra("priority") ?: "normal"
val reminderId = intent?.getStringExtra("reminder_id") ?: "unknown"
showStaticReminderNotification(context, title, body, sound, vibration, priority, reminderId)
// Record reminder trigger in database
recordReminderTrigger(context, reminderId)
return@launch
}
// Existing cached content logic for regular notifications
val db = DailyNotificationDatabase.getDatabase(context)
val latestCache = db.contentCacheDao().getLatest()
@@ -250,4 +270,67 @@ class NotifyReceiver : BroadcastReceiver() {
// Local callback implementation would go here
Log.i(TAG, "Local callback fired: ${callback.id} for event: $eventType")
}
// Static Reminder Helper Methods
private fun showStaticReminderNotification(
context: Context,
title: String,
body: String,
sound: Boolean,
vibration: Boolean,
priority: String,
reminderId: String
) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// Create notification channel for reminders
createReminderNotificationChannel(context, notificationManager)
val notification = NotificationCompat.Builder(context, "daily_reminders")
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle(title)
.setContentText(body)
.setPriority(
when (priority) {
"high" -> NotificationCompat.PRIORITY_HIGH
"low" -> NotificationCompat.PRIORITY_LOW
else -> NotificationCompat.PRIORITY_DEFAULT
}
)
.setSound(if (sound) null else null) // Use default sound if enabled
.setAutoCancel(true)
.setVibrate(if (vibration) longArrayOf(0, 250, 250, 250) else null)
.setCategory(NotificationCompat.CATEGORY_REMINDER)
.build()
notificationManager.notify(reminderId.hashCode(), notification)
Log.i(TAG, "Static reminder displayed: $title (ID: $reminderId)")
}
private fun createReminderNotificationChannel(context: Context, notificationManager: NotificationManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"daily_reminders",
"Daily Reminders",
NotificationManager.IMPORTANCE_DEFAULT
).apply {
description = "Daily reminder notifications"
enableVibration(true)
setShowBadge(true)
}
notificationManager.createNotificationChannel(channel)
}
}
private fun recordReminderTrigger(context: Context, reminderId: String) {
try {
val prefs = context.getSharedPreferences("daily_reminders", Context.MODE_PRIVATE)
val editor = prefs.edit()
editor.putLong("${reminderId}_lastTriggered", System.currentTimeMillis())
editor.apply()
Log.d(TAG, "Reminder trigger recorded: $reminderId")
} catch (e: Exception) {
Log.e(TAG, "Error recording reminder trigger", e)
}
}
}