From 402a50547ad03906e69804dbe16b0998a44a745f Mon Sep 17 00:00:00 2001 From: Ryan Morales Date: Fri, 7 Feb 2025 15:57:20 -0800 Subject: [PATCH 1/4] MOB-22820: remove input box image view if no image is specified --- .../builders/InputBoxNotificationBuilder.kt | 9 +++++++-- .../builders/BasicNotificationBuilderTest.kt | 14 ++++++++++++++ .../builders/InputBoxNotificationBuilderTest.kt | 9 ++++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilder.kt b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilder.kt index 02f2fa96..13486505 100644 --- a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilder.kt +++ b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilder.kt @@ -27,7 +27,7 @@ import com.adobe.marketing.mobile.notificationbuilder.PushTemplateConstants.LOG_ import com.adobe.marketing.mobile.notificationbuilder.PushTemplateConstants.PushPayloadKeys import com.adobe.marketing.mobile.notificationbuilder.R import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.createNotificationChannelIfRequired -import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.setRemoteImage +import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.setRemoteViewImage import com.adobe.marketing.mobile.notificationbuilder.internal.templates.InputBoxPushTemplate import com.adobe.marketing.mobile.services.Log import java.util.Random @@ -74,7 +74,12 @@ internal object InputBoxNotificationBuilder { // get push payload data. if we are handling an intent then we know that we should be building a feedback received notification. val imageUri = if (pushTemplate.isFromIntent) pushTemplate.feedbackImage else pushTemplate.imageUrl - expandedLayout.setRemoteImage(imageUri, R.id.expanded_template_image) + + // set the image on the notification + expandedLayout.setRemoteViewImage( + imageUri, + R.id.expanded_template_image, + ) val expandedBodyText = if (pushTemplate.isFromIntent) pushTemplate.feedbackText else pushTemplate.expandedBodyText diff --git a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/BasicNotificationBuilderTest.kt b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/BasicNotificationBuilderTest.kt index e2a3414a..4789a5d9 100644 --- a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/BasicNotificationBuilderTest.kt +++ b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/BasicNotificationBuilderTest.kt @@ -101,6 +101,20 @@ class BasicNotificationBuilderTest { verify(exactly = 1) { any().setRemoteViewImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } } + @Test + fun `construct should return a NotificationCompat Builder when push template has required data only`() { + val pushTemplate = provideMockedBasicPushTemplateWithRequiredData() + val notificationBuilder = BasicNotificationBuilder.construct( + context, + pushTemplate, + trackerActivityClass, + broadcastReceiverClass + ) + + assertEquals(NotificationCompat.Builder::class.java, notificationBuilder.javaClass) + verify(exactly = 0) { any().setRemoteViewImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } + } + @Config(sdk = [23]) @Test fun `construct should use the api23 expanded layout for API level below 24`() { diff --git a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilderTest.kt b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilderTest.kt index 5839a983..6e988838 100644 --- a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilderTest.kt +++ b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/internal/builders/InputBoxNotificationBuilderTest.kt @@ -20,7 +20,7 @@ import androidx.core.app.NotificationCompat import com.adobe.marketing.mobile.notificationbuilder.NotificationConstructionFailedException import com.adobe.marketing.mobile.notificationbuilder.PushTemplateConstants import com.adobe.marketing.mobile.notificationbuilder.R -import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.setRemoteImage +import com.adobe.marketing.mobile.notificationbuilder.internal.extensions.setRemoteViewImage import com.adobe.marketing.mobile.notificationbuilder.internal.templates.InputBoxPushTemplate import com.adobe.marketing.mobile.notificationbuilder.internal.templates.MOCKED_BASIC_TEMPLATE_BODY import com.adobe.marketing.mobile.notificationbuilder.internal.templates.MOCKED_BASIC_TEMPLATE_BODY_EXPANDED @@ -41,6 +41,7 @@ import io.mockk.Runs import io.mockk.every import io.mockk.just import io.mockk.mockkConstructor +import io.mockk.mockkStatic import io.mockk.unmockkAll import io.mockk.verify import org.junit.After @@ -74,6 +75,7 @@ class InputBoxNotificationBuilderTest { trackerActivityClass = DummyActivity::class.java broadcastReceiverClass = DummyBroadcastReceiver::class.java mockkConstructor(RemoteViews::class) + mockkStatic(RemoteViews::setRemoteViewImage) } @After @@ -93,6 +95,7 @@ class InputBoxNotificationBuilderTest { assertNotNull(notificationBuilder) assertEquals(NotificationCompat.Builder::class.java, notificationBuilder.javaClass) + verify(exactly = 0) { any().setRemoteViewImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } } @Test(expected = NotificationConstructionFailedException::class) @@ -265,7 +268,7 @@ class InputBoxNotificationBuilderTest { broadcastReceiverClass ) - verify { anyConstructed().setRemoteImage(MOCKED_FEEDBACK_IMAGE, R.id.expanded_template_image) } + verify(exactly = 1) { any().setRemoteViewImage(MOCKED_FEEDBACK_IMAGE, R.id.expanded_template_image) } verify { anyConstructed().setTextViewText(R.id.notification_body, MOCKED_FEEDBACK_TEXT) } verify { anyConstructed().setTextViewText(R.id.notification_body_expanded, MOCKED_FEEDBACK_TEXT) } } @@ -282,7 +285,7 @@ class InputBoxNotificationBuilderTest { broadcastReceiverClass ) - verify { anyConstructed().setRemoteImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } + verify(exactly = 1) { any().setRemoteViewImage(MOCKED_IMAGE_URI, R.id.expanded_template_image) } verify { anyConstructed().setTextViewText(R.id.notification_body, MOCKED_BASIC_TEMPLATE_BODY) } verify { anyConstructed().setTextViewText(R.id.notification_body_expanded, MOCKED_BASIC_TEMPLATE_BODY_EXPANDED) } } From 5a43a51e4ed43900207004bec3afaf5dd91b3360 Mon Sep 17 00:00:00 2001 From: Ryan Morales Date: Fri, 7 Feb 2025 16:21:21 -0800 Subject: [PATCH 2/4] bump version to 3.0.3 --- code/gradle.properties | 2 +- .../marketing/mobile/notificationbuilder/NotificationBuilder.kt | 2 +- .../mobile/notificationbuilder/NotificationBuilderTests.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code/gradle.properties b/code/gradle.properties index 08233f40..ec31ce4a 100644 --- a/code/gradle.properties +++ b/code/gradle.properties @@ -18,7 +18,7 @@ android.useAndroidX=true #Maven artifacts #Notification Builder Module notificationbuilderModuleName=notificationbuilder -notificationbuilderVersion=3.0.2 +notificationbuilderVersion=3.0.3 notificationbuilderMavenRepoName=AdobeMobileNotificationBuilderSdk notificationbuilderMavenRepoDescription=Android Notification Builder library for Adobe Mobile Marketing diff --git a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt index a4959aa0..339b65a8 100644 --- a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt +++ b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt @@ -53,7 +53,7 @@ import com.adobe.marketing.mobile.services.ServiceProvider */ object NotificationBuilder { private const val SELF_TAG = "NotificationBuilder" - private const val VERSION = "3.0.2" + private const val VERSION = "3.0.3" @JvmStatic fun version(): String { diff --git a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt index 6007d30f..2ddafbf6 100644 --- a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt +++ b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt @@ -118,7 +118,7 @@ class NotificationBuilderTests { fun `NotificationBuilder version values matches the expected version`() { val version = NotificationBuilder.version() - assertEquals("3.0.2", version) + assertEquals("3.0.3", version) } @Test From 854c14db070fb71753be6f946cab7b3cf719d74d Mon Sep 17 00:00:00 2001 From: Ryan Morales Date: Mon, 10 Feb 2025 11:21:30 -0800 Subject: [PATCH 3/4] move version to NotificationBuilderConstants --- .github/workflows/update-version.yml | 2 +- .../NotificationBuilder.kt | 6 +++--- .../NotificationBuilderConstants.kt | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderConstants.kt diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml index b77f0d78..ffa3d7b0 100644 --- a/.github/workflows/update-version.yml +++ b/.github/workflows/update-version.yml @@ -43,5 +43,5 @@ jobs: version: ${{ github.event.inputs.version }} branch: ${{ github.event.inputs.branch }} dependencies: Core ${{ github.event.inputs.core-dependency }} - paths: code/gradle.properties, code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt + paths: code/gradle.properties, code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderConstants.kt update: true \ No newline at end of file diff --git a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt index 339b65a8..dd574ccd 100644 --- a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt +++ b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilder.kt @@ -17,6 +17,8 @@ import android.content.Context import android.content.Intent import androidx.core.app.NotificationCompat import com.adobe.marketing.mobile.notificationbuilder.NotificationBuilder.constructNotificationBuilder +import com.adobe.marketing.mobile.notificationbuilder.NotificationBuilderConstants.TAG +import com.adobe.marketing.mobile.notificationbuilder.NotificationBuilderConstants.VERSION import com.adobe.marketing.mobile.notificationbuilder.PushTemplateConstants.LOG_TAG import com.adobe.marketing.mobile.notificationbuilder.internal.PushTemplateType import com.adobe.marketing.mobile.notificationbuilder.internal.builders.AutoCarouselNotificationBuilder @@ -52,8 +54,6 @@ import com.adobe.marketing.mobile.services.ServiceProvider * [AEPPushTemplate] or [Intent]. */ object NotificationBuilder { - private const val SELF_TAG = "NotificationBuilder" - private const val VERSION = "3.0.3" @JvmStatic fun version(): String { @@ -157,7 +157,7 @@ object NotificationBuilder { else -> { Log.warning( LOG_TAG, - SELF_TAG, + TAG, "Unknown carousel push template type, creating a legacy style notification." ) return LegacyNotificationBuilder.construct( diff --git a/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderConstants.kt b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderConstants.kt new file mode 100644 index 00000000..60221a90 --- /dev/null +++ b/code/notificationbuilder/src/main/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderConstants.kt @@ -0,0 +1,20 @@ +/* + Copyright 2025 Adobe. All rights reserved. + This file is licensed to you under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. You may obtain a copy + of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under + the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS + OF ANY KIND, either express or implied. See the License for the specific language + governing permissions and limitations under the License. +*/ + +package com.adobe.marketing.mobile.notificationbuilder + +/** + * This object holds all constant values for the NotificationBuilder object. + */ +internal object NotificationBuilderConstants { + internal const val TAG = "NotificationBuilder" + internal const val VERSION = "3.0.3" +} From 7d5fd9ac83bc8a2b116e09a423f748553667de70 Mon Sep 17 00:00:00 2001 From: Ryan Morales Date: Mon, 10 Feb 2025 11:31:06 -0800 Subject: [PATCH 4/4] update test to use version constant --- .../mobile/notificationbuilder/NotificationBuilderTests.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt index 2ddafbf6..99b180dd 100644 --- a/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt +++ b/code/notificationbuilder/src/test/java/com/adobe/marketing/mobile/notificationbuilder/NotificationBuilderTests.kt @@ -118,7 +118,7 @@ class NotificationBuilderTests { fun `NotificationBuilder version values matches the expected version`() { val version = NotificationBuilder.version() - assertEquals("3.0.3", version) + assertEquals(NotificationBuilderConstants.VERSION, version) } @Test