From b3da483f1a642c0ebe42eaa7c25971c096ec124d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Hudi=C4=8Dek?= Date: Mon, 25 Nov 2024 13:31:04 +0000 Subject: [PATCH] Pull request #87: custom in-app dialog button color sync with android sdk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge in MML/infobip-mobile-messaging-huawei from mhudicek/MM-6929-custom-button-color to master Squashed commit of the following: commit 410e5ff6509bb57172b4e182971588cee38a93a9 Author: Matej Hudicek Date: Mon Nov 25 14:18:44 2024 +0100 Remove empty lines in imports commit cf9a183282a76f7343073c007bf785cd5ae7a607 Author: Luka Ilić Date: Mon Nov 25 13:51:28 2024 +0100 custom in-app dialog button color sync with android sdk --- .../inapp/view/InAppViewDialogTest.java | 44 +++++++++---------- .../inapp/view/ActivityWrapper.java | 7 ++- .../inapp/view/InAppViewDialog.java | 17 ++----- .../src/main/res/values-night/colors.xml | 4 ++ .../src/main/res/values/colors.xml | 4 ++ .../src/main/res/values/styles.xml | 4 ++ 6 files changed, 38 insertions(+), 42 deletions(-) create mode 100644 infobip-mobile-messaging-huawei-sdk/src/main/res/values-night/colors.xml create mode 100644 infobip-mobile-messaging-huawei-sdk/src/main/res/values/colors.xml diff --git a/infobip-mobile-messaging-huawei-sdk/src/androidTest/java/org/infobip/mobile/messaging/interactive/inapp/view/InAppViewDialogTest.java b/infobip-mobile-messaging-huawei-sdk/src/androidTest/java/org/infobip/mobile/messaging/interactive/inapp/view/InAppViewDialogTest.java index ec75c4c2..395bc86b 100644 --- a/infobip-mobile-messaging-huawei-sdk/src/androidTest/java/org/infobip/mobile/messaging/interactive/inapp/view/InAppViewDialogTest.java +++ b/infobip-mobile-messaging-huawei-sdk/src/androidTest/java/org/infobip/mobile/messaging/interactive/inapp/view/InAppViewDialogTest.java @@ -1,16 +1,26 @@ package org.infobip.mobile.messaging.interactive.inapp.view; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import android.app.Activity; import android.content.DialogInterface; import android.content.res.Resources; import android.graphics.Bitmap; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import android.view.View; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; - +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import org.infobip.mobile.messaging.Message; import org.infobip.mobile.messaging.R; import org.infobip.mobile.messaging.interactive.NotificationAction; @@ -18,23 +28,9 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; - import java.util.Random; import java.util.concurrent.Executor; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - /** * @author sslavin * @since 24/04/2018. @@ -78,7 +74,7 @@ public void before() { when(alertDialogBuilder.setNegativeButton(anyString(), any(InAppViewDialogClickListener.class))).thenReturn(alertDialogBuilder); when(alertDialogBuilder.setNeutralButton(anyInt(), any(InAppViewDialogClickListener.class))).thenReturn(alertDialogBuilder); when(alertDialogBuilder.create()).thenReturn(alertDialog); - when(activityWrapper.createAlertDialogBuilder(anyBoolean())).thenReturn(alertDialogBuilder); + when(activityWrapper.createAlertDialogBuilder()).thenReturn(alertDialogBuilder); when(activityWrapper.inflateView(eq(R.layout.in_app_dialog_image))).thenReturn(dialogView); when(activityWrapper.getActivity()).thenReturn(activity); when(activity.getResources()).thenReturn(resources); @@ -92,7 +88,7 @@ public void shouldNotShowDialogInNoActions() { inAppViewDialog.show(message, category); - verify(activityWrapper, never()).createAlertDialogBuilder(anyBoolean()); + verify(activityWrapper, never()).createAlertDialogBuilder(); } @Test @@ -108,7 +104,7 @@ public void shouldSetupViewsAccordingToMessageContents() { verify(rlDialogImage, times(1)).setVisibility(View.VISIBLE); verify(image, times(1)).setVisibility(View.VISIBLE); - verify(activityWrapper, times(1)).createAlertDialogBuilder(eq(true)); + verify(activityWrapper, times(1)).createAlertDialogBuilder(); verify(alertDialogBuilder, times(1)).setOnDismissListener(any(InAppViewDialogDismissListener.class)); verify(alertDialogBuilder, times(1)).setView(eq(dialogView)); @@ -129,7 +125,7 @@ public void shouldSetupViewsAccordingToMessageContentsWithoutImage() { verify(rlDialogImage, never()).setVisibility(View.VISIBLE); verify(image, never()).setVisibility(View.VISIBLE); - verify(activityWrapper, times(1)).createAlertDialogBuilder(eq(true)); + verify(activityWrapper, times(1)).createAlertDialogBuilder(); verify(alertDialogBuilder, times(1)).setOnDismissListener(any(InAppViewDialogDismissListener.class)); verify(alertDialogBuilder, times(1)).setView(eq(dialogView)); @@ -152,7 +148,7 @@ public void shouldNotDisplayTitleAndImageFieldsIfDataNotProvided() { verify(rlDialogImage, never()).setVisibility(View.VISIBLE); verify(image, never()).setVisibility(View.VISIBLE); - verify(activityWrapper, times(1)).createAlertDialogBuilder(eq(true)); + verify(activityWrapper, times(1)).createAlertDialogBuilder(); verify(alertDialogBuilder, times(1)).setOnDismissListener(any(InAppViewDialogDismissListener.class)); verify(alertDialogBuilder, times(1)).setView(eq(dialogView)); @@ -173,8 +169,8 @@ public void shouldDisplayDialogWithBuiltInThemeIfDefaultFails() { inAppViewDialog.show(message, category, actions); - verify(activityWrapper, times(1)).createAlertDialogBuilder(eq(true)); - verify(activityWrapper, times(1)).createAlertDialogBuilder(eq(false)); + verify(activityWrapper, times(1)).createAlertDialogBuilder(); + verify(activityWrapper, times(1)).createAlertDialogBuilder(); verify(alertDialog, times(2)).show(); } diff --git a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/interactive/inapp/view/ActivityWrapper.java b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/interactive/inapp/view/ActivityWrapper.java index eda9652d..7431c89a 100644 --- a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/interactive/inapp/view/ActivityWrapper.java +++ b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/interactive/inapp/view/ActivityWrapper.java @@ -1,11 +1,10 @@ package org.infobip.mobile.messaging.interactive.inapp.view; import android.app.Activity; -import androidx.appcompat.app.AlertDialog; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; - +import androidx.appcompat.app.AlertDialog; import org.infobip.mobile.messaging.R; @@ -23,8 +22,8 @@ public class ActivityWrapper { this.layoutInflater = LayoutInflater.from(activity); } - public AlertDialog.Builder createAlertDialogBuilder(boolean useAppTheme) { - return new AlertDialog.Builder(useAppTheme ? activity : new ContextThemeWrapper(activity, R.style.InAppDialog)); + public AlertDialog.Builder createAlertDialogBuilder() { + return new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.InAppDialog)); } public View inflateView(int layoutResId) { diff --git a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/interactive/inapp/view/InAppViewDialog.java b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/interactive/inapp/view/InAppViewDialog.java index c234b9dd..d22c354b 100644 --- a/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/interactive/inapp/view/InAppViewDialog.java +++ b/infobip-mobile-messaging-huawei-sdk/src/main/java/org/infobip/mobile/messaging/interactive/inapp/view/InAppViewDialog.java @@ -2,8 +2,6 @@ import android.app.Activity; import android.graphics.Bitmap; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; import android.text.TextUtils; import android.view.View; import android.widget.ImageView; @@ -66,10 +64,9 @@ private void show(final Bitmap bitmap, @NonNull final Message message, final Not @Override public void run() { try { - showOnUiThreadWithAppTheme(bitmap, message, category, actions); + showOnUiThread(bitmap, message, category, actions); } catch (Exception e) { if (e instanceof IllegalStateException && e.getMessage().contains("You need to use a Theme.AppCompat theme")) { - showOnUiThreadWithOwnTheme(bitmap, message, category, actions); return; } // better not displaying in-app than crashing UI @@ -79,15 +76,7 @@ public void run() { }); } - private void showOnUiThreadWithOwnTheme(Bitmap bitmap, @NonNull Message message, NotificationCategory category, @NonNull NotificationAction[] actions) { - showOnUiThread(bitmap, message, category, actions, false); - } - - private void showOnUiThreadWithAppTheme(Bitmap bitmap, @NonNull Message message, NotificationCategory category, @NonNull NotificationAction[] actions) { - showOnUiThread(bitmap, message, category, actions, true); - } - - private void showOnUiThread(Bitmap bitmap, @NonNull Message message, NotificationCategory category, @NonNull NotificationAction[] actions, boolean useAppTheme) { + private void showOnUiThread(Bitmap bitmap, @NonNull Message message, NotificationCategory category, @NonNull NotificationAction[] actions) { if (bitmap != null) { image.setImageBitmap(bitmap); rlDialogImage.setVisibility(View.VISIBLE); @@ -100,7 +89,7 @@ private void showOnUiThread(Bitmap bitmap, @NonNull Message message, Notificatio } tvMessageText.setText(message.getBody()); - final AlertDialog.Builder builder = activityWrapper.createAlertDialogBuilder(useAppTheme) + final AlertDialog.Builder builder = activityWrapper.createAlertDialogBuilder() .setOnDismissListener(new InAppViewDialogDismissListener(this, callback)) .setView(dialogView); diff --git a/infobip-mobile-messaging-huawei-sdk/src/main/res/values-night/colors.xml b/infobip-mobile-messaging-huawei-sdk/src/main/res/values-night/colors.xml new file mode 100644 index 00000000..8032ecbd --- /dev/null +++ b/infobip-mobile-messaging-huawei-sdk/src/main/res/values-night/colors.xml @@ -0,0 +1,4 @@ + + + @android:color/white + \ No newline at end of file diff --git a/infobip-mobile-messaging-huawei-sdk/src/main/res/values/colors.xml b/infobip-mobile-messaging-huawei-sdk/src/main/res/values/colors.xml new file mode 100644 index 00000000..68c4773b --- /dev/null +++ b/infobip-mobile-messaging-huawei-sdk/src/main/res/values/colors.xml @@ -0,0 +1,4 @@ + + + @android:color/black + \ No newline at end of file diff --git a/infobip-mobile-messaging-huawei-sdk/src/main/res/values/styles.xml b/infobip-mobile-messaging-huawei-sdk/src/main/res/values/styles.xml index c7c160e3..53744027 100644 --- a/infobip-mobile-messaging-huawei-sdk/src/main/res/values/styles.xml +++ b/infobip-mobile-messaging-huawei-sdk/src/main/res/values/styles.xml @@ -2,6 +2,10 @@ +