From f4eaba00a5614d0f04942ab6120cfd033292fa37 Mon Sep 17 00:00:00 2001 From: S1m Date: Tue, 16 Jan 2024 23:44:41 +0100 Subject: [PATCH] Lint --- .../distributor/nextpush/api/SSEListener.kt | 3 ++- .../services/RegistrationCountCache.kt | 26 +++++++++---------- .../nextpush/services/StartService.kt | 5 +++- .../nextpush/utils/Notifications.kt | 4 +-- .../distributor/nextpush/utils/Queues.kt | 3 +-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt index 652bd5b..0d62b6e 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt @@ -96,7 +96,8 @@ class SSEListener(val context: Context) : EventSourceListener() { "deleteApp" -> { val message = Gson().fromJson(data, SSEResponse::class.java) if (Database.getDb(context).getPackageName(message.token) != null && - !AppCompanion.delQueue.containsTokenElseAdd(message.token)) { + !AppCompanion.delQueue.containsTokenElseAdd(message.token) + ) { deleteAppFromSSE(context, message.token) AppCompanion.delQueue.removeToken(message.token) } diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/RegistrationCountCache.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/RegistrationCountCache.kt index 4e4d1f1..ef44bfa 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/RegistrationCountCache.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/RegistrationCountCache.kt @@ -15,20 +15,20 @@ object RegistrationCountCache { } } - fun refresh(context: Context) = synchronized(this) { - nRegistrations = null - val count = getCount(context) - Log.d(TAG, "Refreshing nRegistrations to $count") - // if n == 1: start the SSE (The fg service starts on boot, but doesn't connect without reg) - // if n == 0: We keep the foreground service but stop the SSE/RestarWorker - // The Runner will starts StartService, which will disconnect the SSE - if (count in intArrayOf(0,1)) { - RestartWorker.run(context, delay = 0, force = true) - } - ForegroundNotification(context).update() - } + fun refresh(context: Context) = synchronized(this) { + nRegistrations = null + val count = getCount(context) + Log.d(TAG, "Refreshing nRegistrations to $count") + // if n == 1: start the SSE (The fg service starts on boot, but doesn't connect without reg) + // if n == 0: We keep the foreground service but stop the SSE/RestarWorker + // The Runner will starts StartService, which will disconnect the SSE + if (count in intArrayOf(0, 1)) { + RestartWorker.run(context, delay = 0, force = true) + } + ForegroundNotification(context).update() + } fun oneOrMore(context: Context): Boolean = synchronized(this) { return getCount(context) > 0 } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt index 9075d74..5d4267d 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt @@ -104,7 +104,10 @@ class StartService : Service() { if (isServiceStarted && !FailureHandler.hasFailed() && // If there is no registration, this is a request to stop the SSE - RegistrationCountCache.oneOrMore(context)) return + RegistrationCountCache.oneOrMore(context) + ) { + return + } Log.d(TAG, "Starting the Listener") Log.d(TAG, "Service is started: $isServiceStarted") Log.d(TAG, "nFails: ${FailureHandler.nFails()}") diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/utils/Notifications.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/utils/Notifications.kt index 232b031..d9dfc9f 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/utils/Notifications.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/utils/Notifications.kt @@ -44,7 +44,7 @@ open class AppNotification( private val shown: AtomicBoolean, private val notificationId: Int, private val notificationData: NotificationData, - private val channelData: ChannelData, + private val channelData: ChannelData ) { internal fun createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -221,7 +221,7 @@ class NoServerAppNotification(val context: Context) : AppNotification( ), context.warningChannelData ) { - override fun create(bigText: Boolean): Notification{ + override fun create(bigText: Boolean): Notification { createNotificationChannel() val notificationIntent = Intent(Intent.ACTION_VIEW) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/utils/Queues.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/utils/Queues.kt index 69759dd..2d86abc 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/utils/Queues.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/utils/Queues.kt @@ -4,7 +4,6 @@ import android.util.Log import java.util.Timer import kotlin.concurrent.schedule - fun MutableList.containsTokenElseAdd(connectorToken: String): Boolean { return synchronized(this) { if (connectorToken !in this) { @@ -28,4 +27,4 @@ private fun delayRemove(list: MutableList, token: String) { Timer().schedule(1_000L /* 1sec */) { list.removeToken(token) } -} \ No newline at end of file +}