Skip to content

Commit

Permalink
refactor : NotificationUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
nohjunh committed Jan 26, 2025
1 parent c702268 commit 764bfd1
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@ import android.content.Intent
import android.provider.Settings
import androidx.core.app.NotificationManagerCompat

internal fun handleNotificationToggle(
context: Context,
checked: Boolean,
onNotificationToggled: (Boolean) -> Unit,
) {
if (checked) {
if (checkSystemNotificationEnabled(context)) {
onNotificationToggled(true)
object NotificationUtil {
fun handleNotificationToggle(
context: Context,
checked: Boolean,
onNotificationToggled: (Boolean) -> Unit,
) {
if (checked) {
if (checkSystemNotificationEnabled(context)) {
onNotificationToggled(true)
} else {
openSystemNotificationSetting(context)
}
} else {
openSystemNotificationSetting(context)
onNotificationToggled(false)
}
} else {
onNotificationToggled(false)
}
}

internal fun checkSystemNotificationEnabled(context: Context) =
NotificationManagerCompat
.from(context)
.areNotificationsEnabled()
fun checkSystemNotificationEnabled(context: Context) =
NotificationManagerCompat
.from(context)
.areNotificationsEnabled()

private fun openSystemNotificationSetting(context: Context) {
val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.apply {
putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
}
private fun openSystemNotificationSetting(context: Context) {
val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
.apply {
putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
}

context.startActivity(intent)
context.startActivity(intent)
}
}

0 comments on commit 764bfd1

Please sign in to comment.