diff options
| author | jacquarg <guillaume.jacquart@hoodbrains.com> | 2022-04-12 09:09:40 +0200 |
|---|---|---|
| committer | jacquarg <guillaume.jacquart@hoodbrains.com> | 2022-04-12 09:09:40 +0200 |
| commit | 5cdeb5520c74fbaab1909dc1876361ed73f11b55 (patch) | |
| tree | efc762c2e7e99f7821e9808f86c74fc693c5d9ad /app/src/main/java/foundation/e/privacycentralapp/common | |
| parent | 714db561375e369a9bc080447de6a7b5e619870b (diff) | |
| download | advanced-privacy-5cdeb5520c74fbaab1909dc1876361ed73f11b55.tar.gz | |
5249 display whitelisted trackers count in app trackers menu subtitle.
Diffstat (limited to 'app/src/main/java/foundation/e/privacycentralapp/common')
| -rw-r--r-- | app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt | 146 |
1 files changed, 73 insertions, 73 deletions
diff --git a/app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt b/app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt index a26c06a..f43c2cc 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt @@ -1,73 +1,73 @@ -/*
- * Copyright (C) 2022 E FOUNDATION
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package foundation.e.privacycentralapp.common
-
-import android.app.NotificationChannel
-import android.app.NotificationManager
-import android.app.PendingIntent
-import android.content.BroadcastReceiver
-import android.content.Context
-import android.content.Intent
-import androidx.core.app.NotificationCompat
-import foundation.e.privacycentralapp.R
-import foundation.e.privacycentralapp.data.repositories.LocalStateRepository
-
-class BootCompletedReceiver : BroadcastReceiver() {
- companion object {
- const val FIRST_BOOT_NOTIFICATION_ID = 10
- }
-
- override fun onReceive(context: Context, intent: Intent?) {
- if (intent?.action == Intent.ACTION_BOOT_COMPLETED) {
- val localStateRepository = LocalStateRepository(context)
- if (localStateRepository.firstBoot) {
- showNotification(context)
- localStateRepository.firstBoot = false
- }
- }
- }
-
- private fun showNotification(context: Context) {
- val channelId = "first_boot_notification"
- val pendingIntent =
- PendingIntent.getActivity(
- context,
- 0,
- context.packageManager.getLaunchIntentForPackage(context.packageName),
- PendingIntent.FLAG_IMMUTABLE
- )
- val notificationBuilder: NotificationCompat.Builder =
- NotificationCompat.Builder(context, channelId)
- .setSmallIcon(R.drawable.ic_notification_logo)
- .setContentTitle(context.getString(R.string.first_notification_title))
- .setAutoCancel(true)
- .setContentIntent(pendingIntent)
- .setStyle(
- NotificationCompat.BigTextStyle()
- .bigText(context.getString(R.string.first_notification_summary))
- )
- val notificationManager =
- context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
-
- val name: CharSequence = "First Boot"
- val importance = NotificationManager.IMPORTANCE_HIGH
- val mChannel = NotificationChannel(channelId, name, importance)
- notificationManager.createNotificationChannel(mChannel)
- notificationManager.notify(FIRST_BOOT_NOTIFICATION_ID, notificationBuilder.build())
- }
-}
+/* + * Copyright (C) 2022 E FOUNDATION + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package foundation.e.privacycentralapp.common + +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import androidx.core.app.NotificationCompat +import foundation.e.privacycentralapp.R +import foundation.e.privacycentralapp.data.repositories.LocalStateRepository + +class BootCompletedReceiver : BroadcastReceiver() { + companion object { + const val FIRST_BOOT_NOTIFICATION_ID = 10 + } + + override fun onReceive(context: Context, intent: Intent?) { + if (intent?.action == Intent.ACTION_BOOT_COMPLETED) { + val localStateRepository = LocalStateRepository(context) + if (localStateRepository.firstBoot) { + showNotification(context) + localStateRepository.firstBoot = false + } + } + } + + private fun showNotification(context: Context) { + val channelId = "first_boot_notification" + val pendingIntent = + PendingIntent.getActivity( + context, + 0, + context.packageManager.getLaunchIntentForPackage(context.packageName), + PendingIntent.FLAG_IMMUTABLE + ) + val notificationBuilder: NotificationCompat.Builder = + NotificationCompat.Builder(context, channelId) + .setSmallIcon(R.drawable.ic_notification_logo) + .setContentTitle(context.getString(R.string.first_notification_title)) + .setAutoCancel(true) + .setContentIntent(pendingIntent) + .setStyle( + NotificationCompat.BigTextStyle() + .bigText(context.getString(R.string.first_notification_summary)) + ) + val notificationManager = + context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + + val name: CharSequence = "First Boot" + val importance = NotificationManager.IMPORTANCE_HIGH + val mChannel = NotificationChannel(channelId, name, importance) + notificationManager.createNotificationChannel(mChannel) + notificationManager.notify(FIRST_BOOT_NOTIFICATION_ID, notificationBuilder.build()) + } +} |
