Skip to content

Commit 045dc30

Browse files
committed
Fixed: Builds broken
1 parent 154b540 commit 045dc30

2 files changed

Lines changed: 31 additions & 13 deletions

File tree

app/src/main/java/org/gnucash/android/app/GnuCashApplication.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,7 @@ public static boolean shouldSaveOpeningBalances(boolean defaultValue){
159159
* @return Default currency code string for the application
160160
*/
161161
public static String getDefaultCurrencyCode(){
162-
Locale locale = Locale.getDefault();
163-
//sometimes the locale en_UK is returned which causes a crash with Currency
164-
if (locale.getCountry().equals("UK")) {
165-
locale = new Locale(locale.getLanguage(), "GB");
166-
}
167-
168-
//for unsupported locale es_LG
169-
if (locale.getCountry().equals("LG")){
170-
locale = new Locale(locale.getLanguage(), "ES");
171-
}
162+
Locale locale = getDefaultLocale();
172163

173164
String currencyCode = "USD"; //start with USD as the default
174165
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@@ -183,6 +174,29 @@ public static String getDefaultCurrencyCode(){
183174
return currencyCode;
184175
}
185176

177+
/**
178+
* Returns the default locale which is used for currencies, while handling special cases for
179+
* locales which are not supported for currency such as en_GB
180+
* @return The default locale for this device
181+
*/
182+
public static Locale getDefaultLocale() {
183+
Locale locale = Locale.getDefault();
184+
//sometimes the locale en_UK is returned which causes a crash with Currency
185+
if (locale.getCountry().equals("UK")) {
186+
locale = new Locale(locale.getLanguage(), "GB");
187+
}
188+
189+
//for unsupported locale es_LG
190+
if (locale.getCountry().equals("LG")){
191+
locale = new Locale(locale.getLanguage(), "ES");
192+
}
193+
194+
if (locale.getCountry().equals("en")){
195+
locale = Locale.US;
196+
}
197+
return locale;
198+
}
199+
186200
/**
187201
* Starts the service for scheduled events and schedules an alarm to call the service twice daily.
188202
* <p>If the alarm already exists, this method does nothing. If not, the alarm will be created

app/src/main/java/org/gnucash/android/model/Money.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ public final class Money implements Comparable<Money>{
9292
* A zero instance with the currency of the default locale.
9393
* This can be used anywhere where a starting amount is required without having to create a new object
9494
*/
95-
private static final Money sDefaultZero = Money.createZeroInstance(GnuCashApplication.getDefaultCurrencyCode());
95+
private static Money sDefaultZero;
9696

9797
/**
9898
* Returns a Money instance initialized to the local currency and value 0
9999
* @return Money instance of value 0 in locale currency
100100
*/
101101
public static Money getZeroInstance(){
102-
return sDefaultZero;
102+
if (sDefaultZero == null) {
103+
String currencyCode = Currency.getInstance(GnuCashApplication.getDefaultLocale()).getCurrencyCode();
104+
sDefaultZero = new Money(BigDecimal.ZERO, Currency.getInstance(currencyCode));
105+
}
106+
return sDefaultZero;
103107
}
104108

105109
/**
@@ -180,7 +184,7 @@ public static Money createZeroInstance(String currencyCode){
180184
*/
181185
private void init() {
182186
mCurrency = Currency.getInstance(Money.DEFAULT_CURRENCY_CODE);
183-
mAmount = new BigDecimal(0).setScale(DEFAULT_DECIMAL_PLACES, DEFAULT_ROUNDING_MODE);
187+
mAmount = BigDecimal.ZERO.setScale(DEFAULT_DECIMAL_PLACES, DEFAULT_ROUNDING_MODE);
184188
}
185189

186190
/**

0 commit comments

Comments
 (0)