Skip to content

Commit af507a1

Browse files
committed
Squashes bugs from Android crash logs
- Fixed bug causing crash on start for some locales where device locale has no supported currency - Fixed app crash post-import/export operations - Updated Contributions section of README
1 parent 0b49a97 commit af507a1

File tree

9 files changed

+86
-54
lines changed

9 files changed

+86
-54
lines changed

README.md

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,58 @@
11
# Introduction
22

33
Gnucash Mobile for Android is companion application for desktop Gnucash designed for Android.
4-
It allows you to record transactions on-the-go and export them in the OFX format and later import the data into Gnucash for the desktop. You can create multiple accounts for transactions in Gnucash. Double-entry accounting is also supported.
4+
It allows you to record transactions on-the-go and export them in the QIF or OFX format and later import the data into Gnucash for the desktop. You can create multiple accounts for transactions in Gnucash. Double-entry accounting is also supported.
55

66
The application supports Android 2.2 Froyo (API level 8) and above.
77

88

99
# Installation
1010

11-
There are different ways to get the Gnucash app for Android; through the app store, or building it yourself.
11+
There are different ways to get the Gnucash app for Android; through the app store, or building it yourself.
1212

1313

14-
### App Store
14+
### App Store
1515

1616
<a href="http://play.google.com/store/apps/details?id=org.gnucash.android">
1717
<img alt="Android app on Google Play" src="http://developer.android.com/images/brand/en_generic_rgb_wo_60.png" />
18-
</a>
19-
20-
21-
## Building
22-
23-
The build requires [Maven](http://maven.apache.org/download.html)
24-
v3.0.3+ and the [Android SDK](http://developer.android.com/sdk/index.html)
25-
to be installed in your development environment. In addition you'll need to set
26-
the `ANDROID_HOME` environment variable to the location of your SDK:
27-
28-
export ANDROID_HOME=/home/roberto/tools/android-sdk
29-
30-
After satisfying those requirements, the build is pretty simple:
31-
32-
* Run `mvn clean package` from the `app` directory to build the APK only
33-
* Run `mvn clean install` from the root directory to build the app and also run
34-
the integration tests, this requires a connected Android device or running
35-
emulator. (see this [blog post](http://goo.gl/TprMw) for details)
36-
37-
You might find that your device doesn't let you install your build if you
38-
already have the version from the Android Market installed. This is standard
39-
Android security as it it won't let you directly replace an app that's been
40-
signed with a different key. Manually uninstall GnuCash from your device and
18+
</a>
19+
20+
21+
## Building
22+
23+
The build requires [Maven](http://maven.apache.org/download.html)
24+
v3.0.3+ and the [Android SDK](http://developer.android.com/sdk/index.html)
25+
to be installed in your development environment. In addition you'll need to set
26+
the `ANDROID_HOME` environment variable to the location of your SDK:
27+
28+
export ANDROID_HOME=/home/<user>/tools/android-sdk
29+
30+
After satisfying those requirements, the build is pretty simple:
31+
32+
* Run `mvn clean package` from the `app` directory to build the APK only
33+
* Run `mvn clean install` from the root directory to build the app and also run
34+
the integration tests, this requires a connected Android device or running
35+
emulator. (see this [blog post](http://goo.gl/TprMw) for details)
36+
37+
You might find that your device doesn't let you install your build if you
38+
already have the version from the Android Market installed. This is standard
39+
Android security as it it won't let you directly replace an app that's been
40+
signed with a different key. Manually uninstall GnuCash from your device and
4141
you will then be able to install your own built version.
4242

43+
## Contributing
44+
45+
There are several ways you could contribute to the development.
46+
47+
One way is providing translations for locales which are not yet available, or improving translations.
48+
See this [blog post](http://www.codinguser.com/2012/09/gnucash-for-android-beta-2-lost-in-translation/) for some guidelines.
49+
50+
You could as well contribute code, fixing bugs, new features or automated tests.
51+
Take a look at the [bug tracker](https://github.com/codinguser/gnucash-android/issues?state=open)
52+
for ideas where to start.
53+
54+
For development, it is recommended to use the IntelliJ IDEA 13+ IDE for development which is available as free
55+
community edition. Import the project into the IDE from an external (maven) model.The IDE will resolve dependencies automatically.
4356

4457
#Licence
4558
Gnucash for Android is free software; you can redistribute it and/or

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
import android.content.Context;
2020
import android.content.SharedPreferences;
2121
import android.preference.PreferenceManager;
22+
import android.util.Log;
2223
import org.gnucash.android.R;
2324

25+
import java.util.Currency;
26+
import java.util.Locale;
27+
2428
/**
2529
* An {@link Application} subclass for retrieving static context
2630
* @author Ngewi Fet <[email protected]>
@@ -64,4 +68,33 @@ public static boolean shouldSaveOpeningBalances(boolean defaultValue){
6468
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
6569
return sharedPrefs.getBoolean(context.getString(R.string.key_save_opening_balances), defaultValue);
6670
}
71+
72+
/**
73+
* Returns the default currency code for the application. <br/>
74+
* What value is actually returned is determined in this order of priority:<ul>
75+
* <li>User currency preference (manually set be user in the app)</li>
76+
* <li>Default currency for the device locale</li>
77+
* <li>United States Dollars</li>
78+
* </ul>
79+
*
80+
* @return Default currency code string for the application
81+
*/
82+
public static String getDefaultCurrency(){
83+
Locale locale = Locale.getDefault();
84+
//sometimes the locale en_UK is returned which causes a crash with Currency
85+
if (locale.getCountry().equals("UK")) {
86+
locale = new Locale(locale.getLanguage(), "GB");
87+
}
88+
89+
String currencyCode = "USD"; //start with USD as the default
90+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
91+
try { //there are some strange locales out there
92+
currencyCode = Currency.getInstance(locale).getCurrencyCode();
93+
} catch (Throwable e) {
94+
Log.e(context.getString(R.string.app_name), e.getMessage());
95+
} finally {
96+
currencyCode = prefs.getString(context.getString(R.string.key_default_currency), currencyCode);
97+
}
98+
return currencyCode;
99+
}
67100
}

app/src/org/gnucash/android/db/AccountsDbAdapter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,14 @@ public Money getAccountBalance(long accountId){
624624
*/
625625
public List<Long> getSubAccountIds(long accountId){
626626
List<Long> subAccounts = new ArrayList<Long>();
627+
String accountUID = getAccountUID(accountId);
628+
if (accountUID == null)
629+
return subAccounts;
630+
627631
Cursor cursor = mDb.query(AccountEntry.TABLE_NAME,
628632
new String[]{AccountEntry._ID},
629633
AccountEntry.COLUMN_PARENT_ACCOUNT_UID + " = ?",
630-
new String[]{getAccountUID(accountId)},
634+
new String[]{accountUID},
631635
null, null, null);
632636

633637
if (cursor != null){

app/src/org/gnucash/android/export/ExporterTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ protected void onPostExecute(Boolean exportResult) {
172172
alertFragment.show(fragmentManager, "transactions_delete_confirmation_dialog");
173173
}
174174

175-
mProgressDialog.dismiss();
175+
if (mProgressDialog != null && mProgressDialog.isShowing())
176+
mProgressDialog.dismiss();
176177

177178
}
178179

app/src/org/gnucash/android/importer/GncXmlImportTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ protected Boolean doInBackground(InputStream... inputStreams) {
6363

6464
@Override
6565
protected void onPostExecute(Boolean importSuccess) {
66-
progressDialog.dismiss();
66+
if (progressDialog != null && progressDialog.isShowing())
67+
progressDialog.dismiss();
6768

6869
int message = importSuccess ? R.string.toast_success_importing_accounts : R.string.toast_error_importing_accounts;
6970
Toast.makeText(context, message, Toast.LENGTH_LONG).show();

app/src/org/gnucash/android/ui/account/AccountFormFragment.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,7 @@ private void setParentAccountSelection(long parentAccountId){
422422

423423
for (int pos = 0; pos < mParentAccountCursorAdapter.getCount(); pos++) {
424424
if (mParentAccountCursorAdapter.getItemId(pos) == parentAccountId){
425-
final int position = pos;
426-
mParentAccountSpinner.postDelayed(new Runnable() {
427-
@Override
428-
public void run() {
429-
mParentAccountSpinner.setSelection(position);
430-
}
431-
}, 100);
432-
// mParentAccountSpinner.setSelection(pos, true);
425+
mParentAccountSpinner.setSelection(pos, true);
433426
break;
434427
}
435428
}

app/src/org/gnucash/android/ui/account/AccountsActivity.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.actionbarsherlock.view.MenuItem;
4444
import com.viewpagerindicator.TitlePageIndicator;
4545
import org.gnucash.android.R;
46+
import org.gnucash.android.app.GnuCashApplication;
4647
import org.gnucash.android.importer.GncXmlImportTask;
4748
import org.gnucash.android.model.Money;
4849
import org.gnucash.android.ui.util.Refreshable;
@@ -252,24 +253,9 @@ public void onCreate(Bundle savedInstanceState) {
252253
private void init() {
253254
PreferenceManager.setDefaultValues(this, R.xml.fragment_transaction_preferences, false);
254255

255-
Locale locale = Locale.getDefault();
256-
//sometimes the locale en_UK is returned which causes a crash with Currency
257-
if (locale.getCountry().equals("UK")) {
258-
locale = new Locale(locale.getLanguage(), "GB");
259-
}
256+
Money.DEFAULT_CURRENCY_CODE = GnuCashApplication.getDefaultCurrency();
260257

261-
String currencyCode;
262258
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
263-
try { //there are some strange locales out there
264-
currencyCode = prefs.getString(getString(R.string.key_default_currency),
265-
Currency.getInstance(locale).getCurrencyCode());
266-
} catch (Exception e) {
267-
Log.e(LOG_TAG, e.getMessage());
268-
currencyCode = "USD";
269-
}
270-
271-
Money.DEFAULT_CURRENCY_CODE = currencyCode;
272-
273259
boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);
274260
if (firstRun){
275261
createDefaultAccounts();

app/src/org/gnucash/android/ui/transaction/TransactionFormFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ public static BigDecimal parseInputToDecimal(String amountString){
772772
if (clean.length() == 0) //empty string
773773
return BigDecimal.ZERO;
774774
//all amounts are input to 2 decimal places, so after removing decimal separator, divide by 100
775+
//TODO: Handle currencies with different kinds of decimal places
775776
BigDecimal amount = new BigDecimal(clean).setScale(2,
776777
RoundingMode.HALF_EVEN).divide(new BigDecimal(100), 2,
777778
RoundingMode.HALF_EVEN);

app/src/org/gnucash/android/ui/transaction/TransactionsListFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public void finishEditMode(){
279279
*/
280280
public void setActionModeTitle(){
281281
int count = getListView().getCheckedItemIds().length; //mSelectedIds.size();
282-
if (count > 0){
282+
if (count > 0 && mActionMode != null){
283283
mActionMode.setTitle(getResources().getString(R.string.title_selected, count));
284284
}
285285
}

0 commit comments

Comments
 (0)