-
Notifications
You must be signed in to change notification settings - Fork 0
feat: added zombie record background check #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
periodically check for long running records and notify users in case they have forgotten to end a timer.
There was a problem hiding this 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.
app/src/main/java/net/ardevd/tagius/features/background/ZombieCheckWorker.kt
Show resolved
Hide resolved
| 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 |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
periodically check for long running records and notify users in case they have forgotten to end a timer.