Skip to content

Commit

Permalink
Merge branch 'hotfix/patches' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGELOG.md
	app/build.gradle
	app/src/main/java/org/gnucash/android/db/adapter/AccountsDbAdapter.java
	app/src/main/java/org/gnucash/android/model/Account.java
	app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java
	app/src/main/java/org/gnucash/android/ui/report/piechart/PieChartFragment.java
	app/src/main/java/org/gnucash/android/ui/transaction/dialog/TransferFundsDialogFragment.java
	app/src/main/res/values-it-rIT/strings.xml
	app/src/main/res/values-pl-rPL/strings.xml
	app/src/main/res/values-pt-rPT/strings.xml
	app/src/main/res/values-ro-rRO/strings.xml
	app/src/main/res/values-ru/strings.xml
	app/src/main/res/values-sv-rSE/strings.xml

FIXME: Prices are halved when retrieved
  • Loading branch information
codinguser committed Apr 19, 2016
2 parents 4e1b1a8 + c0d00e1 commit 637cefc
Show file tree
Hide file tree
Showing 34 changed files with 430 additions and 332 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ Version 2.1.0 *(2016-xx-xx)*
* Improved: Scheduled transactions now have more accurate timestamps
* Improved: Generate all scheduled transactions even if a scheduled is missed (e.g. device off)

Version 2.0.6 *(2016-02-20)*
Version 2.0.7 *(2016-04-20)*
----------------------------
* Fixed: Currency exchange rate does not accept very small rates (> 2 decimal places)
* Improved: Updated translations for Japanese, Polish, French, Version 2.0.6 *(2016-02-20)*
----------------------------
* Fixed: Saving transaction gets slower with increase in size of database
* Fixed: Imbalance amount wrongly computed in split editor (for some accounts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ public long bulkAddRecords(@NonNull List<Account> accountList, UpdateMethod upda
stmt.bindString(2, account.getDescription());
stmt.bindString(3, account.getAccountType().name());
stmt.bindString(4, account.getCurrency().getCurrencyCode());
if (account.getColorHexCode() != null) {
stmt.bindString(5, account.getColorHexCode());
if (account.getColor() != Account.DEFAULT_COLOR) {
stmt.bindString(5, convertToRGBHexString(account.getColor()));
}
stmt.bindLong(6, account.isFavorite() ? 1 : 0);
stmt.bindString(7, account.getFullName());
Expand Down Expand Up @@ -200,6 +200,10 @@ public long bulkAddRecords(@NonNull List<Account> accountList, UpdateMethod upda
return stmt;
}

private String convertToRGBHexString(int color) {
return String.format("#%06X", (0xFFFFFF & color));
}

/**
* Marks all transactions for a given account as exported
* @param accountUID Unique ID of the record to be marked as exported
Expand Down Expand Up @@ -401,14 +405,17 @@ private Account buildSimpleAccountInstance(Cursor c) {
Account account = new Account(c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_NAME)));
populateBaseModelAttributes(c, account);

account.setDescription(c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_DESCRIPTION)));
String description = c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_DESCRIPTION));
account.setDescription(description == null ? "" : description);
account.setParentUID(c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_PARENT_ACCOUNT_UID)));
account.setAccountType(AccountType.valueOf(c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_TYPE))));
Currency currency = Currency.getInstance(c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_CURRENCY)));
account.setCommodity(CommoditiesDbAdapter.getInstance().getCommodity(currency.getCurrencyCode()));
account.setPlaceHolderFlag(c.getInt(c.getColumnIndexOrThrow(AccountEntry.COLUMN_PLACEHOLDER)) == 1);
account.setDefaultTransferAccountUID(c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_DEFAULT_TRANSFER_ACCOUNT_UID)));
account.setColorCode(c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_COLOR_CODE)));
String color = c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_COLOR_CODE));
if (color != null)
account.setColor(color);
account.setFavorite(c.getInt(c.getColumnIndexOrThrow(AccountEntry.COLUMN_FAVORITE)) == 1);
account.setFullName(c.getString(c.getColumnIndexOrThrow(AccountEntry.COLUMN_FULL_NAME)));
account.setHidden(c.getInt(c.getColumnIndexOrThrow(AccountEntry.COLUMN_HIDDEN)) == 1);
Expand Down Expand Up @@ -555,7 +562,7 @@ public String getOrCreateImbalanceAccountUID(Currency currency){
account.setAccountType(AccountType.BANK);
account.setParentUID(getOrCreateGnuCashRootAccountUID());
account.setHidden(!GnuCashApplication.isDoubleEntryEnabled());
account.setColorCode("#964B00");
account.setColor("#964B00");
addRecord(account, UpdateMethod.insert);
uid = account.getUID();
}
Expand Down Expand Up @@ -589,7 +596,7 @@ public String createAccountHierarchy(String fullName, AccountType accountType) {
String[] tokens = fullName.trim().split(ACCOUNT_NAME_SEPARATOR);
String uid = getOrCreateGnuCashRootAccountUID();
String parentName = "";
ArrayList<Account> accountsList = new ArrayList<Account>();
ArrayList<Account> accountsList = new ArrayList<>();
for (String token : tokens) {
parentName += token;
String parentUID = findAccountUidByFullName(parentName);
Expand Down Expand Up @@ -829,8 +836,8 @@ public Money getAccountsBalance(@NonNull List<String> accountUIDList, long star
public List<String> getDescendantAccountUIDs(String accountUID, String where, String[] whereArgs) {
// accountsList will hold accountUID with all descendant accounts.
// accountsListLevel will hold descendant accounts of the same level
ArrayList<String> accountsList = new ArrayList<String>();
ArrayList<String> accountsListLevel = new ArrayList<String>();
ArrayList<String> accountsList = new ArrayList<>();
ArrayList<String> accountsListLevel = new ArrayList<>();
accountsListLevel.add(accountUID);
for (;;) {
Cursor cursor = mDb.query(AccountEntry.TABLE_NAME,
Expand Down Expand Up @@ -1094,14 +1101,14 @@ public boolean isFavoriteAccount(String accountUID){
*/
public List<Transaction> getAllOpeningBalanceTransactions(){
Cursor cursor = fetchAccounts(null, null, null);
List<Transaction> openingTransactions = new ArrayList<Transaction>();
List<Transaction> openingTransactions = new ArrayList<>();
try {
SplitsDbAdapter splitsDbAdapter = mTransactionsAdapter.getSplitDbAdapter();
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(AccountEntry._ID));
String accountUID = getUID(id);
String currencyCode = getCurrencyCode(accountUID);
ArrayList<String> accountList = new ArrayList<String>();
ArrayList<String> accountList = new ArrayList<>();
accountList.add(accountUID);
Money balance = splitsDbAdapter.computeSplitBalance(accountList,
currencyCode, getAccountType(accountUID).hasDebitNormalBalance());
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/java/org/gnucash/android/importer/GncXmlHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ public class GncXmlHandler extends DefaultHandler {
*/
private static final String LOG_TAG = "GnuCashAccountImporter";

/*
^ anchor for start of string
# the literal #
( start of group
?: indicate a non-capturing group that doesn't generate back-references
[0-9a-fA-F] hexadecimal digit
{3} three times
) end of group
{2} repeat twice
$ anchor for end of string
*/
/**
* Regular expression for validating color code strings.
* Accepts #rgb and #rrggbb
*/
//TODO: Allow use of #aarrggbb format as well
public static final String ACCOUNT_COLOR_HEX_REGEX = "^#(?:[0-9a-fA-F]{3}){2}$";

/**
* Adapter for saving the imported accounts
*/
Expand Down Expand Up @@ -519,11 +537,11 @@ public void endElement(String uri, String localName, String qualifiedName) throw
//so we trim the last digit in each block, doesn't affect the color much
if (!color.equals("Not Set")) {
// avoid known exception, printStackTrace is very time consuming
if (!Pattern.matches(Account.COLOR_HEX_REGEX, color))
if (!Pattern.matches(ACCOUNT_COLOR_HEX_REGEX, color))
color = "#" + color.replaceAll(".(.)?", "$1").replace("null", "");
try {
if (mAccount != null)
mAccount.setColorCode(color);
mAccount.setColor(color);
} catch (IllegalArgumentException ex) {
//sometimes the color entry in the account file is "Not set" instead of just blank. So catch!
Log.e(LOG_TAG, "Invalid color code '" + color + "' for account " + mAccount.getName());
Expand Down
99 changes: 48 additions & 51 deletions app/src/main/java/org/gnucash/android/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package org.gnucash.android.model;


import android.graphics.Color;
import android.support.annotation.NonNull;

import org.gnucash.android.BuildConfig;
import org.gnucash.android.export.ofx.OfxHelper;
import org.w3c.dom.Document;
Expand All @@ -26,7 +29,6 @@
import java.util.ArrayList;
import java.util.Currency;
import java.util.List;
import java.util.regex.Pattern;

/**
* An account represents a transaction account in with {@link Transaction}s may be recorded
Expand All @@ -47,25 +49,13 @@ public class Account extends BaseModel{
*/
public static final String MIME_TYPE = "vnd.android.cursor.item/vnd." + BuildConfig.APPLICATION_ID + ".account";

/*
^ anchor for start of string
# the literal #
( start of group
?: indicate a non-capturing group that doesn't generate back-references
[0-9a-fA-F] hexadecimal digit
{3} three times
) end of group
{1,2} repeat either once or twice
$ anchor for end of string
*/
/**
* Regular expression for validating color code strings.
* Accepts #rgb and #rrggbb
*/
//TODO: Allow use of #aarrggbb format as well
public static final String COLOR_HEX_REGEX = "^#(?:[0-9a-fA-F]{3}){1,2}$";
/**
* Default color, if not set explicitly through {@link #setColor(String)}.
*/
// TODO: get it from a theme value?
public static final int DEFAULT_COLOR = Color.LTGRAY;

/**
/**
* Accounts types which are used by the OFX standard
*/
public enum OfxAccountType {CHECKING, SAVINGS, MONEYMRKT, CREDITLINE }
Expand All @@ -84,7 +74,7 @@ public enum OfxAccountType {CHECKING, SAVINGS, MONEYMRKT, CREDITLINE }
/**
* Account description
*/
private String mDescription;
private String mDescription = "";

/**
* Currency used by transactions in this account
Expand All @@ -102,7 +92,7 @@ public enum OfxAccountType {CHECKING, SAVINGS, MONEYMRKT, CREDITLINE }
* Defaults to {@link AccountType#CASH}
*/
private AccountType mAccountType = AccountType.CASH;

/**
* List of transactions in this account
*/
Expand All @@ -128,7 +118,7 @@ public enum OfxAccountType {CHECKING, SAVINGS, MONEYMRKT, CREDITLINE }
/**
* Account color field in hex format #rrggbb
*/
private String mColorCode;
private int mColor = DEFAULT_COLOR;

/**
* Flag which marks this account as a favorite account
Expand All @@ -144,13 +134,13 @@ public enum OfxAccountType {CHECKING, SAVINGS, MONEYMRKT, CREDITLINE }
* An extra key for passing the currency code (according ISO 4217) in an intent
*/
public static final String EXTRA_CURRENCY_CODE = "org.gnucash.android.extra.currency_code";

/**
* Extra key for passing the unique ID of the parent account when creating a
* Extra key for passing the unique ID of the parent account when creating a
* new account using Intents
*/
public static final String EXTRA_PARENT_UID = "org.gnucash.android.extra.parent_uid";

/**
* Constructor
* Creates a new account with the default currency and a generated unique ID
Expand All @@ -161,7 +151,7 @@ public Account(String name) {
this.mFullName = mName;
setCommodity(Commodity.DEFAULT_COMMODITY);
}

/**
* Overloaded constructor
* @param name Name of the account
Expand Down Expand Up @@ -207,18 +197,18 @@ public void setFullName(String fullName) {
}

/**
* Returns the account mDescription
* @return String with mDescription
* Returns the account description
* @return String with description
*/
public String getDescription() {
return mDescription;
}

/**
* Sets the account mDescription
* @param description String mDescription
* Sets the account description
* @param description Account description
*/
public void setDescription(String description) {
public void setDescription(@NonNull String description) {
this.mDescription = description;
}

Expand Down Expand Up @@ -247,11 +237,11 @@ public void addTransaction(Transaction transaction){
transaction.setCommodity(mCommodity);
mTransactionsList.add(transaction);
}

/**
* Sets a list of transactions for this account.
* Overrides any previous transactions with those in the list.
* The account UID and currency of the transactions will be set to the unique ID
* The account UID and currency of the transactions will be set to the unique ID
* and currency of the account respectively
* @param transactionsList List of {@link Transaction}s to be set.
*/
Expand All @@ -266,7 +256,7 @@ public void setTransactions(List<Transaction> transactionsList){
public List<Transaction> getTransactions(){
return mTransactionsList;
}

/**
* Returns the number of transactions in this account
* @return Number transactions in account
Expand All @@ -289,26 +279,34 @@ public Money getBalance(){
}

/**
* Returns the color code of the account in the format #rrggbb
* @return Color code of the account
* Returns the color of the account.
* @return Color of the account as an int as returned by {@link Color}.
*/
public String getColorHexCode() {
return mColorCode;
public int getColor() {
return mColor;
}

/**
* Sets the color of the account.
* @param color Color as an int as returned by {@link Color}.
* @throws java.lang.IllegalArgumentException if the color is transparent,
* which is not supported.
*/
public void setColor(int color) {
if (Color.alpha(color) < 255)
throw new IllegalArgumentException("Transparent colors are not supported: " + color);
mColor = color;
}

/**
* Sets the color code of the account.
* @param colorCode Color code to be set in the format #rrggbb or #rgb
* @throws java.lang.IllegalArgumentException if the color code is not properly formatted
* Sets the color of the account.
* @param colorCode Color code to be set in the format #rrggbb
* @throws java.lang.IllegalArgumentException if the color code is not properly formatted or
* the color is transparent.
*/
public void setColorCode(String colorCode) {
if (colorCode == null)
return;

if (!Pattern.matches(COLOR_HEX_REGEX, colorCode))
throw new IllegalArgumentException("Invalid color hex code: " + colorCode);

this.mColorCode = colorCode;
//TODO: Allow use of #aarrggbb format as well
public void setColor(@NonNull String colorCode) {
setColor(Color.parseColor(colorCode));
}

/**
Expand All @@ -328,7 +326,7 @@ public void setFavorite(boolean isFavorite) {
}

/**
* @return the mCurrency
* Returns the currency for this account.
*/
public Currency getCurrency() {
return Currency.getInstance(mCurrencyCode);
Expand All @@ -344,7 +342,6 @@ public void setCurrencyCode(String currencyCode){

/**
* Return the commodity for this account
* @return
*/
public Commodity getCommodity(){
return mCommodity;
Expand Down
Loading

0 comments on commit 637cefc

Please sign in to comment.