From 59051a921b1160b2f354fb64081a5905906f7231 Mon Sep 17 00:00:00 2001 From: manpreet Date: Wed, 4 Sep 2024 19:49:35 +0530 Subject: [PATCH 1/5] support fluent icon for different environments --- .../io/adaptivecards/renderer/UtilTest.java | 21 ++++++++++++ .../renderer/FluentIconImageLoaderAsync.kt | 2 +- .../renderer/IFeatureFlagResolver.kt | 2 ++ .../java/io/adaptivecards/renderer/Util.java | 32 +++++++++++++++++++ .../action/ActionElementRenderer.java | 3 +- .../action/DropdownElementRenderer.java | 5 +-- .../renderer/readonly/FluentIconsRenderer.kt | 2 +- .../FeatureFlagResolverUtility.kt | 14 ++++++++ .../CustomObjects/FeatureFlagResolver.java | 12 ++++++- 9 files changed, 87 insertions(+), 6 deletions(-) diff --git a/source/android/adaptivecards/src/androidTest/java/io/adaptivecards/renderer/UtilTest.java b/source/android/adaptivecards/src/androidTest/java/io/adaptivecards/renderer/UtilTest.java index 58622292e..0ebcd04ae 100644 --- a/source/android/adaptivecards/src/androidTest/java/io/adaptivecards/renderer/UtilTest.java +++ b/source/android/adaptivecards/src/androidTest/java/io/adaptivecards/renderer/UtilTest.java @@ -53,4 +53,25 @@ public void testGetSizeClosestToGivenSize_5() { long closestSize = Util.getSizeClosestToGivenSize(availableSizes, targetSize); assertEquals(24L, closestSize); } + + @Test + public void testExtractFluentIconNameFromUrl_1() { + String url = "icon:Rss"; + String iconName = Util.extractFluentIconNameFromUrl(url); + assertEquals("Rss", iconName); + } + + @Test + public void testExtractFluentIconNameFromUrl_2() { + String url = "icon:Rss,regular"; + String iconName = Util.extractFluentIconNameFromUrl(url); + assertEquals("Rss", iconName); + } + + @Test + public void testExtractFluentIconNameFromUrl_3() { + String url = "icon:Rss,filled"; + String iconName = Util.extractFluentIconNameFromUrl(url); + assertEquals("Rss", iconName); + } } diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/FluentIconImageLoaderAsync.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/FluentIconImageLoaderAsync.kt index 24374fb2b..26c805366 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/FluentIconImageLoaderAsync.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/FluentIconImageLoaderAsync.kt @@ -101,7 +101,7 @@ open class FluentIconImageLoaderAsync( */ private fun fetchUnavailableIconInfo(): HttpRequestResult? { isFilledStyle = true - val unavailableIconURL = "${AdaptiveCardObjectModel.getBaseIconCDNUrl()}/$SQUARE_ICON/$SQUARE_ICON.json" + val unavailableIconURL = Util.getSvgInfoUrl(SQUARE_ICON) return try { val responseBytes = HttpRequestHelper.get(unavailableIconURL) HttpRequestResult(String (responseBytes, StandardCharsets.UTF_8)) diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt index cf4e1c850..d92276481 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt @@ -8,4 +8,6 @@ package io.adaptivecards.renderer interface IFeatureFlagResolver { fun getEcsSettingAsBoolean(key: String): Boolean + + fun getEcsSettingAsString(key: String): String } diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/Util.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/Util.java index 22010d478..d09f5d045 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/Util.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/Util.java @@ -797,6 +797,38 @@ static long getSizeClosestToGivenSize(List availableSizes, Long targetIcon return closestSize; } + /** + * icon url format - icon:[,regular | filled] + * sample icon url - icon:Rss,regular + **/ + public static String extractFluentIconNameFromUrl(String iconUrl) { + + // Split the string by the colon character + String[] parts = iconUrl.split(":"); + + // Check if the split operation resulted in at least 2 parts + if (parts.length >= 2) { + // Split the second part by the comma character + String[] iconParts = parts[1].split(","); + + // Return the first part which is the icon name + return iconParts[0]; + } + + // Return empty string if the icon name could not be extracted + return ""; + } + + /** + * format: "/.json" + * https://res-1.cdn.office.net/assets/fluentui-react-icons/2.0.226/Rss/Rss.json + **/ + public static String getSvgInfoUrl(String iconName) { + String fluentIconCdnRoot = FeatureFlagResolverUtility.INSTANCE.fetchFluentIconCdnRoot(); + String fluentIconCdnPath = FeatureFlagResolverUtility.INSTANCE.fetchFluentIconCdnPath(); + return String.format("%s/%s/%s/%s.json", fluentIconCdnRoot, fluentIconCdnPath, iconName, iconName); + } + private static final String FLUENT_ICON_URL_PREFIX = "icon:"; public static String getOpenUrlAnnouncement(Context context, String urlTitle) { diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/ActionElementRenderer.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/ActionElementRenderer.java index 130ee12ae..c25fa4976 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/ActionElementRenderer.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/ActionElementRenderer.java @@ -152,7 +152,8 @@ public Button renderButton( button.post(() -> Util.expandClickArea(button, minHeight)); String iconUrl = baseActionElement.GetIconUrl(); - String svgInfoURL = baseActionElement.GetSVGInfoURL(); + String fluentIconName = Util.extractFluentIconNameFromUrl(iconUrl); + String svgInfoURL = Util.getSvgInfoUrl(fluentIconName); if (!iconUrl.isEmpty()) { diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/DropdownElementRenderer.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/DropdownElementRenderer.java index acaf77991..b2dd2fb27 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/DropdownElementRenderer.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/DropdownElementRenderer.java @@ -72,7 +72,8 @@ public Button render(RenderedAdaptiveCard renderedCard, Context context, Fragmen Button button = actionRenderer.render(renderedCard, context, fragmentManager, viewGroup, baseActionElement, cardActionHandler, hostConfig, renderArgs); viewGroup.removeView(button); - String svgResourceURL = baseActionElement.GetSVGInfoURL(); + String fluentIconName = Util.extractFluentIconNameFromUrl(iconUrl); + String svgInfoURL = Util.getSvgInfoUrl(fluentIconName); Button dropDownItem = new Button(context, null, R.style.Widget_AppCompat_Light_ActionButton_Overflow); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); @@ -90,7 +91,7 @@ public Button render(RenderedAdaptiveCard renderedCard, Context context, Fragmen if (!iconUrl.isEmpty()) { - Util.loadIcon(context, dropDownItem, iconUrl, svgResourceURL, hostConfig, renderedCard, IconPlacement.LeftOfTitle); + Util.loadIcon(context, dropDownItem, iconUrl, svgInfoURL, hostConfig, renderedCard, IconPlacement.LeftOfTitle); } dropDownItem.setOnClickListener(view -> diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/FluentIconsRenderer.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/FluentIconsRenderer.kt index 25c22ff9d..a6f508b64 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/FluentIconsRenderer.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/FluentIconsRenderer.kt @@ -44,7 +44,7 @@ object FluentIconsRenderer : BaseCardElementRenderer() { ): View { val icon = Util.castTo(baseCardElement, Icon::class.java) val view = ImageView(context) - val svgURL = icon.GetSVGInfoURL() + val svgURL = Util.getSvgInfoUrl(icon.GetName()) val foregroundColor = hostConfig.GetForegroundColor(ContainerStyle.Default, icon.forgroundColor, false) val isFilledStyle = icon.iconStyle == IconStyle.Filled diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/registration/FeatureFlagResolverUtility.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/registration/FeatureFlagResolverUtility.kt index c4187e631..aa17ef227 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/registration/FeatureFlagResolverUtility.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/registration/FeatureFlagResolverUtility.kt @@ -11,6 +11,8 @@ object FeatureFlagResolverUtility { private const val IS_FLOW_LAYOUT_ENABLED = "adaptiveCard/isFlowLayoutEnabled" private const val IS_GRID_LAYOUT_ENABLED = "adaptiveCard/isGridLayoutEnabled" private const val IS_ITEM_FIT_TO_FILL_ENABLED_FOR_COLUMN = "adaptiveCard/isItemFitToFillEnabledForColumn" + private const val FLUENT_ICON_CDN_ROOT_ECS_KEY = "adaptiveCard/fluentIconCdnRoot" + private const val FLUENT_ICON_CDN_PATH_ECS_KEY = "adaptiveCard/fluentIconCdnPath" fun isFlowLayoutEnabled(): Boolean { val featureFlagResolver = CardRendererRegistration.getInstance().featureFlagResolver @@ -29,4 +31,16 @@ object FeatureFlagResolverUtility { return featureFlagResolver?.getEcsSettingAsBoolean(IS_ITEM_FIT_TO_FILL_ENABLED_FOR_COLUMN) ?: false } + + fun fetchFluentIconCdnRoot(): String { + val featureFlagResolver = CardRendererRegistration.getInstance().featureFlagResolver + return featureFlagResolver?.getEcsSettingAsString(FLUENT_ICON_CDN_ROOT_ECS_KEY) + ?: "https://res-1.cdn.office.net" + } + + fun fetchFluentIconCdnPath(): String { + val featureFlagResolver = CardRendererRegistration.getInstance().featureFlagResolver + return featureFlagResolver?.getEcsSettingAsString(FLUENT_ICON_CDN_PATH_ECS_KEY) + ?: "assets/fluentui-react-icons/2.0.226" + } } diff --git a/source/android/mobile/src/main/java/io/adaptivecards/adaptivecardssample/CustomObjects/FeatureFlagResolver.java b/source/android/mobile/src/main/java/io/adaptivecards/adaptivecardssample/CustomObjects/FeatureFlagResolver.java index a155d8ed7..edf377653 100644 --- a/source/android/mobile/src/main/java/io/adaptivecards/adaptivecardssample/CustomObjects/FeatureFlagResolver.java +++ b/source/android/mobile/src/main/java/io/adaptivecards/adaptivecardssample/CustomObjects/FeatureFlagResolver.java @@ -3,7 +3,6 @@ package io.adaptivecards.adaptivecardssample.CustomObjects; import androidx.annotation.NonNull; - import io.adaptivecards.renderer.IFeatureFlagResolver; public class FeatureFlagResolver implements IFeatureFlagResolver { @@ -13,4 +12,15 @@ public boolean getEcsSettingAsBoolean(@NonNull String key) { // This is a sample implementation. The host app should implement this method to return the correct value of the feature flag. return key.equals("adaptiveCard/isFlowLayoutEnabled") || key.equals("adaptiveCard/isItemFitToFillEnabledForColumn"); } + + @Override + public String getEcsSettingAsString(@NonNull String key) { + // This is a sample implementation. The host app should implement this method to return the correct value of the feature flag. + if (key.equals("adaptiveCard/fluentIconCdnRoot")) { + return "https://res-1.cdn.office.net"; + } else if (key.equals("adaptiveCard/fluentIconCdnPath")) { + return "assets/fluentui-react-icons/2.0.226"; + } + return ""; + } } From 7202744a3f44d389d7f98a9bbe9b4e86d9069d81 Mon Sep 17 00:00:00 2001 From: manpreet Date: Thu, 5 Sep 2024 12:09:28 +0530 Subject: [PATCH 2/5] removed unused imports and added default value for cdn root and path in sdk --- samples/v1.5/Scenarios/RatingInput.json | 10 +++++----- .../renderer/input/RatingInputRenderer.kt | 3 --- .../renderer/layout/RatingStarInputView.kt | 1 - .../registration/FeatureFlagResolverUtility.kt | 12 ++++++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/samples/v1.5/Scenarios/RatingInput.json b/samples/v1.5/Scenarios/RatingInput.json index a960e8a66..50f164648 100644 --- a/samples/v1.5/Scenarios/RatingInput.json +++ b/samples/v1.5/Scenarios/RatingInput.json @@ -15,7 +15,7 @@ "isRequired": true, "label": "Pick a rating", "errorMessage": "Please pick a rating", - "horizontalAlignment": "left", + "horizontalAlignment": "Left", "max": 5 }, { @@ -27,7 +27,7 @@ "errorMessage": "Please pick a rating", "color": "marigold", "value": 2, - "horizontalAlignment": "left", + "horizontalAlignment": "Left", "max": 5 }, { @@ -41,7 +41,7 @@ "type": "Rating", "value": 3.2, "size": "medium", - "horizontalAlignment": "left", + "horizontalAlignment": "Left", "count": 10 }, { @@ -50,7 +50,7 @@ "value": 3.2, "color": "marigold", "size": "large", - "horizontalAlignment": "left", + "horizontalAlignment": "Left", "count": 150 }, { @@ -60,7 +60,7 @@ "color": "marigold", "count": 1500, "size": "large", - "horizontalAlignment": "left" + "horizontalAlignment": "Left" } ], "actions": [ diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/input/RatingInputRenderer.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/input/RatingInputRenderer.kt index 1ddfeade3..4512c5841 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/input/RatingInputRenderer.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/input/RatingInputRenderer.kt @@ -3,11 +3,8 @@ package io.adaptivecards.renderer.input import android.content.Context -import android.os.Build import android.view.View import android.view.ViewGroup -import android.view.ViewTreeObserver -import android.widget.LinearLayout import androidx.fragment.app.FragmentManager import io.adaptivecards.objectmodel.BaseCardElement import io.adaptivecards.objectmodel.HostConfig diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/layout/RatingStarInputView.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/layout/RatingStarInputView.kt index ee39f4d90..db0cb4c14 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/layout/RatingStarInputView.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/layout/RatingStarInputView.kt @@ -6,7 +6,6 @@ import android.content.Context import android.graphics.drawable.Drawable import android.util.AttributeSet import android.widget.ImageView -import android.widget.LinearLayout import androidx.core.content.res.ResourcesCompat import com.google.android.flexbox.FlexWrap import com.google.android.flexbox.FlexboxLayout diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/registration/FeatureFlagResolverUtility.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/registration/FeatureFlagResolverUtility.kt index aa17ef227..0af9ce2f2 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/registration/FeatureFlagResolverUtility.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/registration/FeatureFlagResolverUtility.kt @@ -13,6 +13,8 @@ object FeatureFlagResolverUtility { private const val IS_ITEM_FIT_TO_FILL_ENABLED_FOR_COLUMN = "adaptiveCard/isItemFitToFillEnabledForColumn" private const val FLUENT_ICON_CDN_ROOT_ECS_KEY = "adaptiveCard/fluentIconCdnRoot" private const val FLUENT_ICON_CDN_PATH_ECS_KEY = "adaptiveCard/fluentIconCdnPath" + private const val FLUENT_ICON_CDN_ROOT_DEFAULT_VALUE = "https://res-1.cdn.office.net" + private const val FLUENT_ICON_CDN_PATH_DEFAULT_VALUE = "assets/fluentui-react-icons/2.0.226" fun isFlowLayoutEnabled(): Boolean { val featureFlagResolver = CardRendererRegistration.getInstance().featureFlagResolver @@ -34,13 +36,15 @@ object FeatureFlagResolverUtility { fun fetchFluentIconCdnRoot(): String { val featureFlagResolver = CardRendererRegistration.getInstance().featureFlagResolver - return featureFlagResolver?.getEcsSettingAsString(FLUENT_ICON_CDN_ROOT_ECS_KEY) - ?: "https://res-1.cdn.office.net" + val fluentIconCdnRootValue = featureFlagResolver?.getEcsSettingAsString(FLUENT_ICON_CDN_ROOT_ECS_KEY) + return if (fluentIconCdnRootValue.isNullOrEmpty()) FLUENT_ICON_CDN_ROOT_DEFAULT_VALUE + else fluentIconCdnRootValue } fun fetchFluentIconCdnPath(): String { val featureFlagResolver = CardRendererRegistration.getInstance().featureFlagResolver - return featureFlagResolver?.getEcsSettingAsString(FLUENT_ICON_CDN_PATH_ECS_KEY) - ?: "assets/fluentui-react-icons/2.0.226" + val fluentIconCdnPathValue = featureFlagResolver?.getEcsSettingAsString(FLUENT_ICON_CDN_PATH_ECS_KEY) + return if (fluentIconCdnPathValue.isNullOrEmpty()) FLUENT_ICON_CDN_PATH_DEFAULT_VALUE + else fluentIconCdnPathValue } } From 7ce16cfb4aac3f1e0fad79e0c5e4e66e5028a253 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Thu, 5 Sep 2024 12:48:21 +0530 Subject: [PATCH 3/5] Add support for CDN url configuration --- .../ACRCustomFeatureFlagResolver.m | 20 ++++++++++++++----- .../AdaptiveCards/AdaptiveCards/ACRButton.mm | 3 ++- .../ACRCompoundButtonRenderer.mm | 3 ++- .../AdaptiveCards/ACRIconRenderer.mm | 2 +- .../AdaptiveCards/ACRSVGImageView.mm | 3 ++- .../AdaptiveCards/PrivateHeaders/UtiliOS.h | 6 ++++++ .../AdaptiveCards/AdaptiveCards/UtiliOS.mm | 8 ++++++++ .../cpp/ObjectModel/BaseActionElement.cpp | 4 ++-- .../cpp/ObjectModel/BaseActionElement.h | 2 +- source/shared/cpp/ObjectModel/Icon.cpp | 7 +++---- source/shared/cpp/ObjectModel/Icon.h | 7 +------ source/shared/cpp/ObjectModel/IconInfo.cpp | 5 ++--- source/shared/cpp/ObjectModel/IconInfo.h | 2 +- 13 files changed, 46 insertions(+), 26 deletions(-) diff --git a/source/ios/AdaptiveCards/ADCIOSVisualizer/ADCIOSVisualizer/ACRCustomFeatureFlagResolver.m b/source/ios/AdaptiveCards/ADCIOSVisualizer/ADCIOSVisualizer/ACRCustomFeatureFlagResolver.m index 5a6dcfb3f..cb41203d0 100644 --- a/source/ios/AdaptiveCards/ADCIOSVisualizer/ADCIOSVisualizer/ACRCustomFeatureFlagResolver.m +++ b/source/ios/AdaptiveCards/ADCIOSVisualizer/ADCIOSVisualizer/ACRCustomFeatureFlagResolver.m @@ -11,11 +11,13 @@ @implementation ACRCustomFeatureFlagResolver -- (NSArray *)arrayForFlag:(NSString *)flag { +- (NSArray *)arrayForFlag:(NSString *)flag +{ return nil; } -- (BOOL)boolForFlag:(NSString *)flag { +- (BOOL)boolForFlag:(NSString *)flag +{ if([flag isEqualToString:@"isFlowLayoutEnabled"]) { return YES; @@ -29,15 +31,23 @@ - (BOOL)boolForFlag:(NSString *)flag { return NO; } -- (NSDictionary *)dictForFlag:(NSString *)flag { +- (NSDictionary *)dictForFlag:(NSString *)flag +{ return nil; } -- (NSNumber *)numberForFlag:(NSString *)flag { +- (NSNumber *)numberForFlag:(NSString *)flag +{ return nil; } -- (NSString *)stringForFlag:(NSString *)flag { +- (NSString *)stringForFlag:(NSString *)flag +{ + if ([flag isEqualToString:@"fluentIconCdnURL"]) + { + return @"https://res-1.cdn.office.net/assets/fluentui-react-icons/2.0.226/"; + } + return nil; } diff --git a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRButton.mm b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRButton.mm index 73531b2d5..91c0ae300 100644 --- a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRButton.mm +++ b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRButton.mm @@ -12,6 +12,7 @@ #import "ACRUIImageView.h" #import "ACRViewPrivate.h" #import "ACRSVGImageView.h" +#import "UtiliOS.h" @implementation ACRButton @@ -169,7 +170,7 @@ + (UIButton *)rootView:(ACRView *)rootView // it is possible that host config has some size which is not available in CDN. unsigned int imageHeight = 24; BOOL isFilled = [[iconURL lowercaseString] containsString:@"filled"]; - NSString *getSVGURL = [NSString stringWithCString:action->GetSVGInfoURL().c_str() encoding:[NSString defaultCStringEncoding]]; + NSString *getSVGURL = cdnURLForIcon(@(action->GetSVGPath().c_str())); UIImageView *view = [[ACRSVGImageView alloc] init:getSVGURL rtl:rootView.context.rtl isFilled:isFilled size:CGSizeMake(imageHeight, imageHeight) tintColor:button.currentTitleColor]; button.iconView = view; [button addSubview:view]; diff --git a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRCompoundButtonRenderer.mm b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRCompoundButtonRenderer.mm index f1757d125..5b16f0fe9 100644 --- a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRCompoundButtonRenderer.mm +++ b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRCompoundButtonRenderer.mm @@ -132,7 +132,8 @@ -(ACRSVGIconHoldingView*) getIconViewWithIconInfo:(std::shared_ptr) ic rootView:(ACRView *)rootView hostConfig:(ACOHostConfig *)acoConfig; { - NSString *svgPayloadURL = @(icon->GetSVGInfoURL().c_str()); + + NSString *svgPayloadURL = cdnURLForIcon(@(icon->GetSVGPath().c_str())); UIColor *imageTintColor = [acoConfig getTextBlockColor:(ACRContainerStyle::ACRDefault) textColor:icon->getForgroundColor() subtleOption:false]; CGSize size = CGSizeMake(getIconSize(icon->getIconSize()), getIconSize(icon->getIconSize())); diff --git a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRIconRenderer.mm b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRIconRenderer.mm index c1394c81c..d165b61af 100644 --- a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRIconRenderer.mm +++ b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRIconRenderer.mm @@ -45,7 +45,7 @@ - (UIView *)render:(UIView *)viewGroup std::shared_ptr elem = [acoElem element]; std::shared_ptr icon = std::dynamic_pointer_cast(elem); - NSString *svgPayloadURL = @(icon->GetSVGInfoURL().c_str()); + NSString *svgPayloadURL = cdnURLForIcon(@(icon->GetSVGPath().c_str())); CGSize size = CGSizeMake(getIconSize(icon->getIconSize()), getIconSize(icon->getIconSize())); UIColor *imageTintColor = [acoConfig getTextBlockColor:(ACRContainerStyle::ACRDefault) textColor:icon->getForgroundColor() subtleOption:false]; diff --git a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRSVGImageView.mm b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRSVGImageView.mm index 2d1d29b3a..130ab823e 100644 --- a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRSVGImageView.mm +++ b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRSVGImageView.mm @@ -9,6 +9,7 @@ #import "ACRSVGImageView.h" #import "Icon.h" #import "ACRErrors.h" +#import "UtiliOS.h" #ifdef SWIFT_PACKAGE /// Swift Package Imports #import "SVGKit.h" @@ -115,7 +116,7 @@ - (void)showUnavailableIcon { // we will always show hardcoded square icon as fallback NSString *fallbackURLName = @"Square"; - NSString *fallBackURLString = [[NSString alloc] initWithFormat:@"%s%@/%@.json",AdaptiveCards::baseIconCDNUrl, fallbackURLName, fallbackURLName]; + NSString *fallBackURLString = [[NSString alloc] initWithFormat:@"%@%@/%@.json", baseFluentIconCDNURL, fallbackURLName, fallbackURLName]; NSURL *svgURL = [[NSURL alloc] initWithString:fallBackURLString]; [self makeIconCDNRequestWithURL:svgURL completion:^(NSDictionary * _Nullable dict, NSError * _Nullable error) { if (dict != nil) diff --git a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/PrivateHeaders/UtiliOS.h b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/PrivateHeaders/UtiliOS.h index 54ad2914f..9b462bf5e 100644 --- a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/PrivateHeaders/UtiliOS.h +++ b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/PrivateHeaders/UtiliOS.h @@ -40,6 +40,8 @@ using namespace AdaptiveCards; extern const CGFloat kACRScalerTolerance; +extern NSString const *baseFluentIconCDNURL; + // configures tag and initial visibility of the given view. Toggle visibility action // will access the view by the tag to change the visibility. void configVisibility(UIView *view, std::shared_ptr const &visibilityInfo); @@ -180,3 +182,7 @@ NSString* stringWithRemovedBackslashedSymbols(NSString *stringToRemoveSymbols, N BOOL isNullOrEmpty(NSString *string); NSString *stringForCString(const std::optional cString); + +//CDN URL for icon path +NSString *cdnURLForIcon(NSString *iconPath); + diff --git a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/UtiliOS.mm b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/UtiliOS.mm index 4b80d28f3..9c3e22833 100644 --- a/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/UtiliOS.mm +++ b/source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/UtiliOS.mm @@ -30,6 +30,7 @@ // tolerance value for computing scaler for background cover size const CGFloat kACRScalerTolerance = 0.025f; +NSString const *baseFluentIconCDNURL = @"https://res-1.cdn.office.net/assets/fluentui-react-icons/2.0.226/"; void configVisibility(UIView *view, std::shared_ptr const &visibilityInfo) { @@ -1294,3 +1295,10 @@ BOOL isNullOrEmpty(NSString *string) { return [NSString stringWithCString:cStr encoding:NSUTF8StringEncoding]; } + +NSString *cdnURLForIcon(NSString *iconPath) +{ + NSObject *featureFlagResolver = [[ACRRegistration getInstance] getFeatureFlagResolver]; + NSString const *CDNPath = [featureFlagResolver stringForFlag:@"fluentIconCdnURL"] ?: baseFluentIconCDNURL; + return [[NSString alloc] initWithFormat:@"%@%@",CDNPath, iconPath]; +} diff --git a/source/shared/cpp/ObjectModel/BaseActionElement.cpp b/source/shared/cpp/ObjectModel/BaseActionElement.cpp index e3396d1f8..a11fd9d23 100644 --- a/source/shared/cpp/ObjectModel/BaseActionElement.cpp +++ b/source/shared/cpp/ObjectModel/BaseActionElement.cpp @@ -38,7 +38,7 @@ const std::string& BaseActionElement::GetIconUrl() const return m_iconUrl; } -std::string BaseActionElement::GetSVGInfoURL() const +std::string BaseActionElement::GetSVGPath() const { std::regex regex{R"([,:]+)"}; // split on ':' and ',' std::sregex_token_iterator it{m_iconUrl.begin(), m_iconUrl.end(), regex, -1}; @@ -51,7 +51,7 @@ std::string BaseActionElement::GetSVGInfoURL() const iconStyle = config[config.size() - 1]; } } - std::string m_url = baseIconCDNUrl + iconName + "/" + iconName + ".json"; + std::string m_url = iconName + "/" + iconName + ".json"; return m_url; } diff --git a/source/shared/cpp/ObjectModel/BaseActionElement.h b/source/shared/cpp/ObjectModel/BaseActionElement.h index 1b7bbb6d3..3d09628fb 100644 --- a/source/shared/cpp/ObjectModel/BaseActionElement.h +++ b/source/shared/cpp/ObjectModel/BaseActionElement.h @@ -30,7 +30,7 @@ class BaseActionElement : public BaseElement virtual void SetTitle(const std::string& value); const std::string& GetIconUrl() const; - std::string GetSVGInfoURL() const; + std::string GetSVGPath() const; void SetIconUrl(std::string&& value); void SetIconUrl(const std::string& value); diff --git a/source/shared/cpp/ObjectModel/Icon.cpp b/source/shared/cpp/ObjectModel/Icon.cpp index 4099e3ef0..693eabc1b 100644 --- a/source/shared/cpp/ObjectModel/Icon.cpp +++ b/source/shared/cpp/ObjectModel/Icon.cpp @@ -138,15 +138,14 @@ void Icon::PopulateKnownPropertiesSet() void Icon::GetResourceInformation(std::vector& resourceInfo) { RemoteResourceInformation imageResourceInfo; - imageResourceInfo.url = GetSVGInfoURL(); + imageResourceInfo.url = GetSVGPath(); imageResourceInfo.mimeType = "image"; resourceInfo.push_back(imageResourceInfo); } -std::string Icon::GetSVGInfoURL() const +std::string Icon::GetSVGPath() const { // format: "/.json" - // https://res-1.cdn.office.net/assets/fluentui-react-icons/2.0.226/Rss/Rss.json - std::string m_url = baseIconCDNUrl + GetName() + "/" + GetName() + ".json"; + std::string m_url = GetName() + "/" + GetName() + ".json"; return m_url; } diff --git a/source/shared/cpp/ObjectModel/Icon.h b/source/shared/cpp/ObjectModel/Icon.h index 27b58fe2f..21bc15288 100644 --- a/source/shared/cpp/ObjectModel/Icon.h +++ b/source/shared/cpp/ObjectModel/Icon.h @@ -7,11 +7,6 @@ #include "BaseCardElement.h" #include "ElementParserRegistration.h" -namespace AdaptiveCards { - // This is CDN base url for all fluent svg icons - constexpr const char* const baseIconCDNUrl = "https://res-1.cdn.office.net/assets/fluentui-react-icons/2.0.226/"; -} - namespace AdaptiveCards { class Icon : public BaseCardElement @@ -41,7 +36,7 @@ class Icon : public BaseCardElement std::shared_ptr GetSelectAction() const; void SetSelectAction(const std::shared_ptr action); - std::string GetSVGInfoURL() const; + std::string GetSVGPath() const; void GetResourceInformation(std::vector& resourceInfo) override; diff --git a/source/shared/cpp/ObjectModel/IconInfo.cpp b/source/shared/cpp/ObjectModel/IconInfo.cpp index 1313abf38..faf0d7da8 100644 --- a/source/shared/cpp/ObjectModel/IconInfo.cpp +++ b/source/shared/cpp/ObjectModel/IconInfo.cpp @@ -113,10 +113,9 @@ void IconInfo::PopulateKnownPropertiesSet() AdaptiveCardSchemaKeyToString(AdaptiveCardSchemaKey::Style)}); } -std::string IconInfo::GetSVGInfoURL() const +std::string IconInfo::GetSVGPath() const { // format: "/.json" - // https://res-1.cdn.office.net/assets/fluentui-react-icons/2.0.226/Rss/Rss.json - std::string m_url = baseIconCDNUrl + GetName() + "/" + GetName() + ".json"; + std::string m_url = GetName() + "/" + GetName() + ".json"; return m_url; } diff --git a/source/shared/cpp/ObjectModel/IconInfo.h b/source/shared/cpp/ObjectModel/IconInfo.h index ebc8d6957..69e67ff39 100644 --- a/source/shared/cpp/ObjectModel/IconInfo.h +++ b/source/shared/cpp/ObjectModel/IconInfo.h @@ -21,7 +21,7 @@ namespace AdaptiveCards { ~IconInfo() = default; Json::Value SerializeToJsonValue() const; static std::shared_ptr Deserialize(const Json::Value& json); - std::string GetSVGInfoURL() const; + std::string GetSVGPath() const; ForegroundColor getForgroundColor() const; void setForgroundColor(const ForegroundColor value); From d2ca7f91cf5d78f250d5ec4e37daa2e363ec55e9 Mon Sep 17 00:00:00 2001 From: manpreet Date: Thu, 5 Sep 2024 13:11:50 +0530 Subject: [PATCH 4/5] using GetSVGPath method from shared cpp code to create SVGInfoURL --- .../io/adaptivecards/renderer/UtilTest.java | 21 ------------ .../src/main/cpp/objectmodel_wrap.cpp | 24 ++++---------- .../objectmodel/AdaptiveCardObjectModel.java | 4 --- .../AdaptiveCardObjectModelJNI.java | 7 ++-- .../objectmodel/BaseActionElement.java | 4 +-- .../io/adaptivecards/objectmodel/Icon.java | 4 +-- .../adaptivecards/objectmodel/IconInfo.java | 4 +-- .../renderer/CompoundButtonRenderer.java | 2 +- .../renderer/FluentIconImageLoaderAsync.kt | 3 +- .../java/io/adaptivecards/renderer/Util.java | 33 +++++-------------- .../action/ActionElementRenderer.java | 3 +- .../action/DropdownElementRenderer.java | 3 +- .../renderer/readonly/FluentIconsRenderer.kt | 2 +- 13 files changed, 29 insertions(+), 85 deletions(-) diff --git a/source/android/adaptivecards/src/androidTest/java/io/adaptivecards/renderer/UtilTest.java b/source/android/adaptivecards/src/androidTest/java/io/adaptivecards/renderer/UtilTest.java index 0ebcd04ae..58622292e 100644 --- a/source/android/adaptivecards/src/androidTest/java/io/adaptivecards/renderer/UtilTest.java +++ b/source/android/adaptivecards/src/androidTest/java/io/adaptivecards/renderer/UtilTest.java @@ -53,25 +53,4 @@ public void testGetSizeClosestToGivenSize_5() { long closestSize = Util.getSizeClosestToGivenSize(availableSizes, targetSize); assertEquals(24L, closestSize); } - - @Test - public void testExtractFluentIconNameFromUrl_1() { - String url = "icon:Rss"; - String iconName = Util.extractFluentIconNameFromUrl(url); - assertEquals("Rss", iconName); - } - - @Test - public void testExtractFluentIconNameFromUrl_2() { - String url = "icon:Rss,regular"; - String iconName = Util.extractFluentIconNameFromUrl(url); - assertEquals("Rss", iconName); - } - - @Test - public void testExtractFluentIconNameFromUrl_3() { - String url = "icon:Rss,filled"; - String iconName = Util.extractFluentIconNameFromUrl(url); - assertEquals("Rss", iconName); - } } diff --git a/source/android/adaptivecards/src/main/cpp/objectmodel_wrap.cpp b/source/android/adaptivecards/src/main/cpp/objectmodel_wrap.cpp index 327b3de69..cc225a682 100644 --- a/source/android/adaptivecards/src/main/cpp/objectmodel_wrap.cpp +++ b/source/android/adaptivecards/src/main/cpp/objectmodel_wrap.cpp @@ -14689,7 +14689,7 @@ SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectM } -SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_BaseActionElement_1GetSVGInfoURL(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { +SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_BaseActionElement_1GetSVGPath(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { jstring jresult = 0 ; AdaptiveCards::BaseActionElement *arg1 = (AdaptiveCards::BaseActionElement *) 0 ; std::shared_ptr< AdaptiveCards::BaseActionElement const > *smartarg1 = 0 ; @@ -14701,7 +14701,7 @@ SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectM smartarg1 = *(std::shared_ptr< const AdaptiveCards::BaseActionElement > **)&jarg1; arg1 = (AdaptiveCards::BaseActionElement *)(smartarg1 ? smartarg1->get() : 0); - result = ((AdaptiveCards::BaseActionElement const *)arg1)->GetSVGInfoURL(); + result = ((AdaptiveCards::BaseActionElement const *)arg1)->GetSVGPath(); jresult = jenv->NewStringUTF((&result)->c_str()); return jresult; } @@ -17085,18 +17085,6 @@ SWIGEXPORT jlong JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectMod } -SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_baseIconCDNUrl_1get(JNIEnv *jenv, jclass jcls) { - jstring jresult = 0 ; - char *result = 0 ; - - (void)jenv; - (void)jcls; - result = (char *)(char *)AdaptiveCards::baseIconCDNUrl; - if (result) jresult = jenv->NewStringUTF((const char *)result); - return jresult; -} - - SWIGEXPORT jlong JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_new_1Icon_1_1SWIG_10(JNIEnv *jenv, jclass jcls) { jlong jresult = 0 ; AdaptiveCards::Icon *result = 0 ; @@ -17345,7 +17333,7 @@ SWIGEXPORT void JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectMode } -SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_Icon_1GetSVGInfoURL(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { +SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_Icon_1GetSVGPath(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { jstring jresult = 0 ; AdaptiveCards::Icon *arg1 = (AdaptiveCards::Icon *) 0 ; std::shared_ptr< AdaptiveCards::Icon const > *smartarg1 = 0 ; @@ -17357,7 +17345,7 @@ SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectM smartarg1 = *(std::shared_ptr< const AdaptiveCards::Icon > **)&jarg1; arg1 = (AdaptiveCards::Icon *)(smartarg1 ? smartarg1->get() : 0); - result = ((AdaptiveCards::Icon const *)arg1)->GetSVGInfoURL(); + result = ((AdaptiveCards::Icon const *)arg1)->GetSVGPath(); jresult = jenv->NewStringUTF((&result)->c_str()); return jresult; } @@ -41605,7 +41593,7 @@ SWIGEXPORT jlong JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectMod } -SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_IconInfo_1GetSVGInfoURL(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { +SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_IconInfo_1GetSVGPath(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { jstring jresult = 0 ; AdaptiveCards::IconInfo *arg1 = (AdaptiveCards::IconInfo *) 0 ; std::shared_ptr< AdaptiveCards::IconInfo const > *smartarg1 = 0 ; @@ -41617,7 +41605,7 @@ SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectM smartarg1 = *(std::shared_ptr< const AdaptiveCards::IconInfo > **)&jarg1; arg1 = (AdaptiveCards::IconInfo *)(smartarg1 ? smartarg1->get() : 0); - result = ((AdaptiveCards::IconInfo const *)arg1)->GetSVGInfoURL(); + result = ((AdaptiveCards::IconInfo const *)arg1)->GetSVGPath(); jresult = jenv->NewStringUTF((&result)->c_str()); return jresult; } diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/AdaptiveCardObjectModel.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/AdaptiveCardObjectModel.java index 3ebe19903..cf037539c 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/AdaptiveCardObjectModel.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/AdaptiveCardObjectModel.java @@ -481,8 +481,4 @@ public static String ToLowercase(String value) { return AdaptiveCardObjectModelJNI.ToLowercase(value); } - public static String getBaseIconCDNUrl() { - return AdaptiveCardObjectModelJNI.baseIconCDNUrl_get(); - } - } diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/AdaptiveCardObjectModelJNI.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/AdaptiveCardObjectModelJNI.java index bfd1d315f..5e9fd3044 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/AdaptiveCardObjectModelJNI.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/AdaptiveCardObjectModelJNI.java @@ -679,7 +679,7 @@ public class AdaptiveCardObjectModelJNI { public final static native void BaseActionElement_SetTitle__SWIG_1(long jarg1, BaseActionElement jarg1_, String jarg2); public final static native void BaseActionElement_SetTitleSwigExplicitBaseActionElement__SWIG_1(long jarg1, BaseActionElement jarg1_, String jarg2); public final static native String BaseActionElement_GetIconUrl(long jarg1, BaseActionElement jarg1_); - public final static native String BaseActionElement_GetSVGInfoURL(long jarg1, BaseActionElement jarg1_); + public final static native String BaseActionElement_GetSVGPath(long jarg1, BaseActionElement jarg1_); public final static native void BaseActionElement_SetIconUrl__SWIG_0(long jarg1, BaseActionElement jarg1_, long jarg2); public final static native void BaseActionElement_SetIconUrl__SWIG_1(long jarg1, BaseActionElement jarg1_, String jarg2); public final static native String BaseActionElement_GetStyle(long jarg1, BaseActionElement jarg1_); @@ -804,7 +804,6 @@ public class AdaptiveCardObjectModelJNI { public final static native void delete_ContainerParser(long jarg1); public final static native long ContainerParser_Deserialize(long jarg1, ContainerParser jarg1_, long jarg2, ParseContext jarg2_, long jarg3, JsonValue jarg3_); public final static native long ContainerParser_DeserializeFromString(long jarg1, ContainerParser jarg1_, long jarg2, ParseContext jarg2_, String jarg3); - public final static native String baseIconCDNUrl_get(); public final static native long new_Icon__SWIG_0(); public final static native long new_Icon__SWIG_1(long jarg1, Icon jarg1_); public final static native void delete_Icon(long jarg1); @@ -819,7 +818,7 @@ public class AdaptiveCardObjectModelJNI { public final static native void Icon_SetName(long jarg1, Icon jarg1_, String jarg2); public final static native long Icon_GetSelectAction(long jarg1, Icon jarg1_); public final static native void Icon_SetSelectAction(long jarg1, Icon jarg1_, long jarg2, BaseActionElement jarg2_); - public final static native String Icon_GetSVGInfoURL(long jarg1, Icon jarg1_); + public final static native String Icon_GetSVGPath(long jarg1, Icon jarg1_); public final static native void Icon_GetResourceInformation(long jarg1, Icon jarg1_, long jarg2, RemoteResourceInformationVector jarg2_); public final static native long Icon_dynamic_cast(long jarg1, BaseCardElement jarg1_); public final static native long new_IconParser__SWIG_0(); @@ -2078,7 +2077,7 @@ public class AdaptiveCardObjectModelJNI { public final static native void delete_IconInfo(long jarg1); public final static native long IconInfo_SerializeToJsonValue(long jarg1, IconInfo jarg1_); public final static native long IconInfo_Deserialize(long jarg1, JsonValue jarg1_); - public final static native String IconInfo_GetSVGInfoURL(long jarg1, IconInfo jarg1_); + public final static native String IconInfo_GetSVGPath(long jarg1, IconInfo jarg1_); public final static native int IconInfo_getForgroundColor(long jarg1, IconInfo jarg1_); public final static native void IconInfo_setForgroundColor(long jarg1, IconInfo jarg1_, int jarg2); public final static native int IconInfo_getIconSize(long jarg1, IconInfo jarg1_); diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/BaseActionElement.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/BaseActionElement.java index 1f02a40b6..3978b318b 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/BaseActionElement.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/BaseActionElement.java @@ -95,8 +95,8 @@ public String GetIconUrl() { return AdaptiveCardObjectModelJNI.BaseActionElement_GetIconUrl(swigCPtr, this); } - public String GetSVGInfoURL() { - return AdaptiveCardObjectModelJNI.BaseActionElement_GetSVGInfoURL(swigCPtr, this); + public String GetSVGPath() { + return AdaptiveCardObjectModelJNI.BaseActionElement_GetSVGPath(swigCPtr, this); } public void SetIconUrl(SWIGTYPE_p_std__string value) { diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/Icon.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/Icon.java index 22d6962f6..58ffb2529 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/Icon.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/Icon.java @@ -96,8 +96,8 @@ public void SetSelectAction(BaseActionElement action) { AdaptiveCardObjectModelJNI.Icon_SetSelectAction(swigCPtr, this, BaseActionElement.getCPtr(action), action); } - public String GetSVGInfoURL() { - return AdaptiveCardObjectModelJNI.Icon_GetSVGInfoURL(swigCPtr, this); + public String GetSVGPath() { + return AdaptiveCardObjectModelJNI.Icon_GetSVGPath(swigCPtr, this); } public void GetResourceInformation(RemoteResourceInformationVector resourceInfo) { diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/IconInfo.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/IconInfo.java index 76fea03a6..c5a236d39 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/IconInfo.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/objectmodel/IconInfo.java @@ -57,8 +57,8 @@ public static IconInfo Deserialize(JsonValue json) { return (cPtr == 0) ? null : new IconInfo(cPtr, true); } - public String GetSVGInfoURL() { - return AdaptiveCardObjectModelJNI.IconInfo_GetSVGInfoURL(swigCPtr, this); + public String GetSVGPath() { + return AdaptiveCardObjectModelJNI.IconInfo_GetSVGPath(swigCPtr, this); } public ForegroundColor getForgroundColor() { diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/CompoundButtonRenderer.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/CompoundButtonRenderer.java index f4e964389..a5a6294b4 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/CompoundButtonRenderer.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/CompoundButtonRenderer.java @@ -110,7 +110,7 @@ private ViewGroup getCompoundButtonLayout(Context context, CompoundButton compou imageView.setVisibility(View.GONE); } else { boolean isFilledStyle = compoundButton.getIcon().getIconStyle() == IconStyle.Filled; - String svgInfoURL = compoundButton.getIcon().GetSVGInfoURL(); + String svgInfoURL = Util.getSvgInfoUrl(compoundButton.getIcon().GetSVGPath()); String foregroundColorIcon = hostConfig.GetForegroundColor(ContainerStyle.Default, compoundButton.getIcon().getForgroundColor(), false); FluentIconImageLoaderAsync fluentIconImageLoaderAsync = new FluentIconImageLoaderAsync( renderedCard, diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/FluentIconImageLoaderAsync.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/FluentIconImageLoaderAsync.kt index 26c805366..437e91810 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/FluentIconImageLoaderAsync.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/FluentIconImageLoaderAsync.kt @@ -101,7 +101,7 @@ open class FluentIconImageLoaderAsync( */ private fun fetchUnavailableIconInfo(): HttpRequestResult? { isFilledStyle = true - val unavailableIconURL = Util.getSvgInfoUrl(SQUARE_ICON) + val unavailableIconURL = Util.getUnavailableIconSvgInfoUrl() return try { val responseBytes = HttpRequestHelper.get(unavailableIconURL) HttpRequestResult(String (responseBytes, StandardCharsets.UTF_8)) @@ -147,7 +147,6 @@ open class FluentIconImageLoaderAsync( companion object { const val FILLED_STYLE = "filled" const val REGULAR_STYLE = "regular" - const val SQUARE_ICON = "Square" const val FLIP_IN_RTL_PROPERTY = "flipInRtl" } diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/Util.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/Util.java index d09f5d045..f2c847f2d 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/Util.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/Util.java @@ -797,36 +797,21 @@ static long getSizeClosestToGivenSize(List availableSizes, Long targetIcon return closestSize; } - /** - * icon url format - icon:[,regular | filled] - * sample icon url - icon:Rss,regular - **/ - public static String extractFluentIconNameFromUrl(String iconUrl) { - - // Split the string by the colon character - String[] parts = iconUrl.split(":"); - - // Check if the split operation resulted in at least 2 parts - if (parts.length >= 2) { - // Split the second part by the comma character - String[] iconParts = parts[1].split(","); - - // Return the first part which is the icon name - return iconParts[0]; - } - - // Return empty string if the icon name could not be extracted - return ""; - } - /** * format: "/.json" * https://res-1.cdn.office.net/assets/fluentui-react-icons/2.0.226/Rss/Rss.json **/ - public static String getSvgInfoUrl(String iconName) { + public static String getSvgInfoUrl(String svgPath) { + String fluentIconCdnRoot = FeatureFlagResolverUtility.INSTANCE.fetchFluentIconCdnRoot(); + String fluentIconCdnPath = FeatureFlagResolverUtility.INSTANCE.fetchFluentIconCdnPath(); + return String.format("%s/%s/%s", fluentIconCdnRoot, fluentIconCdnPath, svgPath); + } + + public static String getUnavailableIconSvgInfoUrl() { + String unavailableIconName = "Square"; String fluentIconCdnRoot = FeatureFlagResolverUtility.INSTANCE.fetchFluentIconCdnRoot(); String fluentIconCdnPath = FeatureFlagResolverUtility.INSTANCE.fetchFluentIconCdnPath(); - return String.format("%s/%s/%s/%s.json", fluentIconCdnRoot, fluentIconCdnPath, iconName, iconName); + return String.format("%s/%s/%s/%s.json", fluentIconCdnRoot, fluentIconCdnPath, unavailableIconName, unavailableIconName); } private static final String FLUENT_ICON_URL_PREFIX = "icon:"; diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/ActionElementRenderer.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/ActionElementRenderer.java index c25fa4976..c81b815b8 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/ActionElementRenderer.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/ActionElementRenderer.java @@ -152,8 +152,7 @@ public Button renderButton( button.post(() -> Util.expandClickArea(button, minHeight)); String iconUrl = baseActionElement.GetIconUrl(); - String fluentIconName = Util.extractFluentIconNameFromUrl(iconUrl); - String svgInfoURL = Util.getSvgInfoUrl(fluentIconName); + String svgInfoURL = Util.getSvgInfoUrl(baseActionElement.GetSVGPath()); if (!iconUrl.isEmpty()) { diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/DropdownElementRenderer.java b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/DropdownElementRenderer.java index b2dd2fb27..cb383dd38 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/DropdownElementRenderer.java +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/action/DropdownElementRenderer.java @@ -72,8 +72,7 @@ public Button render(RenderedAdaptiveCard renderedCard, Context context, Fragmen Button button = actionRenderer.render(renderedCard, context, fragmentManager, viewGroup, baseActionElement, cardActionHandler, hostConfig, renderArgs); viewGroup.removeView(button); - String fluentIconName = Util.extractFluentIconNameFromUrl(iconUrl); - String svgInfoURL = Util.getSvgInfoUrl(fluentIconName); + String svgInfoURL = Util.getSvgInfoUrl(baseActionElement.GetSVGPath()); Button dropDownItem = new Button(context, null, R.style.Widget_AppCompat_Light_ActionButton_Overflow); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/FluentIconsRenderer.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/FluentIconsRenderer.kt index a6f508b64..fd72c3e7e 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/FluentIconsRenderer.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/readonly/FluentIconsRenderer.kt @@ -44,7 +44,7 @@ object FluentIconsRenderer : BaseCardElementRenderer() { ): View { val icon = Util.castTo(baseCardElement, Icon::class.java) val view = ImageView(context) - val svgURL = Util.getSvgInfoUrl(icon.GetName()) + val svgURL = Util.getSvgInfoUrl(icon.GetSVGPath()) val foregroundColor = hostConfig.GetForegroundColor(ContainerStyle.Default, icon.forgroundColor, false) val isFilledStyle = icon.iconStyle == IconStyle.Filled From 5f3837d139b5406291fe2878ffe1190de21a92d5 Mon Sep 17 00:00:00 2001 From: manpreet Date: Thu, 5 Sep 2024 13:40:37 +0530 Subject: [PATCH 5/5] making return type as optional string for getEcsSettingAsString method --- .../main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt index d92276481..d520bf0b1 100644 --- a/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt +++ b/source/android/adaptivecards/src/main/java/io/adaptivecards/renderer/IFeatureFlagResolver.kt @@ -9,5 +9,5 @@ interface IFeatureFlagResolver { fun getEcsSettingAsBoolean(key: String): Boolean - fun getEcsSettingAsString(key: String): String + fun getEcsSettingAsString(key: String): String? }