Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
256cc6cfc8 |
@@ -11,8 +11,8 @@ android {
|
|||||||
applicationId = "com.expapp.trigger"
|
applicationId = "com.expapp.trigger"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 10
|
versionCode = 11
|
||||||
versionName = "1.1.6"
|
versionName = "1.1.7"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables {
|
vectorDrawables {
|
||||||
|
|||||||
@@ -10,8 +10,16 @@ class AppSettings(private val storage: KeyValueStorage) {
|
|||||||
private const val KEY_BIOMETRIC_ENABLED = "key_biometric_enabled"
|
private const val KEY_BIOMETRIC_ENABLED = "key_biometric_enabled"
|
||||||
private const val KEY_BG_MONITOR_ENABLED = "key_bg_monitor_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_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
|
var isBiometricEnabled: Boolean
|
||||||
get() = storage.getBoolean(KEY_BIOMETRIC_ENABLED, true)
|
get() = storage.getBoolean(KEY_BIOMETRIC_ENABLED, true)
|
||||||
set(value) = storage.putBoolean(KEY_BIOMETRIC_ENABLED, value)
|
set(value) = storage.putBoolean(KEY_BIOMETRIC_ENABLED, value)
|
||||||
|
|||||||
@@ -210,6 +210,11 @@ fun MainScreen(
|
|||||||
is UpdateCheckResult.UpdateAvailable -> {
|
is UpdateCheckResult.UpdateAvailable -> {
|
||||||
availableUpdate = result.info
|
availableUpdate = result.info
|
||||||
showUpdateDialog = true
|
showUpdateDialog = true
|
||||||
|
val newVer = result.info.versionName
|
||||||
|
if (appSettings.lastNotifiedUpdateVersion != newVer) {
|
||||||
|
appSettings.lastNotifiedUpdateVersion = newVer
|
||||||
|
com.expapp.trigger.worker.NotificationHelper.sendUpdateAvailableNotification(context, newVer)
|
||||||
|
}
|
||||||
if (isManual) {
|
if (isManual) {
|
||||||
Toast.makeText(context, "New update available: v${result.info.versionName}!", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "New update available: v${result.info.versionName}!", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,12 +45,16 @@ object NotificationHelper {
|
|||||||
id: Int,
|
id: Int,
|
||||||
title: String,
|
title: String,
|
||||||
message: String,
|
message: String,
|
||||||
isSuccess: Boolean = true
|
isSuccess: Boolean = true,
|
||||||
|
extraAction: String? = null
|
||||||
): Boolean {
|
): Boolean {
|
||||||
createNotificationChannel(context)
|
createNotificationChannel(context)
|
||||||
|
|
||||||
val intent = Intent(context, MainActivity::class.java).apply {
|
val intent = Intent(context, MainActivity::class.java).apply {
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
if (extraAction != null) {
|
||||||
|
putExtra("action_trigger", extraAction)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val pendingIntent = PendingIntent.getActivity(
|
val pendingIntent = PendingIntent.getActivity(
|
||||||
context,
|
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 {
|
fun sendTestNotification(context: Context): Boolean {
|
||||||
return sendNotification(
|
return sendNotification(
|
||||||
context = context,
|
context = context,
|
||||||
|
|||||||
@@ -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()
|
return Result.success()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user