diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f03780c..46cb505 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,8 +11,8 @@ android { applicationId = "com.expapp.trigger" minSdk = 24 targetSdk = 34 - versionCode = 10 - versionName = "1.1.6" + versionCode = 11 + versionName = "1.1.7" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/com/expapp/trigger/data/repository/AppSettings.kt b/app/src/main/java/com/expapp/trigger/data/repository/AppSettings.kt index b57716d..dde5018 100644 --- a/app/src/main/java/com/expapp/trigger/data/repository/AppSettings.kt +++ b/app/src/main/java/com/expapp/trigger/data/repository/AppSettings.kt @@ -10,8 +10,16 @@ class AppSettings(private val storage: KeyValueStorage) { private const val KEY_BIOMETRIC_ENABLED = "key_biometric_enabled" private const val KEY_BG_MONITOR_ENABLED = "key_bg_monitor_enabled" private const val KEY_LAST_STATUS_PREFIX = "last_status_" + private const val KEY_LAST_NOTIFIED_VERSION = "key_last_notified_version" } + var lastNotifiedUpdateVersion: String? + get() = storage.getString(KEY_LAST_NOTIFIED_VERSION, null) + set(value) { + if (value != null) storage.putString(KEY_LAST_NOTIFIED_VERSION, value) + else storage.remove(KEY_LAST_NOTIFIED_VERSION) + } + var isBiometricEnabled: Boolean get() = storage.getBoolean(KEY_BIOMETRIC_ENABLED, true) set(value) = storage.putBoolean(KEY_BIOMETRIC_ENABLED, value) diff --git a/app/src/main/java/com/expapp/trigger/ui/screens/MainScreen.kt b/app/src/main/java/com/expapp/trigger/ui/screens/MainScreen.kt index 3d3b3ff..7c737fa 100644 --- a/app/src/main/java/com/expapp/trigger/ui/screens/MainScreen.kt +++ b/app/src/main/java/com/expapp/trigger/ui/screens/MainScreen.kt @@ -210,6 +210,11 @@ fun MainScreen( is UpdateCheckResult.UpdateAvailable -> { availableUpdate = result.info showUpdateDialog = true + val newVer = result.info.versionName + if (appSettings.lastNotifiedUpdateVersion != newVer) { + appSettings.lastNotifiedUpdateVersion = newVer + com.expapp.trigger.worker.NotificationHelper.sendUpdateAvailableNotification(context, newVer) + } if (isManual) { Toast.makeText(context, "New update available: v${result.info.versionName}!", Toast.LENGTH_SHORT).show() } diff --git a/app/src/main/java/com/expapp/trigger/worker/NotificationHelper.kt b/app/src/main/java/com/expapp/trigger/worker/NotificationHelper.kt index b5c8f79..8675cb7 100644 --- a/app/src/main/java/com/expapp/trigger/worker/NotificationHelper.kt +++ b/app/src/main/java/com/expapp/trigger/worker/NotificationHelper.kt @@ -45,12 +45,16 @@ object NotificationHelper { id: Int, title: String, message: String, - isSuccess: Boolean = true + isSuccess: Boolean = true, + extraAction: String? = null ): Boolean { createNotificationChannel(context) val intent = Intent(context, MainActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP + if (extraAction != null) { + putExtra("action_trigger", extraAction) + } } val pendingIntent = PendingIntent.getActivity( context, @@ -81,6 +85,17 @@ object NotificationHelper { } } + fun sendUpdateAvailableNotification(context: Context, newVersion: String): Boolean { + return sendNotification( + context = context, + id = 8888, + title = "🚀 Update Available: v$newVersion", + message = "A new version (v$newVersion) of Device Trigger is ready to install. Tap to update!", + isSuccess = true, + extraAction = "open_update" + ) + } + fun sendTestNotification(context: Context): Boolean { return sendNotification( context = context, diff --git a/app/src/main/java/com/expapp/trigger/worker/ServerMonitorWorker.kt b/app/src/main/java/com/expapp/trigger/worker/ServerMonitorWorker.kt index 8a9a72f..e727e04 100644 --- a/app/src/main/java/com/expapp/trigger/worker/ServerMonitorWorker.kt +++ b/app/src/main/java/com/expapp/trigger/worker/ServerMonitorWorker.kt @@ -120,6 +120,24 @@ class ServerMonitorWorker( } } + // Check for app updates in the background and notify if a new update is found + try { + val updateManager = com.expapp.trigger.update.UpdateManager(appContext) + val currentVersion = com.expapp.trigger.BuildConfig.VERSION_NAME + updateManager.checkForUpdate(currentVersion) { result -> + if (result is com.expapp.trigger.update.UpdateCheckResult.UpdateAvailable) { + val newVer = result.info.versionName + val lastNotified = appSettings.lastNotifiedUpdateVersion + if (lastNotified != newVer) { + appSettings.lastNotifiedUpdateVersion = newVer + NotificationHelper.sendUpdateAvailableNotification(appContext, newVer) + } + } + } + } catch (_: Exception) { + // Ignore background check failure + } + return Result.success() } }