Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Move constant values of Notification to NotificationUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Jun 9, 2023
1 parent 0f03b9a commit 8614657
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
6 changes: 0 additions & 6 deletions app/src/main/kotlin/com/sanmer/geomag/app/Const.kt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -98,7 +97,7 @@ class CalculateService : LifecycleService() {
.setOngoing(true)
.build()

startForeground(Const.NOTIFICATION_ID_CALCULATE, notification)
startForeground(NotificationUtils.NOTIFICATION_ID_CALCULATE, notification)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -71,7 +70,7 @@ class LocationService : LifecycleService() {
.setOngoing(true)
.build()

startForeground(Const.NOTIFICATION_ID_LOCATION, notification)
startForeground(NotificationUtils.NOTIFICATION_ID_LOCATION, notification)
}

companion object {
Expand Down

0 comments on commit 8614657

Please sign in to comment.