Skip to content

Commit 5dbafff

Browse files
authored
Release beta-11 (#273)
* Fixed currency formatting issues * Enhanced add Transfer Method graphQL calls * Bug fixes
1 parent c0d8640 commit 5dbafff

File tree

102 files changed

+2815
-2039
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2815
-2039
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
[1.0.0-beta11](https://github.com/hyperwallet/hyperwallet-android-ui-sdk/releases/tag/1.0.0-beta11)
5+
-------------------
6+
* Fixed currency formatting issues
7+
* Enhanced add Transfer Method graphQL calls
8+
* Bug fixes
9+
410
[1.0.0-beta10](https://github.com/hyperwallet/hyperwallet-android-ui-sdk/releases/tag/1.0.0-beta10)
511
-------------------
612
* UI Enhancements

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Note that this SDK is geared towards those who need both backend data and UI fea
1818
To install Hyperwallet UI SDK, you just need to add the dependencies into your build.gradle file in Android Studio (or Gradle). For example:
1919

2020
```bash
21-
api 'com.hyperwallet.android.ui:transfermethodui:1.0.0-beta10'
22-
api 'com.hyperwallet.android.ui:receiptui:1.0.0-beta10'
23-
api 'com.hyperwallet.android.ui:transferui:1.0.0-beta10'
21+
api 'com.hyperwallet.android.ui:transfermethodui:1.0.0-beta11'
22+
api 'com.hyperwallet.android.ui:receiptui:1.0.0-beta11'
23+
api 'com.hyperwallet.android.ui:transferui:1.0.0-beta11'
2424
```
2525

2626
### Proguard

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ allprojects {
2424

2525
}
2626

27-
project.version = "1.0.0-beta10"
27+
project.version = "1.0.0-beta11"
2828

2929
}
3030

@@ -33,12 +33,12 @@ subprojects {
3333
ext {
3434
hyperwalletGroupId = 'com.hyperwallet.android.ui'
3535

36-
compileVersion = 29
36+
compileVersion = 30
3737
minVersion = 21
38-
targetVersion = 29
38+
targetVersion = 30
3939
codeVersion = 1
4040

41-
hyperwalletCoreVersion = '1.0.0-beta09'
41+
hyperwalletCoreVersion = '1.0.0-beta10'
4242
hyperwalletInsightVersion = '1.0.0-beta02'
4343
//
4444
androidMaterialVersion = '1.0.0'

commonui/src/main/java/com/hyperwallet/android/ui/common/util/CurrencyParser.java

Lines changed: 133 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.hyperwallet.android.ui.common.util;
22

3-
import static com.hyperwallet.android.model.transfer.Transfer.EMPTY_STRING;
4-
53
import android.content.Context;
64

75
import androidx.annotation.VisibleForTesting;
@@ -12,22 +10,27 @@
1210

1311
import java.io.IOException;
1412
import java.io.InputStream;
13+
import java.math.RoundingMode;
1514
import java.text.DecimalFormat;
1615
import java.text.DecimalFormatSymbols;
1716
import java.text.NumberFormat;
1817
import java.util.ArrayList;
1918
import java.util.Currency;
19+
import java.util.HashMap;
2020
import java.util.List;
21+
import java.util.Locale;
2122

2223
public class CurrencyParser {
2324
private static CurrencyParser instance;
2425
private static final String CURRENCY_LIST = "currency.json";
25-
private List<CurrencyDetails> currencyList;
26+
private final List<CurrencyDetails> currencyList;
27+
private final HashMap<String, LocaleDetails> localeList = new HashMap<>();
2628
private static final String REGEX_REMOVE_EMPTY_SPACE = "^\\s+|\\s+$";
2729

2830

2931
private CurrencyParser(Context context) {
3032
currencyList = populateCurrencyList(readJSONFromAsset(context));
33+
setLocaleList();
3134
}
3235

3336
public static CurrencyParser getInstance(Context context) {
@@ -73,21 +76,6 @@ private List<CurrencyDetails> populateCurrencyList(String currencyList) {
7376
return mCurrencyDetailsList;
7477
}
7578

76-
/**
77-
* Formats the currency as per currency code.
78-
*
79-
* @param currency Any currency symbol.
80-
* @param amount Any valid number in decimal.
81-
* @return Returns the formatted number as per currency.
82-
*/
83-
public String formatCurrency(String currency, String amount) {
84-
int numberOfFractions = getNumberOfFractionDigits(currency);
85-
NumberFormat format = NumberFormat.getCurrencyInstance();
86-
format.setMinimumFractionDigits(numberOfFractions);
87-
format.setCurrency(Currency.getInstance(currency));
88-
return format.format(Double.parseDouble(amount));
89-
}
90-
9179
@VisibleForTesting
9280
int getNumberOfFractionDigits(String currencyCode) {
9381
for (CurrencyDetails list : currencyList) {
@@ -108,15 +96,21 @@ int getNumberOfFractionDigits(String currencyCode) {
10896
*/
10997

11098
public String formatCurrencyWithSymbol(String currency, String amount) {
111-
DecimalFormat currencyFormatter = (DecimalFormat) DecimalFormat.getCurrencyInstance();
99+
DecimalFormat currencyFormatter;
100+
if(localeList.containsKey(currency)) {
101+
LocaleDetails locale = localeList.get(currency);
102+
currencyFormatter = (DecimalFormat) DecimalFormat.getCurrencyInstance((new Locale(locale.getLanguage(),locale.getCountryCode())));
103+
}else {
104+
currencyFormatter = (DecimalFormat) DecimalFormat.getCurrencyInstance();
105+
}
112106
CurrencyDetails currencyDetails = getCurrency(currency);
113107
currencyFormatter.setMinimumFractionDigits(currencyDetails == null ? 0 : currencyDetails.getDecimals());
114108
currencyFormatter.setCurrency(Currency.getInstance(currency));
115109
DecimalFormatSymbols decimalFormatSymbols = currencyFormatter.getDecimalFormatSymbols();
116110
decimalFormatSymbols.setCurrencySymbol("");
117111
currencyFormatter.setDecimalFormatSymbols(decimalFormatSymbols);
118-
String formattedAmount = currencyFormatter.format(Double.parseDouble(amount)).replaceAll(REGEX_REMOVE_EMPTY_SPACE, EMPTY_STRING);
119-
return currencyDetails == null ? "" : currencyDetails.getSymbol() + formattedAmount;
112+
String formattedAmount = currencyFormatter.format(Double.parseDouble(amount));
113+
return currencyDetails == null ? "" : currencyDetails.getSymbol() + formattedAmount.trim();
120114
}
121115

122116
public CurrencyDetails getCurrency(String currencyCode) {
@@ -127,4 +121,122 @@ public CurrencyDetails getCurrency(String currencyCode) {
127121
}
128122
return null;
129123
}
124+
125+
/**
126+
*
127+
*/
128+
public void setLocaleList() {
129+
localeList.clear();
130+
localeList.put("AED",new LocaleDetails("en","AE"));
131+
localeList.put("ALL",new LocaleDetails("en","US"));
132+
localeList.put("AMD",new LocaleDetails("hy","AM"));
133+
localeList.put("ARS",new LocaleDetails("es","AR"));
134+
localeList.put("AUD",new LocaleDetails("en","AU"));
135+
localeList.put("BAM",new LocaleDetails("hr","BA"));
136+
localeList.put("BDT",new LocaleDetails("en","BD"));
137+
localeList.put("BGN",new LocaleDetails("bg","BG"));
138+
localeList.put("BHD",new LocaleDetails("en","US"));
139+
localeList.put("BOB",new LocaleDetails("qu","BO"));
140+
localeList.put("BRL",new LocaleDetails("en","BR"));
141+
localeList.put("BWP",new LocaleDetails("en","BW"));
142+
localeList.put("CAD",new LocaleDetails("en","CA"));
143+
localeList.put("CHF",new LocaleDetails("en","CH"));
144+
localeList.put("CLP",new LocaleDetails("es","CL"));
145+
localeList.put("CNH",new LocaleDetails("en","CN"));
146+
localeList.put("CNY",new LocaleDetails("en","CN"));
147+
localeList.put("COP",new LocaleDetails("es","CO"));
148+
localeList.put("CZK",new LocaleDetails("cs","CZ"));
149+
localeList.put("DKK",new LocaleDetails("en","DK"));
150+
localeList.put("EEK",new LocaleDetails("en","US"));
151+
localeList.put("EGP",new LocaleDetails("en","US"));
152+
localeList.put("ETB",new LocaleDetails("so","ET"));
153+
localeList.put("EUR",new LocaleDetails("es","EA"));
154+
localeList.put("FJD",new LocaleDetails("en","FJ"));
155+
localeList.put("GBP",new LocaleDetails("kw","GB"));
156+
localeList.put("GHS",new LocaleDetails("ee","GH"));
157+
localeList.put("GMD",new LocaleDetails("en","GM"));
158+
localeList.put("HKD",new LocaleDetails("en","HK"));
159+
localeList.put("HRK",new LocaleDetails("es","HR"));
160+
localeList.put("HUF",new LocaleDetails("hu","HU"));
161+
localeList.put("IDR",new LocaleDetails("jv","ID"));
162+
localeList.put("ILS",new LocaleDetails("he","IL"));
163+
localeList.put("INR",new LocaleDetails("en","IN"));
164+
localeList.put("ISK",new LocaleDetails("en","US"));
165+
localeList.put("JMD",new LocaleDetails("en","JM"));
166+
localeList.put("JOD",new LocaleDetails("en","us"));
167+
localeList.put("JPY",new LocaleDetails("en","JP"));
168+
localeList.put("KES",new LocaleDetails("guz","KE"));
169+
localeList.put("KHR",new LocaleDetails("km","KH"));
170+
localeList.put("KRW",new LocaleDetails("en","KR"));
171+
localeList.put("KWD",new LocaleDetails("en","US"));
172+
localeList.put("KZT",new LocaleDetails("ru","KZ"));
173+
localeList.put("LAK",new LocaleDetails("lo","LA"));
174+
localeList.put("LKR",new LocaleDetails("ta","LK"));
175+
localeList.put("LSL",new LocaleDetails("en","US"));
176+
localeList.put("MAD",new LocaleDetails("zgh","MA"));
177+
localeList.put("MGA",new LocaleDetails("en","MG"));
178+
localeList.put("MRU",new LocaleDetails("ff","MR"));
179+
localeList.put("MUR",new LocaleDetails("en","MU"));
180+
localeList.put("MWK",new LocaleDetails("en","MW"));
181+
localeList.put("MXN",new LocaleDetails("en","MX"));
182+
localeList.put("MYR",new LocaleDetails("en","MY"));
183+
localeList.put("MZN",new LocaleDetails("mgh","MZ"));
184+
localeList.put("NAD",new LocaleDetails("af","NA"));
185+
localeList.put("NGN",new LocaleDetails("en","NG"));
186+
localeList.put("NOK",new LocaleDetails("nn","NO"));
187+
localeList.put("NPR",new LocaleDetails("en","US"));
188+
localeList.put("NZD",new LocaleDetails("en","PN"));
189+
localeList.put("OMR",new LocaleDetails("ae","OM"));
190+
localeList.put("PEN",new LocaleDetails("en","PE"));
191+
localeList.put("PGK",new LocaleDetails("en","PG"));
192+
localeList.put("PHP",new LocaleDetails("ceb","PH"));
193+
localeList.put("PKR",new LocaleDetails("en","PK"));
194+
localeList.put("PLN",new LocaleDetails("pl","PL"));
195+
localeList.put("QAR",new LocaleDetails("en","US"));
196+
localeList.put("RON",new LocaleDetails("ro","RO"));
197+
localeList.put("RSD",new LocaleDetails("sr","Latn_RS"));
198+
localeList.put("RUB",new LocaleDetails("ru","RU"));
199+
localeList.put("SBD",new LocaleDetails("en","SB"));
200+
localeList.put("SEK",new LocaleDetails("en","SE"));
201+
localeList.put("SGD",new LocaleDetails("ta","SG"));
202+
localeList.put("SVG",new LocaleDetails("en","US"));
203+
localeList.put("SZL",new LocaleDetails("en","SZ"));
204+
localeList.put("THB",new LocaleDetails("th","TH"));
205+
localeList.put("TND",new LocaleDetails("en","TN"));
206+
localeList.put("TOP",new LocaleDetails("to","TO"));
207+
localeList.put("TRY",new LocaleDetails("tr","TR"));
208+
localeList.put("TWD",new LocaleDetails("zh","TW"));
209+
localeList.put("UGX",new LocaleDetails("cgg","UG"));
210+
localeList.put("USD",new LocaleDetails("es","US"));
211+
localeList.put("UYU",new LocaleDetails("es","UY"));
212+
localeList.put("VND",new LocaleDetails("vi","VN"));
213+
localeList.put("VUV",new LocaleDetails("en","VU"));
214+
localeList.put("WST",new LocaleDetails("en","WS"));
215+
localeList.put("XPF",new LocaleDetails("fr","PF"));
216+
localeList.put("ZAR",new LocaleDetails("en","ZA"));
217+
localeList.put("ZMW",new LocaleDetails("en","ZM"));
218+
}
219+
220+
public HashMap<String, LocaleDetails> getLocaleList()
221+
{
222+
return localeList;
223+
}
224+
/**
225+
* truncate decimals for given value
226+
*
227+
* @param value Any value in string.
228+
* @param noOfDecimals number of decimal to be truncate.
229+
* @return Returns truncated decimal value.
230+
*/
231+
public static String getValueWithTruncateDecimals(String value, int noOfDecimals) {
232+
if (value != null) {
233+
NumberFormat nf = NumberFormat.getNumberInstance();
234+
nf.setMaximumFractionDigits(noOfDecimals);
235+
nf.setRoundingMode(RoundingMode.HALF_UP);
236+
double amount = Double.parseDouble(value);
237+
return nf.format(amount);
238+
} else {
239+
return "";
240+
}
241+
}
130242
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.hyperwallet.android.ui.common.util;
2+
3+
public class LocaleDetails {
4+
private String language;
5+
private String countryCode;
6+
7+
public LocaleDetails(String language, String countryCode) {
8+
this.language = language;
9+
this.countryCode = countryCode;
10+
}
11+
12+
public String getLanguage() {
13+
return language;
14+
}
15+
16+
public String getCountryCode() {
17+
return countryCode;
18+
}
19+
}

0 commit comments

Comments
 (0)