|
2 | 2 |
|
3 | 3 | import static com.shakebugs.react.utils.Converter.resToString; |
4 | 4 |
|
5 | | -import android.annotation.SuppressLint; |
6 | 5 | import android.content.Context; |
7 | 6 |
|
8 | 7 | import com.facebook.react.bridge.ReadableArray; |
|
28 | 27 | import com.shakebugs.shake.internal.domain.models.NetworkRequest; |
29 | 28 | import com.shakebugs.shake.internal.domain.models.NotificationEvent; |
30 | 29 | import com.shakebugs.shake.report.ShakeFile; |
| 30 | +import com.shakebugs.shake.theme.ShakeTheme; |
31 | 31 |
|
32 | 32 | import java.util.ArrayList; |
33 | 33 | import java.util.HashMap; |
@@ -283,6 +283,37 @@ public WritableMap mapShakeFormToMap(ShakeForm shakeForm) { |
283 | 283 | return shakeFormMap; |
284 | 284 | } |
285 | 285 |
|
| 286 | + public ShakeTheme mapMapToShakeTheme(ReadableMap shakeThemeMap) { |
| 287 | + if (shakeThemeMap == null) return null; |
| 288 | + |
| 289 | + String fontFamilyBold = shakeThemeMap.hasKey("fontFamilyBold") ? shakeThemeMap.getString("fontFamilyBold") : null; |
| 290 | + String fontFamilyMedium = shakeThemeMap.hasKey("fontFamilyMedium") ? shakeThemeMap.getString("fontFamilyMedium") : null; |
| 291 | + String backgroundColor = shakeThemeMap.hasKey("backgroundColor") ? shakeThemeMap.getString("backgroundColor") : null; |
| 292 | + String secondaryBackgroundColor = shakeThemeMap.hasKey("secondaryBackgroundColor") ? shakeThemeMap.getString("secondaryBackgroundColor") : null; |
| 293 | + String textColor = shakeThemeMap.hasKey("textColor") ? shakeThemeMap.getString("textColor") : null; |
| 294 | + String secondaryTextColor = shakeThemeMap.hasKey("secondaryTextColor") ? shakeThemeMap.getString("secondaryTextColor") : null; |
| 295 | + String accentColor = shakeThemeMap.hasKey("accentColor") ? shakeThemeMap.getString("accentColor") : null; |
| 296 | + String accentTextColor = shakeThemeMap.hasKey("accentTextColor") ? shakeThemeMap.getString("accentTextColor") : null; |
| 297 | + String outlineColor = shakeThemeMap.hasKey("outlineColor") ? shakeThemeMap.getString("outlineColor") : null; |
| 298 | + Double borderRadius = shakeThemeMap.hasKey("borderRadius") ? shakeThemeMap.getDouble("borderRadius") : null; |
| 299 | + Double elevation = shakeThemeMap.hasKey("elevation") ? shakeThemeMap.getDouble("elevation") : null; |
| 300 | + |
| 301 | + ShakeTheme shakeTheme = new ShakeTheme(); |
| 302 | + shakeTheme.setFontFamilyBoldValue(findAssetPath(context, fontFamilyBold)); |
| 303 | + shakeTheme.setFontFamilyMediumValue(findAssetPath(context, fontFamilyMedium)); |
| 304 | + shakeTheme.setBackgroundColorValue(Converter.stringToColor(backgroundColor)); |
| 305 | + shakeTheme.setSecondaryBackgroundColorValue(Converter.stringToColor(secondaryBackgroundColor)); |
| 306 | + shakeTheme.setTextColorValue(Converter.stringToColor(textColor)); |
| 307 | + shakeTheme.setSecondaryTextColorValue(Converter.stringToColor(secondaryTextColor)); |
| 308 | + shakeTheme.setAccentColorValue(Converter.stringToColor(accentColor)); |
| 309 | + shakeTheme.setAccentTextColorValue(Converter.stringToColor(accentTextColor)); |
| 310 | + shakeTheme.setOutlineColorValue(Converter.stringToColor(outlineColor)); |
| 311 | + shakeTheme.setBorderRadiusValue(Converter.convertDpToPixels(context, borderRadius)); |
| 312 | + shakeTheme.setElevationValue(Converter.convertDpToPixels(context, elevation)); |
| 313 | + |
| 314 | + return shakeTheme; |
| 315 | + } |
| 316 | + |
286 | 317 | public NetworkRequest mapToNetworkRequest(ReadableMap object) { |
287 | 318 | if (object == null) return null; |
288 | 319 |
|
@@ -426,4 +457,22 @@ private Object[] toArray(ReadableArray readableArray) { |
426 | 457 |
|
427 | 458 | return array; |
428 | 459 | } |
| 460 | + |
| 461 | + private String findAssetPath(Context context, String assetName) { |
| 462 | + if (assetName == null) return null; |
| 463 | + |
| 464 | + String[] assetPaths = new String[]{"fonts", "images", "sounds"}; |
| 465 | + for (String assetPath : assetPaths) { |
| 466 | + try { |
| 467 | + String[] assets = context.getAssets().list(assetPath); |
| 468 | + for (String asset : assets) { |
| 469 | + if (asset.contains(assetName)) { |
| 470 | + return assetPath + "/" + asset; |
| 471 | + } |
| 472 | + } |
| 473 | + } catch (Exception ignore) { |
| 474 | + } |
| 475 | + } |
| 476 | + return null; |
| 477 | + } |
429 | 478 | } |
0 commit comments