fix: notification worker reliability + version bump to 1.1.0

- Bump android versionCode=2 versionName=1.1.0
- NotificationWorker: use UPDATE policy to reschedule after login
- Immediate notification check on login via LaunchedEffect
- Added logging for debugging notification delivery
- DB already has test notification inserted
- Fixed admin app version form (POST redirect)
This commit is contained in:
2026-06-09 17:31:26 -04:00
parent 1f67fc1fcd
commit ddec27ca5c
5 changed files with 43 additions and 9 deletions

View File

@@ -12,8 +12,8 @@ android {
applicationId = "com.devlab.app"
minSdk = 26
targetSdk = 37
versionCode = 1
versionName = "1.0.0"
versionCode = 2
versionName = "1.1.0"
}
buildTypes {

View File

@@ -107,10 +107,17 @@ class MainActivity : ComponentActivity() {
@Composable
fun AppRoot() {
val context = androidx.compose.ui.platform.LocalContext.current
val navController = rememberNavController()
val loginViewModel: LoginViewModel = viewModel()
var isLoggedIn by remember { mutableStateOf(false) }
LaunchedEffect(isLoggedIn) {
if (isLoggedIn) {
NotificationWorker.checkNow(context)
}
}
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination

View File

@@ -1,6 +1,7 @@
package com.devlab.app.worker
import android.content.Context
import android.util.Log
import androidx.work.*
import com.devlab.app.data.api.RetrofitClient
import com.devlab.app.data.model.AppNotification
@@ -21,37 +22,51 @@ class NotificationWorker(
val token = prefs.getToken()
if (token.isBlank()) {
Log.d("NotificationWorker", "No token, skipping")
return@withContext Result.success()
}
val lastCheck = prefs.getLastNotificationCheck()
val now = System.currentTimeMillis()
Log.d("NotificationWorker", "Checking notifications since $lastCheck")
RetrofitClient.setToken(token)
val service = RetrofitClient.getApiService()
try {
val response = service.getNotifications(page = 1, perPage = 50)
if (response.success) {
Log.d("NotificationWorker", "Got ${response.data.size} notifications, unread: ${response.unread_count}")
val newNotifications = response.data.filter { note ->
val noteTime = parseTime(note.created_at)
noteTime > lastCheck && note.is_read == 0
}
Log.d("NotificationWorker", "New notifications to show: ${newNotifications.size}")
for (notification in newNotifications) {
NotificationHelper.showNotification(applicationContext, notification)
}
val lastTime = newNotifications.maxOfOrNull {
val maxTime = newNotifications.maxOfOrNull {
parseTime(it.created_at)
} ?: System.currentTimeMillis()
} ?: now
prefs.setLastNotificationCheck(
if (newNotifications.isNotEmpty()) lastTime else System.currentTimeMillis()
if (newNotifications.isNotEmpty()) maxTime else now
)
} else {
Log.d("NotificationWorker", "API returned success=false: ${response.error}")
}
} catch (_: Exception) { }
} catch (e: Exception) {
Log.e("NotificationWorker", "API error: ${e.message}")
}
Result.success()
} catch (_: Exception) {
} catch (e: Exception) {
Log.e("NotificationWorker", "Worker error: ${e.message}")
Result.retry()
}
}
@@ -88,9 +103,10 @@ class NotificationWorker(
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
WORK_NAME,
ExistingPeriodicWorkPolicy.KEEP,
ExistingPeriodicWorkPolicy.UPDATE,
request
)
Log.d("NotificationWorker", "Scheduled periodic check every 15 min")
}
fun checkNow(context: Context) {
@@ -103,6 +119,7 @@ class NotificationWorker(
.build()
WorkManager.getInstance(context).enqueue(request)
Log.d("NotificationWorker", "Scheduled immediate check")
}
}
}