@@ -51,41 +51,46 @@ object UtilityForecastIcon {
5151 // ntsra,80
5252 // legacy: i=nsn;j=nsn;ip=60;jp=30
5353 // legacy add - 2nd condition
54- private fun parseBitmapString (context : Context , url : String ): Bitmap = if (url.contains(" /" ) || url.contains(" ;j=" ) || (url.contains(" i=" ) && url.contains(" j=" ))) {
55- val conditions = url.split(" /" ).dropLastWhile { it.isEmpty() } // snow,20/ovc,20
56- if (conditions.size > 1 ) {
57- getDualBitmapWithNumbers(context, conditions[0 ], conditions[1 ])
58- } else {
59- // legacy add
60- val urlTmp = url.replace(" i=" , " " )
54+ private fun parseBitmapString (context : Context , url : String ): Bitmap =
55+ if (url.contains(" /" ) || url.contains(" ;j=" ) || (url.contains(" i=" ) && url.contains(" j=" ))) {
56+ val conditions = url.split(" /" ).dropLastWhile { it.isEmpty() } // snow,20/ovc,20
57+ if (conditions.size > 1 ) {
58+ getDualBitmapWithNumbers(context, conditions[0 ], conditions[1 ])
59+ } else {
60+ // legacy add
61+ val urlTmp = url.replace(" i=" , " " )
6162 .replace(" j=" , " " )
6263 .replace(" ip=" , " " )
6364 .replace(" jp=" , " " )
64- val items = urlTmp.split(" ;" )
65- if (items.size > 3 ) {
66- getDualBitmapWithNumbers(context, items[0 ] + items[2 ], items[1 ] + items[3 ])
67- } else if (items.size > 2 ) {
68- if (url.contains(" ;jp=" )) {
69- getDualBitmapWithNumbers(context, items[0 ], items[1 ] + items[2 ])
65+ val items = urlTmp.split(" ;" )
66+ if (items.size > 3 ) {
67+ getDualBitmapWithNumbers(context, items[0 ] + items[2 ], items[1 ] + items[3 ])
68+ } else if (items.size > 2 ) {
69+ if (url.contains(" ;jp=" )) {
70+ getDualBitmapWithNumbers(context, items[0 ], items[1 ] + items[2 ])
71+ } else {
72+ getDualBitmapWithNumbers(context, items[0 ] + items[2 ], items[1 ])
73+ }
7074 } else {
71- getDualBitmapWithNumbers(context, items[0 ] + items[ 2 ] , items[1 ])
75+ getDualBitmapWithNumbers(context, items[0 ], items[1 ])
7276 }
73- } else {
74- getDualBitmapWithNumbers(context, items[0 ], items[1 ])
77+ // legacy add end
7578 }
76- // legacy add end
79+ } else {
80+ getBitmapWithOneNumber(context, url)
7781 }
78- } else {
79- getBitmapWithOneNumber(context, url)
80- }
8182
8283 // Given two strings return a custom bitmap made of two bitmaps with optional numeric label
8384 // input examples
8485 // rain_showers,60 rain_showers,30
8586 // nrain_showers,80 nrain_showers,70
8687 // ntsra_hi,40 ntsra_hi
8788 // bkn rain
88- private fun getDualBitmapWithNumbers (context : Context , iconLeftString : String , iconRightString : String ): Bitmap {
89+ private fun getDualBitmapWithNumbers (
90+ context : Context ,
91+ iconLeftString : String ,
92+ iconRightString : String
93+ ): Bitmap {
8994 val leftTokens = iconLeftString.split(" ," ).dropLastWhile { it.isEmpty() }
9095 val rightTokens = iconRightString.split(" ," ).dropLastWhile { it.isEmpty() }
9196 var leftNumber = if (leftTokens.size > 1 ) {
@@ -150,18 +155,20 @@ object UtilityForecastIcon {
150155
151156 private fun getFilename (url : String ): String {
152157 var fileName = url.replace(" ?size=medium" , " " )
153- .replace(" ?size=small" , " " )
154- .replace(" https://api.weather.gov/icons/land/" , " " )
155- .replace(" http://api.weather.gov/icons/land/" , " " )
156- .replace(" http://nids-wapiapp.bldr.ncep.noaa.gov:9000/icons/land/" , " " )
157- .replace(" day/" , " " )
158- // legacy add
159- .replace(" http://forecast.weather.gov/newimages/medium/" , " " )
160- .replace(" https://forecast.weather.gov/newimages/medium/" , " " )
161- .replace(" .png" , " " )
162- .replace(" http://forecast.weather.gov/DualImage.php?" , " " )
163- .replace(" https://forecast.weather.gov/DualImage.php?" , " " )
164- .replace(" &" , " " )
158+ .replace(" ?size=small" , " " )
159+ .replace(" https://api.weather.gov/icons/land/" , " " )
160+ .replace(" http://api.weather.gov/icons/land/" , " " )
161+ .replace(" http://nids-wapiapp.bldr.ncep.noaa.gov:9000/icons/land/" , " " )
162+ // below line added as a work around in response to this bug: https://github.com/weather-gov/api/discussions/733
163+ .replace(" /icons/land/" , " " )
164+ .replace(" day/" , " " )
165+ // legacy add
166+ .replace(" http://forecast.weather.gov/newimages/medium/" , " " )
167+ .replace(" https://forecast.weather.gov/newimages/medium/" , " " )
168+ .replace(" .png" , " " )
169+ .replace(" http://forecast.weather.gov/DualImage.php?" , " " )
170+ .replace(" https://forecast.weather.gov/DualImage.php?" , " " )
171+ .replace(" &" , " " )
165172 // legacy add end
166173 if (fileName.contains(" night" )) {
167174 fileName = fileName.replace(" night/" , " n" ).replace(" /" , " /n" )
0 commit comments