blongho / worldCountryData

Android library for country flag, currency, and other country information
https://blongho.github.io/worldCountryData/doc/
MIT License
98 stars 35 forks source link

Currencies not being loaded because of validation #33

Closed serhuz closed 2 years ago

serhuz commented 3 years ago

There's a logic that checks whether the given currency is valid

private boolean isValid(final Currency currency) {
    return currency != null && currency.getSymbol() != null && currency.getName() != null
        && currency.getCode() != null;
  }

Yet, there are currencies which have no symbol defined, like Hong Kong Dollar

{
    "country": "HK",
    "name": "Hong Kong dollar",
    "code": "HKD"
 }

This effectively excludes such currencies from being added to currencyMap field.

private void loadCurrencies(Context context) {
    final String currencyArray = AssetsReader.readFromAssets(context,
        R.raw.com_blongho_country_data_currencies);
    Gson gson = new Gson();
    final Currency[] currencies = gson.fromJson(currencyArray, Currency[].class);
    for (final Currency currency : currencies) {
      if (isValid(currency)) {
        currencyMap.put(currency.getCountry().toLowerCase(), currency);
      }
    }
  }

Would it make sense to mark the symbol field as @Nullable and remove isValid() check?

github-actions[bot] commented 3 years ago

Your first issue in worldCountryData. The team will take a look at it as soon as possible

github-actions[bot] commented 3 years ago

Staled issue

blongho commented 2 years ago

Thanks for this eye-opener. This issue has been resolved