Skip to content

Commit

Permalink
Autoselect the default currency for the user in the first run dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
rivaldi8 committed Feb 2, 2015
1 parent 93e4354 commit 17b4b8b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/src/org/gnucash/android/ui/account/AccountsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Currency;
import java.util.List;
import java.util.Locale;

/**
* Manages actions related to accounts, displaying, exporting and creating new accounts
Expand Down Expand Up @@ -443,11 +446,16 @@ public void onClick(DialogInterface dialog, int which) {
AccountsActivity.this,
android.R.layout.select_dialog_singlechoice,
getResources().getStringArray(R.array.currency_names));
adb.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

final List<String> currencyCodes = Arrays.asList(
getResources().getStringArray(R.array.key_currency_codes));
String userCurrencyCode = Currency.getInstance(Locale.getDefault()).getCurrencyCode();
int currencyIndex = currencyCodes.indexOf(userCurrencyCode.toUpperCase());

adb.setSingleChoiceItems(arrayAdapter, currencyIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String currency = Arrays.asList(getResources().getStringArray(R.array.key_currency_codes)).get(which);
String currency = currencyCodes.get(which);
PreferenceManager.getDefaultSharedPreferences(AccountsActivity.this)
.edit()
.putString(getString(R.string.key_default_currency), currency)
Expand Down

0 comments on commit 17b4b8b

Please sign in to comment.