Skip to content

Commit

Permalink
Merge branch 'hotfix/patches' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
codinguser committed Jul 8, 2015
2 parents 66a8144 + 55a1f50 commit 154b540
Show file tree
Hide file tree
Showing 34 changed files with 165 additions and 89 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Change Log
===============================================================================
Version 1.6.1 *(2015-07-08)*
----------------------------
* Fixed: Crash when importing some scheduled transations with custom period strings
* Fixed: Crash when closing export progress dialog if an export error occurred
* Fixed: Crash when creating a sub-account and changing the account type
* Fixed: Crash when loading backup files with no timestamp in their name
* Fixed: Crash when app is run on devices with locale es_LG
* Improved: Updated betterpickers library
* Improved: New dialogs for time and date when creating transactions
* Improved: Added translation to Ukrainian

Version 1.6.0 *(2015-06-20)*
----------------------------
* Feature: Scheduled backups (QIF, OFX and XML)
Expand Down
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ apply plugin: 'crashlytics'

def versionMajor = 1
def versionMinor = 6
def versionPatch = 0
def versionBuild = 7
def versionPatch = 1
def versionBuild = 0

def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd")
Expand Down Expand Up @@ -100,13 +100,13 @@ android {
applicationId 'org.gnucash.android.devel'
testApplicationId 'org.gnucash.android.devel.test'
resValue "string", "app_name", "GnuCash-devel"
versionName "${versionMajor}.${versionMinor}.${versionPatch}-dev${versionBuild}_${buildTime()}"
versionName "${versionMajor}.${versionMinor}.${versionPatch}-dev${versionBuild}_r${gitSha()}"
resValue "string", "app_version_name", "${versionName}"
}

beta {
resValue "string", "app_name", "GnuCash - beta"
versionName "${versionMajor}.${versionMinor}.${versionPatch}-beta${versionBuild}_r${gitSha()}"
versionName "${versionMajor}.${versionMinor}.${versionPatch}-beta${versionBuild}"
resValue "string", "app_version_name", "${versionName}"
buildConfigField "boolean", "USE_CRASHLYTICS", "true"
}
Expand Down Expand Up @@ -154,7 +154,7 @@ dependencies {
compile('com.android.support:support-v4:22.1.1',
'com.actionbarsherlock:actionbarsherlock:4.4.0@aar',
'com.viewpagerindicator:library:2.4.1@aar',
'com.doomonafireball.betterpickers:library:1.5.2',
'com.doomonafireball.betterpickers:library:1.6.0',
'com.commonsware.cwac:merge:1.1.+',
'com.github.PhilJay:MPAndroidChart:v2.1.0',
'joda-time:joda-time:2.7',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.gnucash.android.db.SplitsDbAdapter;
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.AccountType;
import org.gnucash.android.model.Money;
import org.gnucash.android.receivers.AccountCreator;
import org.gnucash.android.ui.account.AccountsActivity;
Expand All @@ -47,19 +48,24 @@
import java.util.Currency;
import java.util.List;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.action.ViewActions.swipeRight;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

@RunWith(AndroidJUnit4.class)
Expand Down Expand Up @@ -213,6 +219,31 @@ public void testChangeParentAccount() {
assertThat(DUMMY_ACCOUNT_UID).isEqualTo(parentUID);
}

/**
* When creating a sub-account (starting from within another account), if we change the account
* type to another type with no accounts of that type, then the parent account list should be hidden.
* The account which is then created is not a sub-account, but rather a top-level account
*/
@Test
public void shouldHideParentAccountViewWhenNoParentsExist(){
onView(withText(DUMMY_ACCOUNT_NAME)).perform(click());
onView(withId(R.id.fragment_transaction_list)).perform(swipeRight());
onView(withText(R.string.label_create_account)).check(matches(isDisplayed())).perform(click());
sleep(1000);
onView(withId(R.id.checkbox_parent_account)).check(matches(allOf(isChecked())));
onView(withId(R.id.input_account_name)).perform(typeText("Trading account"));
onView(withId(R.id.input_account_type_spinner)).perform(click());
onData(allOf(is(instanceOf(String.class)), is(AccountType.TRADING.name()))).perform(click());

onView(withId(R.id.layout_parent_account)).check(matches(not(isDisplayed())));
onView(withId(R.id.menu_save)).perform(click());

//no sub-accounts
assertThat(mAccountsDbAdapter.getSubAccountCount(DUMMY_ACCOUNT_UID)).isEqualTo(0);
assertThat(mAccountsDbAdapter.getSubAccountCount(mAccountsDbAdapter.getOrCreateGnuCashRootAccountUID())).isEqualTo(2);
assertThat(mAccountsDbAdapter.getSimpleAccountList()).extracting("mAccountType").contains(AccountType.TRADING);
}

@Test
public void testEditAccount(){
String editedAccountName = "Edited Account";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.gnucash.android.test.ui;

import android.app.Fragment;
import android.content.ContentValues;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -28,8 +27,6 @@
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.Spinner;

import org.gnucash.android.R;
import org.gnucash.android.db.AccountsDbAdapter;
Expand Down Expand Up @@ -58,7 +55,6 @@
import java.util.List;
import java.util.Locale;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.clearText;
import static android.support.test.espresso.action.ViewActions.click;
Expand All @@ -69,15 +65,10 @@
import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
import static android.support.test.espresso.matcher.ViewMatchers.isChecked;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked;
import static android.support.test.espresso.matcher.ViewMatchers.withChild;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withSpinnerText;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.assertj.android.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

Expand Down Expand Up @@ -191,14 +182,26 @@ public void testAddTransactionShouldRequireAmount(){
.perform(typeText("Lunch"));

onView(withId(R.id.menu_save)).perform(click());

sleep(500);
assertToastDisplayed(R.string.toast_transanction_amount_required);

int afterCount = mTransactionsDbAdapter.getTransactionsCount(DUMMY_ACCOUNT_UID);
assertThat(afterCount).isEqualTo(beforeCount);

}

/**
* Sleep the thread for a specified period
* @param millis Duration to sleep in milliseconds
*/
private void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

/**
* Checks that a specific toast message is displayed
* @param toastString
Expand All @@ -219,7 +222,8 @@ private void validateEditTransactionFields(Transaction transaction){
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
onView(withId(R.id.input_transaction_amount)).check(matches(withText(formatter.format(balance.asDouble()))));

onView(withId(R.id.input_date)).check(matches(withText(TransactionFormFragment.DATE_FORMATTER.format(transaction.getTimeMillis()))));
onView(withId(R.id.input_time)).check(matches(withText(TransactionFormFragment.TIME_FORMATTER.format(transaction.getTimeMillis()))));
onView(withId(R.id.input_description)).check(matches(withText(transaction.getNote())));

validateTimeInput(transaction.getTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,18 @@ public static boolean shouldSaveOpeningBalances(boolean defaultValue){
*
* @return Default currency code string for the application
*/
public static String getDefaultCurrency(){
public static String getDefaultCurrencyCode(){
Locale locale = Locale.getDefault();
//sometimes the locale en_UK is returned which causes a crash with Currency
if (locale.getCountry().equals("UK")) {
locale = new Locale(locale.getLanguage(), "GB");
}

//for unsupported locale es_LG
if (locale.getCountry().equals("LG")){
locale = new Locale(locale.getLanguage(), "ES");
}

String currencyCode = "USD"; //start with USD as the default
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
try { //there are some strange locales out there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ private Money computeBalance(String accountUID, long startTimestamp, long endTim
* @return the absolute balance of account list
*/
public Money getAccountsBalance(List<String> accountUIDList, long startTimestamp, long endTimestamp) {
String currencyCode = GnuCashApplication.getDefaultCurrency();
String currencyCode = GnuCashApplication.getDefaultCurrencyCode();
Money balance = Money.createZeroInstance(currencyCode);

SplitsDbAdapter splitsDbAdapter = SplitsDbAdapter.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public long getID(@NonNull String uid){
* Returns the string unique ID (GUID) of a record in the database
* @param id long database record ID
* @return GUID of the record
* @throws IllegalArgumentException if the record ID does not exist in the database
*/
public String getUID(long id){
Cursor cursor = mDb.query(mTableName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.gnucash.android.export.xml.GncXmlExporter;
import org.gnucash.android.model.Transaction;
import org.gnucash.android.ui.account.AccountsActivity;
import org.gnucash.android.ui.account.AccountsListFragment;
import org.gnucash.android.ui.settings.SettingsActivity;
import org.gnucash.android.ui.transaction.TransactionsActivity;

Expand Down Expand Up @@ -233,7 +234,9 @@ protected void onPostExecute(Boolean exportResult) {

//now refresh the respective views
if (mContext instanceof AccountsActivity){
((AccountsActivity) mContext).getCurrentAccountListFragment().refresh();
AccountsListFragment fragment = ((AccountsActivity) mContext).getCurrentAccountListFragment();
if (fragment != null)
fragment.refresh();
}
if (mContext instanceof TransactionsActivity){
((TransactionsActivity) mContext).refresh();
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/gnucash/android/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public static String buildExportFilename(ExportFormat format) {
public static long getExportTime(String filename){
String[] tokens = filename.split("_");
long timeMillis = 0;
if (tokens.length < 2){
return timeMillis;
}
try {
Date date = EXPORT_FILENAME_DATE_FORMAT.parse(tokens[0] + "_" + tokens[1]);
timeMillis = date.getTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ protected void onPostExecute(Boolean importSuccess) {
if (mDelegate != null)
mDelegate.onTaskComplete();

if (progressDialog != null && progressDialog.isShowing())
progressDialog.dismiss();
try {
if (progressDialog != null && progressDialog.isShowing())
progressDialog.dismiss();
} catch (IllegalArgumentException ex){
//TODO: This is a hack to catch "View not attached to window" exceptions
//FIXME by moving the creation and display of the progress dialog to the Fragment
} finally {
progressDialog = null;
}

int message = importSuccess ? R.string.toast_success_importing_accounts : R.string.toast_error_importing_accounts;
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/gnucash/android/model/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import com.crashlytics.android.Crashlytics;

import org.gnucash.android.app.GnuCashApplication;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
Expand Down Expand Up @@ -90,7 +92,7 @@ public final class Money implements Comparable<Money>{
* A zero instance with the currency of the default locale.
* This can be used anywhere where a starting amount is required without having to create a new object
*/
private static final Money sDefaultZero = Money.createZeroInstance(Currency.getInstance(Locale.getDefault()).getCurrencyCode());
private static final Money sDefaultZero = Money.createZeroInstance(GnuCashApplication.getDefaultCurrencyCode());

/**
* Returns a Money instance initialized to the local currency and value 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new_account, container, false);
getSherlockActivity().getSupportActionBar().setTitle(R.string.title_add_account);
getSherlockActivity().getSupportActionBar().setTitle(R.string.label_create_account);
mCurrencySpinner = (Spinner) view.findViewById(R.id.input_currency_spinner);
mNameEditText = (EditText) view.findViewById(R.id.input_account_name);
//mNameEditText.requestFocus();
Expand Down Expand Up @@ -443,14 +443,14 @@ private void setSelectedCurrency(String currencyCode){
* @param parentAccountId Record ID of parent account to be selected
*/
private void setParentAccountSelection(long parentAccountId){
if (parentAccountId > 0 && parentAccountId != mRootAccountId){
mParentCheckBox.setChecked(true);
mParentAccountSpinner.setEnabled(true);
} else
if (parentAccountId <= 0 || parentAccountId == mRootAccountId) {
return;
}

for (int pos = 0; pos < mParentAccountCursorAdapter.getCount(); pos++) {
if (mParentAccountCursorAdapter.getItemId(pos) == parentAccountId){
mParentCheckBox.setChecked(true);
mParentAccountSpinner.setEnabled(true);
mParentAccountSpinner.setSelection(pos, true);
break;
}
Expand Down Expand Up @@ -581,11 +581,15 @@ private void loadParentAccountList(AccountType accountType){
mParentAccountCursor.close();

mParentAccountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(condition, null);
if (mParentAccountCursor.getCount() <= 0){
final View view = getView();
assert view != null;
final View view = getView();
assert view != null;
if (mParentAccountCursor.getCount() <= 0){
mParentCheckBox.setChecked(false); //disable before hiding, else we can still read it when saving
view.findViewById(R.id.layout_parent_account).setVisibility(View.GONE);
view.findViewById(R.id.label_parent_account).setVisibility(View.GONE);
} else {
view.findViewById(R.id.layout_parent_account).setVisibility(View.VISIBLE);
view.findViewById(R.id.label_parent_account).setVisibility(View.VISIBLE);
}

mParentAccountCursorAdapter = new QualifiedAccountNameCursorAdapter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void setTab(int index){
private void init() {
PreferenceManager.setDefaultValues(this, R.xml.fragment_transaction_preferences, false);

Money.DEFAULT_CURRENCY_CODE = GnuCashApplication.getDefaultCurrency();
Money.DEFAULT_CURRENCY_CODE = GnuCashApplication.getDefaultCurrencyCode();

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.actionbarsherlock.app.SherlockPreferenceActivity;

import org.gnucash.android.R;
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.ui.UxArgument;
import org.gnucash.android.ui.passcode.PasscodeLockScreenActivity;
import org.gnucash.android.ui.passcode.PasscodePreferenceActivity;
Expand Down Expand Up @@ -108,6 +109,10 @@ public boolean onPreferenceClick(Preference preference) {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (mEditor == null){
mEditor = PreferenceManager.getDefaultSharedPreferences(GnuCashApplication.getAppContext()).edit();
}

switch (requestCode) {
case PASSCODE_REQUEST_CODE:
if (resultCode == Activity.RESULT_OK && data != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,10 @@ public void restoreBackup() {
final DateFormat dateFormatter = SimpleDateFormat.getDateTimeInstance();
for (File backupFile : sortedBackupFiles) {
long time = Exporter.getExportTime(backupFile.getName());
arrayAdapter.add(dateFormatter.format(new Date(time)));
if (time > 0)
arrayAdapter.add(dateFormatter.format(new Date(time)));
else //if no timestamp was found in the filename, just use the name
arrayAdapter.add(backupFile.getName());
}

AlertDialog.Builder restoreDialogBuilder = new AlertDialog.Builder(this);
Expand Down
Loading

0 comments on commit 154b540

Please sign in to comment.