Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android + iOS]: Allow configuration of AC Fluent icon CDN paths for different environments #232

Merged
merged 8 commits into from
Sep 6, 2024
Merged
10 changes: 5 additions & 5 deletions samples/v1.5/Scenarios/RatingInput.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"isRequired": true,
"label": "Pick a rating",
"errorMessage": "Please pick a rating",
"horizontalAlignment": "left",
"horizontalAlignment": "Left",
"max": 5
},
{
Expand All @@ -27,7 +27,7 @@
"errorMessage": "Please pick a rating",
"color": "marigold",
"value": 2,
"horizontalAlignment": "left",
"horizontalAlignment": "Left",
"max": 5
},
{
Expand All @@ -41,7 +41,7 @@
"type": "Rating",
"value": 3.2,
"size": "medium",
"horizontalAlignment": "left",
"horizontalAlignment": "Left",
"count": 10
},
{
Expand All @@ -50,7 +50,7 @@
"value": 3.2,
"color": "marigold",
"size": "large",
"horizontalAlignment": "left",
"horizontalAlignment": "Left",
"count": 150
},
{
Expand All @@ -60,7 +60,7 @@
"color": "marigold",
"count": 1500,
"size": "large",
"horizontalAlignment": "left"
"horizontalAlignment": "Left"
}
],
"actions": [
Expand Down
24 changes: 6 additions & 18 deletions source/android/adaptivecards/src/main/cpp/objectmodel_wrap.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ open class FluentIconImageLoaderAsync(
*/
private fun fetchUnavailableIconInfo(): HttpRequestResult<String>? {
isFilledStyle = true
val unavailableIconURL = "${AdaptiveCardObjectModel.getBaseIconCDNUrl()}/$SQUARE_ICON/$SQUARE_ICON.json"
val unavailableIconURL = Util.getUnavailableIconSvgInfoUrl()
return try {
val responseBytes = HttpRequestHelper.get(unavailableIconURL)
HttpRequestResult(String (responseBytes, StandardCharsets.UTF_8))
Expand Down Expand Up @@ -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"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ package io.adaptivecards.renderer
interface IFeatureFlagResolver {

fun getEcsSettingAsBoolean(key: String): Boolean

fun getEcsSettingAsString(key: String): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,23 @@ static long getSizeClosestToGivenSize(List<Long> availableSizes, Long targetIcon
return closestSize;
}

/**
* format: "<fluentIconCdnRoot><fluentIconCdnPath><Icon Name>/<IconName>.json"
* https://res-1.cdn.office.net/assets/fluentui-react-icons/2.0.226/Rss/Rss.json
**/
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, unavailableIconName, unavailableIconName);
}

private static final String FLUENT_ICON_URL_PREFIX = "icon:";

public static String getOpenUrlAnnouncement(Context context, String urlTitle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Button renderButton(
button.post(() -> Util.expandClickArea(button, minHeight));

String iconUrl = baseActionElement.GetIconUrl();
String svgInfoURL = baseActionElement.GetSVGInfoURL();
String svgInfoURL = Util.getSvgInfoUrl(baseActionElement.GetSVGPath());

if (!iconUrl.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +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 svgResourceURL = baseActionElement.GetSVGInfoURL();
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);
Expand All @@ -90,7 +90,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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetSVGPath())
val foregroundColor = hostConfig.GetForegroundColor(ContainerStyle.Default, icon.forgroundColor, false)
val isFilledStyle = icon.iconStyle == IconStyle.Filled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ 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"
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
Expand All @@ -29,4 +33,18 @@ object FeatureFlagResolverUtility {
return featureFlagResolver?.getEcsSettingAsBoolean(IS_ITEM_FIT_TO_FILL_ENABLED_FOR_COLUMN)
?: false
}

fun fetchFluentIconCdnRoot(): String {
val featureFlagResolver = CardRendererRegistration.getInstance().featureFlagResolver
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
val fluentIconCdnPathValue = featureFlagResolver?.getEcsSettingAsString(FLUENT_ICON_CDN_PATH_ECS_KEY)
return if (fluentIconCdnPathValue.isNullOrEmpty()) FLUENT_ICON_CDN_PATH_DEFAULT_VALUE
else fluentIconCdnPathValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package io.adaptivecards.adaptivecardssample.CustomObjects;

import androidx.annotation.NonNull;

import io.adaptivecards.renderer.IFeatureFlagResolver;

public class FeatureFlagResolver implements IFeatureFlagResolver {
Expand All @@ -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 "";
}
}
Loading