From 861465748bd4763a645cb62f3c53d149e07a8cc9 Mon Sep 17 00:00:00 2001 From: ya0211 Date: Fri, 9 Jun 2023 11:46:40 +0800 Subject: [PATCH] Move constant values of Notification to NotificationUtils --- app/src/main/kotlin/com/sanmer/geomag/app/Const.kt | 6 ------ .../com/sanmer/geomag/app/utils/NotificationUtils.kt | 10 +++++++--- .../com/sanmer/geomag/service/CalculateService.kt | 5 ++--- .../com/sanmer/geomag/service/LocationService.kt | 5 ++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/sanmer/geomag/app/Const.kt b/app/src/main/kotlin/com/sanmer/geomag/app/Const.kt index e9ba071..b6524f6 100644 --- a/app/src/main/kotlin/com/sanmer/geomag/app/Const.kt +++ b/app/src/main/kotlin/com/sanmer/geomag/app/Const.kt @@ -1,12 +1,6 @@ package com.sanmer.geomag.app object Const { - // NOTIFICATION - const val CHANNEL_ID_LOCATION = "location_service" - const val CHANNEL_ID_CALCULATE = "calculate_service" - const val NOTIFICATION_ID_LOCATION = 1024 - const val NOTIFICATION_ID_CALCULATE = 1025 - // URL const val TRANSLATE_URL = "https://weblate.sanmer.dev/engage/geomag" const val GITHUB_URL = "https://github.com/ya0211/Geomag" diff --git a/app/src/main/kotlin/com/sanmer/geomag/app/utils/NotificationUtils.kt b/app/src/main/kotlin/com/sanmer/geomag/app/utils/NotificationUtils.kt index 774771a..8286a16 100644 --- a/app/src/main/kotlin/com/sanmer/geomag/app/utils/NotificationUtils.kt +++ b/app/src/main/kotlin/com/sanmer/geomag/app/utils/NotificationUtils.kt @@ -20,21 +20,25 @@ import com.google.accompanist.permissions.isGranted import com.google.accompanist.permissions.rememberPermissionState import com.sanmer.geomag.App import com.sanmer.geomag.R -import com.sanmer.geomag.app.Const import kotlin.reflect.KClass object NotificationUtils { + const val CHANNEL_ID_LOCATION = "location_service" + const val CHANNEL_ID_CALCULATE = "calculate_service" + const val NOTIFICATION_ID_LOCATION = 1024 + const val NOTIFICATION_ID_CALCULATE = 1025 + val context by lazy { App.context } private val notificationManager by lazy { NotificationManagerCompat.from(context) } init { val channels = listOf( - NotificationChannel(Const.CHANNEL_ID_LOCATION, + NotificationChannel(CHANNEL_ID_LOCATION, context.getString(R.string.notification_name_location), NotificationManager.IMPORTANCE_HIGH ), - NotificationChannel(Const.CHANNEL_ID_CALCULATE, + NotificationChannel(CHANNEL_ID_CALCULATE, context.getString(R.string.notification_name_calculate), NotificationManager.IMPORTANCE_HIGH ) diff --git a/app/src/main/kotlin/com/sanmer/geomag/service/CalculateService.kt b/app/src/main/kotlin/com/sanmer/geomag/service/CalculateService.kt index ee3089b..3349e1a 100644 --- a/app/src/main/kotlin/com/sanmer/geomag/service/CalculateService.kt +++ b/app/src/main/kotlin/com/sanmer/geomag/service/CalculateService.kt @@ -11,7 +11,6 @@ import androidx.lifecycle.LifecycleService import androidx.lifecycle.lifecycleScope import com.sanmer.geomag.Geomag import com.sanmer.geomag.R -import com.sanmer.geomag.app.Const import com.sanmer.geomag.app.utils.NotificationUtils import com.sanmer.geomag.model.Position import com.sanmer.geomag.model.Record @@ -89,7 +88,7 @@ class CalculateService : LifecycleService() { PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) val notification = NotificationUtils - .buildNotification(this, Const.CHANNEL_ID_CALCULATE) + .buildNotification(this, NotificationUtils.CHANNEL_ID_CALCULATE) .setSmallIcon(R.drawable.maze_oultine) .setContentTitle(getString(R.string.notification_name_calculate)) .setContentText(getString(R.string.message_location_click)) @@ -98,7 +97,7 @@ class CalculateService : LifecycleService() { .setOngoing(true) .build() - startForeground(Const.NOTIFICATION_ID_CALCULATE, notification) + startForeground(NotificationUtils.NOTIFICATION_ID_CALCULATE, notification) } companion object { diff --git a/app/src/main/kotlin/com/sanmer/geomag/service/LocationService.kt b/app/src/main/kotlin/com/sanmer/geomag/service/LocationService.kt index 1b35840..584e17a 100644 --- a/app/src/main/kotlin/com/sanmer/geomag/service/LocationService.kt +++ b/app/src/main/kotlin/com/sanmer/geomag/service/LocationService.kt @@ -14,7 +14,6 @@ import androidx.lifecycle.LifecycleService import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope import com.sanmer.geomag.R -import com.sanmer.geomag.app.Const import com.sanmer.geomag.app.utils.LocationManagerUtils import com.sanmer.geomag.app.utils.NotificationUtils import com.sanmer.geomag.ui.activity.main.MainActivity @@ -62,7 +61,7 @@ class LocationService : LifecycleService() { PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) val notification = NotificationUtils - .buildNotification(this, Const.CHANNEL_ID_LOCATION) + .buildNotification(this, NotificationUtils.CHANNEL_ID_LOCATION) .setSmallIcon(R.drawable.location_outline) .setContentTitle(getString(R.string.notification_name_location)) .setContentText(getString(R.string.message_location_click)) @@ -71,7 +70,7 @@ class LocationService : LifecycleService() { .setOngoing(true) .build() - startForeground(Const.NOTIFICATION_ID_LOCATION, notification) + startForeground(NotificationUtils.NOTIFICATION_ID_LOCATION, notification) } companion object {