From 4bd37041c3ace75e4ac5bfbd87fe6d1cfad8038a Mon Sep 17 00:00:00 2001 From: TheScarastic Date: Mon, 11 Apr 2022 14:51:12 +0530 Subject: privacycentralapp: Add notification on 1st boot to tell us more about our app --- app/src/main/AndroidManifest.xml | 9 +++ .../common/BootCompletedReceiver.kt | 73 ++++++++++++++++++++++ .../data/repositories/LocalStateRepository.kt | 8 ++- app/src/main/res/drawable/ic_notification_logo.xml | 33 ++++++++++ app/src/main/res/values/strings.xml | 3 + 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/foundation/e/privacycentralapp/common/BootCompletedReceiver.kt create mode 100644 app/src/main/res/drawable/ic_notification_logo.xml (limited to 'app') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cbb4ccc..d285b6f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,6 +31,15 @@ android:windowSoftInputMode="adjustResize" tools:replace="android:icon,android:label,android:theme" > + + + + + + + . + */ + +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()) + } +} diff --git a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt index 145ff32..9a7fd15 100644 --- a/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt +++ b/app/src/main/java/foundation/e/privacycentralapp/data/repositories/LocalStateRepository.kt @@ -28,11 +28,13 @@ class LocalStateRepository(context: Context) { private const val KEY_IP_SCRAMBLING = "ipScrambling" private const val KEY_FAKE_LATITUDE = "fakeLatitude" private const val KEY_FAKE_LONGITUDE = "fakeLongitude" + private const val KEY_FIRST_BOOT = "firstBoot" } private val sharedPref = context.getSharedPreferences(SHARED_PREFS_FILE, Context.MODE_PRIVATE) - private val quickPrivacyEnabledMutableFlow = MutableStateFlow(sharedPref.getBoolean(KEY_QUICK_PRIVACY, false)) + private val quickPrivacyEnabledMutableFlow = + MutableStateFlow(sharedPref.getBoolean(KEY_QUICK_PRIVACY, false)) var isQuickPrivacyEnabled: Boolean get() = quickPrivacyEnabledMutableFlow.value set(value) { @@ -70,6 +72,10 @@ class LocalStateRepository(context: Context) { get() = sharedPref.getBoolean(KEY_IP_SCRAMBLING, false) set(value) = set(KEY_IP_SCRAMBLING, value) + var firstBoot: Boolean + get() = sharedPref.getBoolean(KEY_FIRST_BOOT, true) + set(value) = set(KEY_FIRST_BOOT, value) + private fun set(key: String, value: Boolean) { sharedPref.edit().putBoolean(key, value).commit() } diff --git a/app/src/main/res/drawable/ic_notification_logo.xml b/app/src/main/res/drawable/ic_notification_logo.xml new file mode 100644 index 0000000..a8ec9c2 --- /dev/null +++ b/app/src/main/res/drawable/ic_notification_logo.xml @@ -0,0 +1,33 @@ + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 88bd473..199472d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,4 +134,7 @@ @string/dashboard_state_ipaddress_off @string/dashboard_state_ipaddress_on @string/dashboard_graph_trackers_legend + + Discover Advanced Privacy + Tap to find out how to easily block trackers, fake your location & hide your IP address. \ No newline at end of file -- cgit v1.2.1