Skip to content

Conversation

@ardevd
Copy link
Owner

@ardevd ardevd commented Jan 29, 2026

periodically check for long running records and notify users in case they have forgotten to end a timer.

periodically check for long running records and notify
users in case they have forgotten to end a timer.
@ardevd ardevd self-assigned this Jan 29, 2026
Copilot AI review requested due to automatic review settings January 29, 2026 21:24
@ardevd ardevd added the enhancement New feature or request label Jan 29, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a background job that periodically checks for "zombie records" - time tracking records that have been running for an extended period (10+ hours). When detected, the app sends a notification to remind users to stop the timer if they've forgotten about it.

Changes:

  • Added AndroidX WorkManager dependency for background job scheduling
  • Created ZombieCheckWorker that runs hourly to check for long-running timers
  • Added POST_NOTIFICATIONS permission for Android 13+ compatibility
  • Added notification strings for zombie record alerts

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
gradle/libs.versions.toml Adds work-runtime-ktx dependency version 2.11.0
app/build.gradle.kts Includes the WorkManager dependency in the app module
app/src/main/AndroidManifest.xml Adds POST_NOTIFICATIONS permission for notifications on Android 13+
app/src/main/res/values/strings.xml Defines notification title and description strings for zombie alerts
app/src/main/java/net/ardevd/tagius/features/background/ZombieCheckWorker.kt Implements the background worker that checks for running timers over 10 hours and sends notifications
app/src/main/java/net/ardevd/tagius/features/records/ui/list/RecordsListFragment.kt Sets up the periodic WorkManager job when the records fragment is created
app/src/main/java/net/ardevd/tagius/features/auth/ui/LoginFragment.kt Adds unused WorkManager-related imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 12 to 64
class ZombieCheckWorker(
val context: Context,
params: WorkerParameters
) : CoroutineWorker(context, params) {

override suspend fun doWork(): Result {
return try {
val apiService = RetrofitClient.getInstance(applicationContext)

val now = System.currentTimeMillis() / 1000
val startOfDay = now - (24 * 60 * 60) // Look back 24h just in case
val timeRangeString = "$startOfDay-$now"
val response = apiService.getRecords(timeRangeString, running = 1)

if (response.records.isNotEmpty()) {
val record = response.records[0]

val durationHours = (now - record.startTime) / 3600
// CHECK THRESHOLD (10 hours)
if (durationHours >= 10) {
sendNotification(durationHours.toInt())
}
}

Result.success()
} catch (_: Exception) {
// If network fails, just retry later
Result.retry()
}
}

private fun sendNotification(hours: Int) {
val channelId = "zombie_alert"
val notificationManager =
applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

// Create Channel (Safe to call repeatedly)
val channel =
NotificationChannel(channelId, "Timer Alerts", NotificationManager.IMPORTANCE_HIGH)
notificationManager.createNotificationChannel(channel)
val descText = context.getString(R.string.zombie_still_working_desc, hours)

val notification = NotificationCompat.Builder(applicationContext, channelId)
.setSmallIcon(R.drawable.ic_timer) // Make sure you have this icon
.setContentTitle(context.getString(R.string.zombie_still_working))
.setContentText(descText)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.build()

notificationManager.notify(1001, notification)
}
} No newline at end of file
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new ZombieCheckWorker class lacks test coverage. Given that the codebase has tests for other components (e.g., LoginRetrofitClientTest, TimeUtilsTest), consider adding tests for the worker to verify the logic for checking running records, calculating durations, and the threshold comparison. This is especially important for background jobs that run periodically without user interaction.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link

Copilot AI commented Jan 30, 2026

@ardevd I've opened a new pull request, #38, to work on those changes. Once the pull request is ready, I'll request review from you.

@ardevd ardevd merged commit 4f8fe2c into main Jan 30, 2026
2 checks passed
@ardevd ardevd deleted the zombie-record-checks branch January 30, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants