From b6337b36a0371cfb8b31f797181846d783ab7947 Mon Sep 17 00:00:00 2001 From: Thore Goebel Date: Wed, 1 Jan 2025 13:04:46 +0100 Subject: [PATCH 1/2] Centralise advertisement drawables and strings --- .../Enums/AdvertisementSetType.kt | 30 ++++- .../Enums/AdvertisementTarget.kt | 16 ++- .../AdvertisementForegroundService.kt | 103 +++--------------- .../ui/advertisement/AdvertisementFragment.kt | 12 +- .../AdvertisementCollectionFragment.kt | 31 +----- app/src/main/res/values/strings.xml | 20 +++- 6 files changed, 87 insertions(+), 125 deletions(-) diff --git a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/AdvertisementSetType.kt b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/AdvertisementSetType.kt index 4d962f73..9ed8b59a 100644 --- a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/AdvertisementSetType.kt +++ b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/AdvertisementSetType.kt @@ -1,5 +1,8 @@ package de.simon.dankelmann.bluetoothlespam.Enums +import de.simon.dankelmann.bluetoothlespam.R + + enum class AdvertisementSetType { ADVERTISEMENT_TYPE_UNDEFINED, ADVERTISEMENT_TYPE_FAST_PAIRING_DEVICE, @@ -16,4 +19,29 @@ enum class AdvertisementSetType { ADVERTISEMENT_TYPE_EASY_SETUP_BUDS, ADVERTISEMENT_TYPE_LOVESPOUSE_PLAY, ADVERTISEMENT_TYPE_LOVESPOUSE_STOP -} \ No newline at end of file +} + +fun AdvertisementSetType.stringResId(): Int { + return when (this) { + AdvertisementSetType.ADVERTISEMENT_TYPE_UNDEFINED -> R.string.ad_set_type_undefined + + AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_DEVICE -> R.string.ad_set_type_fast_pairing_device + AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_NON_PRODUCTION -> R.string.ad_set_type_fast_pairing_non_production + AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_PHONE_SETUP -> R.string.ad_set_type_fast_pairing_phone_setup + AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_DEBUG -> R.string.ad_set_type_fast_pairing_debug + + AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NEW_AIRTAG -> R.string.ad_set_type_continuity_new_airtag + AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NEW_DEVICE -> R.string.ad_set_type_continuity_new_device + AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NOT_YOUR_DEVICE -> R.string.ad_set_type_continuity_not_your_device + AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_ACTION_MODALS -> R.string.ad_set_type_continuity_action_modals + AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_IOS_17_CRASH -> R.string.ad_set_type_continuity_ios17_crash + + AdvertisementSetType.ADVERTISEMENT_TYPE_SWIFT_PAIRING -> R.string.ad_set_type_swift_pairing + + AdvertisementSetType.ADVERTISEMENT_TYPE_EASY_SETUP_WATCH -> R.string.ad_set_type_easy_setup_watch + AdvertisementSetType.ADVERTISEMENT_TYPE_EASY_SETUP_BUDS -> R.string.ad_set_type_easy_setup_buds + + AdvertisementSetType.ADVERTISEMENT_TYPE_LOVESPOUSE_PLAY -> R.string.ad_set_type_lovespouse_play + AdvertisementSetType.ADVERTISEMENT_TYPE_LOVESPOUSE_STOP -> R.string.ad_set_type_lovespouse_stop + } +} diff --git a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/AdvertisementTarget.kt b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/AdvertisementTarget.kt index 311da3f6..961cb017 100644 --- a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/AdvertisementTarget.kt +++ b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/AdvertisementTarget.kt @@ -1,5 +1,7 @@ package de.simon.dankelmann.bluetoothlespam.Enums +import de.simon.dankelmann.bluetoothlespam.R + enum class AdvertisementTarget { ADVERTISEMENT_TARGET_KITCHEN_SINK, ADVERTISEMENT_TARGET_UNDEFINED, @@ -8,4 +10,16 @@ enum class AdvertisementTarget { ADVERTISEMENT_TARGET_WINDOWS, ADVERTISEMENT_TARGET_SAMSUNG, ADVERTISEMENT_TARGET_LOVESPOUSE -} \ No newline at end of file +} + +fun AdvertisementTarget.getDrawableId(): Int { + return when (this) { + AdvertisementTarget.ADVERTISEMENT_TARGET_SAMSUNG -> R.drawable.samsung + AdvertisementTarget.ADVERTISEMENT_TARGET_ANDROID -> R.drawable.ic_android + AdvertisementTarget.ADVERTISEMENT_TARGET_IOS -> R.drawable.apple + AdvertisementTarget.ADVERTISEMENT_TARGET_UNDEFINED -> R.drawable.bluetooth + AdvertisementTarget.ADVERTISEMENT_TARGET_WINDOWS -> R.drawable.microsoft + AdvertisementTarget.ADVERTISEMENT_TARGET_KITCHEN_SINK -> R.drawable.shuffle + AdvertisementTarget.ADVERTISEMENT_TARGET_LOVESPOUSE -> R.drawable.heart + } +} diff --git a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/AdvertisementForegroundService.kt b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/AdvertisementForegroundService.kt index ac194795..71c9fadf 100644 --- a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/AdvertisementForegroundService.kt +++ b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/AdvertisementForegroundService.kt @@ -19,9 +19,9 @@ import androidx.core.content.ContextCompat import androidx.navigation.NavDeepLinkBuilder import de.simon.dankelmann.bluetoothlespam.AppContext.AppContext import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementError -import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementSetType import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementState -import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementTarget +import de.simon.dankelmann.bluetoothlespam.Enums.getDrawableId +import de.simon.dankelmann.bluetoothlespam.Enums.stringResId import de.simon.dankelmann.bluetoothlespam.Interfaces.Callbacks.IAdvertisementServiceCallback import de.simon.dankelmann.bluetoothlespam.Interfaces.Callbacks.IAdvertisementSetQueueHandlerCallback import de.simon.dankelmann.bluetoothlespam.MainActivity @@ -80,7 +80,6 @@ class AdvertisementForegroundService: IAdvertisementServiceCallback, IAdvertisem super.onDestroy() } - private fun createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && AppContext.getActivity() != null) { val notificationManager = AppContext.getActivity().getSystemService(NOTIFICATION_SERVICE) as NotificationManager @@ -101,52 +100,10 @@ class AdvertisementForegroundService: IAdvertisementServiceCallback, IAdvertisem //.setArguments(bundle) .createPendingIntent() - // Custom Layout val notificationView = RemoteViews(packageName, R.layout.advertisement_foreground_service_notification) - var title = "" - var subtitle = "" - var targetImageId = R.drawable.bluetooth - - if (advertisementSet != null) { - title = advertisementSet.title - subtitle = when (advertisementSet.type) { - AdvertisementSetType.ADVERTISEMENT_TYPE_UNDEFINED -> "Undefined Type" - - AdvertisementSetType.ADVERTISEMENT_TYPE_EASY_SETUP_BUDS -> "Easy Setup Buds" - AdvertisementSetType.ADVERTISEMENT_TYPE_EASY_SETUP_WATCH -> "Easy Setup Watch" - - AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_DEVICE -> "Fast Pairing" - AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_NON_PRODUCTION -> "Fast Pairing" - AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_PHONE_SETUP -> "Fast Pairing" - AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_DEBUG -> "Fast Pairing" - - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NEW_DEVICE -> "New Apple Device" - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NEW_AIRTAG -> "New Airtag" - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NOT_YOUR_DEVICE -> "Not your Device" - - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_ACTION_MODALS -> "Apple Action" - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_IOS_17_CRASH -> "Apple iOs 17 Crash" - - AdvertisementSetType.ADVERTISEMENT_TYPE_SWIFT_PAIRING -> "Swift Pairing" - - AdvertisementSetType.ADVERTISEMENT_TYPE_LOVESPOUSE_PLAY -> "Lovespouse Play" - AdvertisementSetType.ADVERTISEMENT_TYPE_LOVESPOUSE_STOP -> "Lovespouse Stop" - } - - targetImageId = when (advertisementSet.target) { - AdvertisementTarget.ADVERTISEMENT_TARGET_SAMSUNG -> R.drawable.samsung - AdvertisementTarget.ADVERTISEMENT_TARGET_ANDROID -> R.drawable.ic_android - AdvertisementTarget.ADVERTISEMENT_TARGET_IOS -> R.drawable.apple - AdvertisementTarget.ADVERTISEMENT_TARGET_UNDEFINED -> R.drawable.bluetooth - AdvertisementTarget.ADVERTISEMENT_TARGET_WINDOWS -> R.drawable.microsoft - AdvertisementTarget.ADVERTISEMENT_TARGET_KITCHEN_SINK -> R.drawable.shuffle - AdvertisementTarget.ADVERTISEMENT_TARGET_LOVESPOUSE -> R.drawable.heart - } - } - - val toggleImageSrc = when(AppContext.getAdvertisementSetQueueHandler().isActive()){ + val toggleImageSrc = when (AppContext.getAdvertisementSetQueueHandler().isActive()) { true -> R.drawable.pause false -> R.drawable.play_arrow } @@ -154,15 +111,17 @@ class AdvertisementForegroundService: IAdvertisementServiceCallback, IAdvertisem // Views for Custom Layout notificationView.setTextViewText( R.id.advertisementForegroundServiceNotificationTitleTextView, - title - ) - notificationView.setTextViewText( - R.id.advertisementForegroundServiceNotificationSubTitleTextView, - subtitle + advertisementSet?.title ?: "" ) + advertisementSet?.type?.stringResId()?.let { resId -> + notificationView.setTextViewText( + R.id.advertisementForegroundServiceNotificationSubTitleTextView, + getString(resId) + ) + } notificationView.setImageViewResource( R.id.advertisementForegroundServiceNotificationTargetImageView, - targetImageId + advertisementSet?.target?.getDrawableId() ?: R.drawable.bluetooth ) notificationView.setImageViewResource( @@ -185,14 +144,12 @@ class AdvertisementForegroundService: IAdvertisementServiceCallback, IAdvertisem targetIconColor, targetIconColor ) - notificationView.setColorInt( R.id.advertisementForegroundServiceNotificationToggleImageView, "setColorFilter", buttonActiveColor, buttonActiveColor ) - notificationView.setColorInt( R.id.advertisementForegroundServiceNotificationStopImageView, "setColorFilter", @@ -205,13 +162,11 @@ class AdvertisementForegroundService: IAdvertisementServiceCallback, IAdvertisem "setColorFilter", targetIconColor ) - notificationView.setInt( R.id.advertisementForegroundServiceNotificationStopImageView, "setColorFilter", buttonActiveColor ) - notificationView.setInt( R.id.advertisementForegroundServiceNotificationToggleImageView, "setColorFilter", @@ -220,31 +175,13 @@ class AdvertisementForegroundService: IAdvertisementServiceCallback, IAdvertisem } if (advertisementSet != null) { - var titleColor = when (advertisementSet.advertisementState) { - AdvertisementState.ADVERTISEMENT_STATE_UNDEFINED -> resources.getColor( - R.color.color_title, - AppContext.getContext().theme - ) - - AdvertisementState.ADVERTISEMENT_STATE_STARTED -> resources.getColor( - R.color.color_title, - AppContext.getContext().theme - ) - - AdvertisementState.ADVERTISEMENT_STATE_SUCCEEDED -> resources.getColor( - R.color.color_title, - AppContext.getContext().theme - ) - - AdvertisementState.ADVERTISEMENT_STATE_FAILED -> resources.getColor( - R.color.log_error, - AppContext.getContext().theme - ) + val titleColorRes = when (advertisementSet.advertisementState) { + AdvertisementState.ADVERTISEMENT_STATE_FAILED -> R.color.log_error + else -> R.color.color_title } - notificationView.setTextColor( R.id.advertisementForegroundServiceNotificationTitleTextView, - titleColor + resources.getColor(titleColorRes, AppContext.getContext().theme) ) } @@ -275,18 +212,14 @@ class AdvertisementForegroundService: IAdvertisementServiceCallback, IAdvertisem pendingStopSwitchIntent ) - var contentText = "Bluetooth LE Spam" - if (advertisementSet != null) { - contentText = advertisementSet.title - } + val appName = getString(R.string.app_name) + val contentText = advertisementSet?.title ?: appName return NotificationCompat.Builder(AppContext.getActivity(), _channelId) - .setContentTitle("Bluetooth LE Spam") + .setContentTitle(appName) .setContentText(contentText) .setSmallIcon(R.drawable.bluetooth) .setContentIntent(pendingIntentTargeted) - //.setColor(resources.getColor(R.color.blue_normal, AppContext.getContext().theme)) - //.setColorized(true) .setStyle(NotificationCompat.DecoratedCustomViewStyle()) .setChannelId(_channelId) .setOngoing(true) diff --git a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisement/AdvertisementFragment.kt b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisement/AdvertisementFragment.kt index b675ac60..9aa93064 100644 --- a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisement/AdvertisementFragment.kt +++ b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisement/AdvertisementFragment.kt @@ -19,6 +19,7 @@ import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementSetRange import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementSetType import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementState import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementTarget +import de.simon.dankelmann.bluetoothlespam.Enums.getDrawableId import de.simon.dankelmann.bluetoothlespam.Interfaces.Callbacks.IAdvertisementServiceCallback import de.simon.dankelmann.bluetoothlespam.Interfaces.Callbacks.IAdvertisementSetQueueHandlerCallback import de.simon.dankelmann.bluetoothlespam.Models.AdvertisementSet @@ -252,18 +253,9 @@ class AdvertisementFragment : Fragment(), IAdvertisementServiceCallback, IAdvert } viewModel.target.observe(viewLifecycleOwner) { target -> - val targetDrawableId = when (target) { - AdvertisementTarget.ADVERTISEMENT_TARGET_UNDEFINED -> R.drawable.bluetooth - AdvertisementTarget.ADVERTISEMENT_TARGET_IOS -> R.drawable.apple - AdvertisementTarget.ADVERTISEMENT_TARGET_ANDROID -> R.drawable.ic_android - AdvertisementTarget.ADVERTISEMENT_TARGET_WINDOWS -> R.drawable.microsoft - AdvertisementTarget.ADVERTISEMENT_TARGET_SAMSUNG -> R.drawable.samsung - AdvertisementTarget.ADVERTISEMENT_TARGET_KITCHEN_SINK -> R.drawable.shuffle - AdvertisementTarget.ADVERTISEMENT_TARGET_LOVESPOUSE -> R.drawable.heart - } binding.advertisementFragmentTargetImage.setImageDrawable( ResourcesCompat.getDrawable( - resources, targetDrawableId, AppContext.getContext().theme + resources, target.getDrawableId(), AppContext.getContext().theme ) ) } diff --git a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisementcollection/AdvertisementCollectionFragment.kt b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisementcollection/AdvertisementCollectionFragment.kt index dad764df..6879d1df 100644 --- a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisementcollection/AdvertisementCollectionFragment.kt +++ b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/ui/advertisementcollection/AdvertisementCollectionFragment.kt @@ -13,6 +13,7 @@ import de.simon.dankelmann.bluetoothlespam.AppContext.AppContext import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementQueueMode import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementSetType import de.simon.dankelmann.bluetoothlespam.Enums.AdvertisementTarget +import de.simon.dankelmann.bluetoothlespam.Enums.stringResId import de.simon.dankelmann.bluetoothlespam.Helpers.DatabaseHelpers import de.simon.dankelmann.bluetoothlespam.Models.AdvertisementSetCollection import de.simon.dankelmann.bluetoothlespam.Models.AdvertisementSetList @@ -242,35 +243,11 @@ class AdvertisementCollectionFragment : Fragment() { } advertisementSetTypes.forEach { advertisementSetType -> - var titlePrefix = when (advertisementSetType) { - AdvertisementSetType.ADVERTISEMENT_TYPE_UNDEFINED -> "Undefined" - - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NEW_DEVICE -> "New Device PopUps" - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NEW_AIRTAG -> "New Airtag PopUps" - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_NOT_YOUR_DEVICE -> "Not your Device PopUps" - - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_ACTION_MODALS -> "iOS Action Modals" - AdvertisementSetType.ADVERTISEMENT_TYPE_CONTINUITY_IOS_17_CRASH -> "iOs 17 Crash" - - AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_DEVICE -> "Fast Pairing Device" - AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_PHONE_SETUP -> "Fast Pairing Phone Setup" - AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_NON_PRODUCTION -> "Fast Pairing Non Production" - AdvertisementSetType.ADVERTISEMENT_TYPE_FAST_PAIRING_DEBUG -> "Fast Pairing Debug" - - AdvertisementSetType.ADVERTISEMENT_TYPE_SWIFT_PAIRING -> "Swift Pairing" - - AdvertisementSetType.ADVERTISEMENT_TYPE_EASY_SETUP_WATCH -> "Easy Setup Watch" - AdvertisementSetType.ADVERTISEMENT_TYPE_EASY_SETUP_BUDS -> "Easy Setup Buds" - - AdvertisementSetType.ADVERTISEMENT_TYPE_LOVESPOUSE_PLAY -> "Lovespouse Play" - AdvertisementSetType.ADVERTISEMENT_TYPE_LOVESPOUSE_STOP -> "Lovespouse Stop" - } - // Initialize the List - var advertisementSetList = AdvertisementSetList() - advertisementSetList.title = "$titlePrefix List" + val advertisementSetList = AdvertisementSetList() + advertisementSetList.title = "${getString(advertisementSetType.stringResId())} List" - var advertisementSets = + val advertisementSets = DatabaseHelpers.getAllAdvertisementSetsForType(advertisementSetType) advertisementSetList.advertisementSets = advertisementSets.toMutableList() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c87ef8fa..18885d91 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -39,4 +39,22 @@ Checking Requirements… - \ No newline at end of file + + + Undefined Type + Fast Pairing Device + Fast Pairing Non-Production + Fast Pairing Phone Setup + Fast Pairing Debug + New Apple Device + New Airtag + Not Your Device + Apple Action Modal + iOS 17 Crash + Swift Pairing + Easy Setup Buds + Easy Setup Watch + Lovespouse Play + Lovespouse Stop + + From ad60971c67792b112ee8accd9a2e0325bb7d51cd Mon Sep 17 00:00:00 2001 From: Thore Goebel Date: Wed, 1 Jan 2025 13:15:28 +0100 Subject: [PATCH 2/2] Centralise SpamType strings + clean service code --- .../bluetoothlespam/Enums/SpamPackageType.kt | 21 +++++++ .../BluetoothLeScanForegroundService.kt | 57 +++++++++---------- app/src/main/res/values/strings.xml | 5 ++ 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/SpamPackageType.kt b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/SpamPackageType.kt index 957415a4..44ccb118 100644 --- a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/SpamPackageType.kt +++ b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Enums/SpamPackageType.kt @@ -1,5 +1,8 @@ package de.simon.dankelmann.bluetoothlespam.Enums +import de.simon.dankelmann.bluetoothlespam.R + + enum class SpamPackageType { UNKNOWN, FAST_PAIRING, @@ -13,4 +16,22 @@ enum class SpamPackageType { EASY_SETUP_BUDS, LOVESPOUSE_PLAY, LOVESPOUSE_STOP +} + +fun SpamPackageType.stringRes(): Int { + return when (this) { + SpamPackageType.UNKNOWN -> R.string.spam_unknown + + SpamPackageType.FAST_PAIRING -> R.string.ad_set_type_fast_pairing + SpamPackageType.CONTINUITY_NEW_AIRTAG -> R.string.ad_set_type_continuity_new_airtag + SpamPackageType.CONTINUITY_NEW_DEVICE -> R.string.ad_set_type_continuity_new_device + SpamPackageType.CONTINUITY_NOT_YOUR_DEVICE -> R.string.ad_set_type_continuity_not_your_device + SpamPackageType.CONTINUITY_ACTION_MODAL -> R.string.ad_set_type_continuity_action_modals + SpamPackageType.CONTINUITY_IOS_17_CRASH -> R.string.ad_set_type_continuity_ios17_crash + SpamPackageType.SWIFT_PAIRING -> R.string.ad_set_type_swift_pairing + SpamPackageType.EASY_SETUP_WATCH -> R.string.ad_set_type_easy_setup_watch + SpamPackageType.EASY_SETUP_BUDS -> R.string.ad_set_type_easy_setup_buds + SpamPackageType.LOVESPOUSE_PLAY -> R.string.ad_set_type_lovespouse_play + SpamPackageType.LOVESPOUSE_STOP -> R.string.ad_set_type_lovespouse_stop + } } \ No newline at end of file diff --git a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/BluetoothLeScanForegroundService.kt b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/BluetoothLeScanForegroundService.kt index 115cc45d..36fd30a9 100644 --- a/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/BluetoothLeScanForegroundService.kt +++ b/app/src/main/java/de/simon/dankelmann/bluetoothlespam/Services/BluetoothLeScanForegroundService.kt @@ -19,6 +19,7 @@ import androidx.core.content.ContextCompat import androidx.navigation.NavDeepLinkBuilder import de.simon.dankelmann.bluetoothlespam.AppContext.AppContext import de.simon.dankelmann.bluetoothlespam.Enums.SpamPackageType +import de.simon.dankelmann.bluetoothlespam.Enums.stringRes import de.simon.dankelmann.bluetoothlespam.Interfaces.Callbacks.IBluetoothLeScanCallback import de.simon.dankelmann.bluetoothlespam.MainActivity import de.simon.dankelmann.bluetoothlespam.Models.FlipperDeviceScanResult @@ -53,7 +54,14 @@ class BluetoothLeScanForegroundService: IBluetoothLeScanCallback, Service() { super.onCreate() createNotificationChannel() - startForeground(2, createNotification("Detecting Spam", "Searching Flippers and others", false)) + startForeground( + 2, + createNotification( + getString(R.string.spam_detecting_title), + getString(R.string.spam_detecting_text), + false + ) + ) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { @@ -92,20 +100,19 @@ class BluetoothLeScanForegroundService: IBluetoothLeScanCallback, Service() { } } - private fun createNotification(title:String, subTitle: String, alertOnlyOnce:Boolean): Notification { + private fun createNotification( + title: String, + subTitle: String, + alertOnlyOnce: Boolean + ): Notification { val pendingIntentTargeted = NavDeepLinkBuilder(this) .setComponentName(MainActivity::class.java) .setGraph(R.navigation.nav_graph) .setDestination(R.id.nav_spam_detector) - //.setArguments(bundle) .createPendingIntent() - - // Custom Layout val notificationView = RemoteViews(packageName, R.layout.bluetooth_le_scan_foreground_service_notification) - - // Views for Custom Layout notificationView.setTextViewText( R.id.bluetoothLeScanningForegroundNotificationTitle, title @@ -115,16 +122,11 @@ class BluetoothLeScanForegroundService: IBluetoothLeScanCallback, Service() { subTitle ) - - //var contentText = "Bluetooth LE Spam" - return NotificationCompat.Builder(AppContext.getActivity(), _channelId) - .setContentTitle("Bluetooth LE Spam") + .setContentTitle(getString(R.string.app_name)) .setContentText(subTitle) .setSmallIcon(R.drawable.bluetooth) .setContentIntent(pendingIntentTargeted) - //.setColor(resources.getColor(R.color.blue_normal, AppContext.getContext().theme)) - //.setColorized(true) .setStyle(NotificationCompat.DecoratedCustomViewStyle()) .setChannelId(_channelId) .setOngoing(true) @@ -160,27 +162,22 @@ class BluetoothLeScanForegroundService: IBluetoothLeScanCallback, Service() { } } - override fun onSpamResultPackageDetected(spamPackageScanResult: SpamPackageScanResult, alreadyKnown: Boolean) { - val spamPackageTypeText = when(spamPackageScanResult.spamPackageType){ - SpamPackageType.UNKNOWN -> "Unknown Spam" - SpamPackageType.FAST_PAIRING -> "Fast Pairing" - SpamPackageType.CONTINUITY_NEW_AIRTAG -> "Continuity Airtag" - SpamPackageType.CONTINUITY_NEW_DEVICE -> "Continuity new Device" - SpamPackageType.CONTINUITY_NOT_YOUR_DEVICE -> "Continuity not your Device" - SpamPackageType.CONTINUITY_ACTION_MODAL -> "Continuity Action Modal" - SpamPackageType.CONTINUITY_IOS_17_CRASH -> "Continuity iOS 17 Crash" - SpamPackageType.SWIFT_PAIRING -> "Swift Pairing" - SpamPackageType.EASY_SETUP_WATCH -> "Easy Setup Watch" - SpamPackageType.EASY_SETUP_BUDS -> "Easy Setup Buds" - SpamPackageType.LOVESPOUSE_PLAY -> "Lovespouse Play" - SpamPackageType.LOVESPOUSE_STOP -> "Lovespouse Stop" - } - updateNotification("Spam Detected", spamPackageTypeText + " | " + spamPackageScanResult.address, !notifyOnNewSpam, 2) + override fun onSpamResultPackageDetected( + spamPackageScanResult: SpamPackageScanResult, + alreadyKnown: Boolean + ) { + val spamPackageTypeText = getString(spamPackageScanResult.spamPackageType.stringRes()) + updateNotification( + getString(R.string.spam_detected_title), + spamPackageTypeText + " | " + spamPackageScanResult.address, + !notifyOnNewSpam, + 2 + ) notifyOnNewSpam = false } override fun onSpamResultPackageListUpdated() { - if(AppContext.getBluetoothLeScanService().getSpamPackageScanResultList().isEmpty()){ + if (AppContext.getBluetoothLeScanService().getSpamPackageScanResultList().isEmpty()) { notifyOnNewSpam = true } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 18885d91..b71e8149 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -42,6 +42,7 @@ Undefined Type + Fast Pairing Fast Pairing Device Fast Pairing Non-Production Fast Pairing Phone Setup @@ -57,4 +58,8 @@ Lovespouse Play Lovespouse Stop + Unknown Spam + Detecting Spam + Detecting Flipper Zero and other devices + Spam Detected