From d27c3c7d8b5d1837f3eeeec741751408f93e6630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Schia?= Date: Sat, 17 Aug 2024 08:13:05 +0200 Subject: [PATCH] Make check for expressive variants more generic as there are more than just --active variants --- .github/scripts/generate-android-vectors.js | 13 +- .../main/kotlin/no/nrk/core/icons/NrkIcons.kt | 118 +++++++++--------- 2 files changed, 67 insertions(+), 64 deletions(-) diff --git a/.github/scripts/generate-android-vectors.js b/.github/scripts/generate-android-vectors.js index d903ccc9..7290bab9 100644 --- a/.github/scripts/generate-android-vectors.js +++ b/.github/scripts/generate-android-vectors.js @@ -130,11 +130,14 @@ function generateKotlinValues() { // Probably a more efficient way to do this, but I don't think it really matters const expressiveVariant = generatedDrawables.find((element) => { - const isActiveVariant = drawable.match("__active") - - if (isActiveVariant) { - // Active expressive variants are named "horse_expressive__active", if "_expressive" was always the postfix we could just handle it like non-active ones - return element == rawNormalIconName.replace("__active", "") + "_expressive__active.xml" + // Icon variants such as "nrk-bell--active", "nrk-media-play-expressive--fail", or " nrk-media-volume-expressive--1" + // Variants end with "--variant", with "-expressive" being infront of the variant type. For those we need to insert "_expressive" into the name + // instead of just adding it at the end like + const indexOfVariantStart = drawable.indexOf("__") + + if (indexOfVariantStart != -1) { + // From "nrk_media_playe__fail" to "nrk_media_playe_expressive__fail" + return element == rawNormalIconName.substring(0, indexOfVariantStart) + "_expressive" + rawNormalIconName.substring(indexOfVariantStart) + ".xml" } else { return element == rawNormalIconName + "_expressive.xml" } diff --git a/android/icons/src/main/kotlin/no/nrk/core/icons/NrkIcons.kt b/android/icons/src/main/kotlin/no/nrk/core/icons/NrkIcons.kt index aa00666a..a558dfb1 100644 --- a/android/icons/src/main/kotlin/no/nrk/core/icons/NrkIcons.kt +++ b/android/icons/src/main/kotlin/no/nrk/core/icons/NrkIcons.kt @@ -123,16 +123,16 @@ object NrkIcons { expressive = R.drawable.nrk_broadcast_expressive ) - val NrkBulletSquare = NrkIcon( - normal = R.drawable.nrk_bullet_square, - expressive = R.drawable.nrk_bullet_square_expressive - ) - val NrkBulletedList = NrkIcon( normal = R.drawable.nrk_bulleted_list, expressive = R.drawable.nrk_bulleted_list_expressive ) + val NrkBulletSquare = NrkIcon( + normal = R.drawable.nrk_bullet_square, + expressive = R.drawable.nrk_bullet_square_expressive + ) + val NrkCalendar = NrkIcon( normal = R.drawable.nrk_calendar, expressive = R.drawable.nrk_calendar_expressive @@ -153,16 +153,6 @@ object NrkIcons { expressive = R.drawable.nrk_check_expressive ) - val NrkCheckActive = NrkIcon( - normal = R.drawable.nrk_check__active, - expressive = R.drawable.nrk_check_expressive__active - ) - - val NrkCheckRadioUnchecked = NrkIcon( - normal = R.drawable.nrk_check_radio__unchecked, - expressive = null - ) - val NrkCheckbox = NrkIcon( normal = R.drawable.nrk_checkbox, expressive = R.drawable.nrk_checkbox_expressive @@ -173,6 +163,16 @@ object NrkIcons { expressive = R.drawable.nrk_checkbox_expressive__active ) + val NrkCheckRadioUnchecked = NrkIcon( + normal = R.drawable.nrk_check_radio__unchecked, + expressive = null + ) + + val NrkCheckActive = NrkIcon( + normal = R.drawable.nrk_check__active, + expressive = R.drawable.nrk_check_expressive__active + ) + val NrkChevronDown = NrkIcon( normal = R.drawable.nrk_chevron_down, expressive = R.drawable.nrk_chevron_down_expressive @@ -328,11 +328,6 @@ object NrkIcons { expressive = R.drawable.nrk_geo_expressive ) - val NrkGeoActive = NrkIcon( - normal = R.drawable.nrk_geo__active, - expressive = R.drawable.nrk_geo_expressive__active - ) - val NrkGeopoint = NrkIcon( normal = R.drawable.nrk_geopoint, expressive = R.drawable.nrk_geopoint_expressive @@ -343,6 +338,11 @@ object NrkIcons { expressive = R.drawable.nrk_geopoint_expressive__active ) + val NrkGeoActive = NrkIcon( + normal = R.drawable.nrk_geo__active, + expressive = R.drawable.nrk_geo_expressive__active + ) + val NrkGlobe = NrkIcon( normal = R.drawable.nrk_globe, expressive = R.drawable.nrk_globe_expressive @@ -575,17 +575,17 @@ object NrkIcons { val NrkMediaChromecast1 = NrkIcon( normal = R.drawable.nrk_media_chromecast__1, - expressive = null + expressive = R.drawable.nrk_media_chromecast_expressive__1 ) val NrkMediaChromecast2 = NrkIcon( normal = R.drawable.nrk_media_chromecast__2, - expressive = null + expressive = R.drawable.nrk_media_chromecast_expressive__2 ) val NrkMediaChromecast3 = NrkIcon( normal = R.drawable.nrk_media_chromecast__3, - expressive = null + expressive = R.drawable.nrk_media_chromecast_expressive__3 ) val NrkMediaChromecastActive = NrkIcon( @@ -603,9 +603,14 @@ object NrkIcons { expressive = null ) - val NrkMediaDirekteActive = NrkIcon( - normal = R.drawable.nrk_media_direkte__active, - expressive = null + val NrkMediaDirektetv = NrkIcon( + normal = R.drawable.nrk_media_direktetv, + expressive = R.drawable.nrk_media_direktetv_expressive + ) + + val NrkMediaDirektetvActive = NrkIcon( + normal = R.drawable.nrk_media_direktetv__active, + expressive = R.drawable.nrk_media_direktetv_expressive__active ) val NrkMediaDirekteAnimatedActive = NrkIcon( @@ -623,14 +628,9 @@ object NrkIcons { expressive = null ) - val NrkMediaDirektetv = NrkIcon( - normal = R.drawable.nrk_media_direktetv, - expressive = R.drawable.nrk_media_direktetv_expressive - ) - - val NrkMediaDirektetvActive = NrkIcon( - normal = R.drawable.nrk_media_direktetv__active, - expressive = R.drawable.nrk_media_direktetv_expressive__active + val NrkMediaDirekteActive = NrkIcon( + normal = R.drawable.nrk_media_direkte__active, + expressive = null ) val NrkMediaFfw = NrkIcon( @@ -703,11 +703,6 @@ object NrkIcons { expressive = R.drawable.nrk_media_play_expressive ) - val NrkMediaPlayFail = NrkIcon( - normal = R.drawable.nrk_media_play__fail, - expressive = null - ) - val NrkMediaPlaylist = NrkIcon( normal = R.drawable.nrk_media_playlist, expressive = R.drawable.nrk_media_playlist_expressive @@ -718,6 +713,11 @@ object NrkIcons { expressive = R.drawable.nrk_media_playlist_add_expressive ) + val NrkMediaPlaylistAdded = NrkIcon( + normal = R.drawable.nrk_media_playlist_added, + expressive = R.drawable.nrk_media_playlist_added_expressive + ) + val NrkMediaPlaylistAddLater = NrkIcon( normal = R.drawable.nrk_media_playlist_add_later, expressive = R.drawable.nrk_media_playlist_add_later_expressive @@ -728,16 +728,16 @@ object NrkIcons { expressive = R.drawable.nrk_media_playlist_add_next_expressive ) - val NrkMediaPlaylistAdded = NrkIcon( - normal = R.drawable.nrk_media_playlist_added, - expressive = R.drawable.nrk_media_playlist_added_expressive - ) - val NrkMediaPlaylistRemove = NrkIcon( normal = R.drawable.nrk_media_playlist_remove, expressive = R.drawable.nrk_media_playlist_remove_expressive ) + val NrkMediaPlayFail = NrkIcon( + normal = R.drawable.nrk_media_play__fail, + expressive = R.drawable.nrk_media_play_expressive__fail + ) + val NrkMediaPrevious = NrkIcon( normal = R.drawable.nrk_media_previous, expressive = R.drawable.nrk_media_previous_expressive @@ -758,16 +758,16 @@ object NrkIcons { expressive = R.drawable.nrk_media_quaver_expressive ) - val NrkMediaQuaverActive = NrkIcon( - normal = R.drawable.nrk_media_quaver__active, - expressive = R.drawable.nrk_media_quaver_expressive__active - ) - val NrkMediaQuaverOff = NrkIcon( normal = R.drawable.nrk_media_quaver_off, expressive = R.drawable.nrk_media_quaver_off_expressive ) + val NrkMediaQuaverActive = NrkIcon( + normal = R.drawable.nrk_media_quaver__active, + expressive = R.drawable.nrk_media_quaver_expressive__active + ) + val NrkMediaRwd = NrkIcon( normal = R.drawable.nrk_media_rwd, expressive = R.drawable.nrk_media_rwd_expressive @@ -798,6 +798,11 @@ object NrkIcons { expressive = null ) + val NrkMediaSpeed1x = NrkIcon( + normal = R.drawable.nrk_media_speed_1x, + expressive = null + ) + val NrkMediaSpeed125x = NrkIcon( normal = R.drawable.nrk_media_speed_1_25x, expressive = null @@ -808,11 +813,6 @@ object NrkIcons { expressive = null ) - val NrkMediaSpeed1x = NrkIcon( - normal = R.drawable.nrk_media_speed_1x, - expressive = null - ) - val NrkMediaSpeed2x = NrkIcon( normal = R.drawable.nrk_media_speed_2x, expressive = null @@ -835,7 +835,7 @@ object NrkIcons { val NrkMediaSubtitlesUnavailable = NrkIcon( normal = R.drawable.nrk_media_subtitles__unavailable, - expressive = null + expressive = R.drawable.nrk_media_subtitles_expressive__unavailable ) val NrkMediaTheater = NrkIcon( @@ -870,22 +870,22 @@ object NrkIcons { val NrkMediaVolume1 = NrkIcon( normal = R.drawable.nrk_media_volume__1, - expressive = null + expressive = R.drawable.nrk_media_volume_expressive__1 ) val NrkMediaVolume2 = NrkIcon( normal = R.drawable.nrk_media_volume__2, - expressive = null + expressive = R.drawable.nrk_media_volume_expressive__2 ) val NrkMediaVolume3 = NrkIcon( normal = R.drawable.nrk_media_volume__3, - expressive = null + expressive = R.drawable.nrk_media_volume_expressive__3 ) val NrkMediaVolumeMuted = NrkIcon( normal = R.drawable.nrk_media_volume__muted, - expressive = null + expressive = R.drawable.nrk_media_volume_expressive__muted ) val NrkMening = NrkIcon(