Skip to content

Commit eece627

Browse files
committed
Merge branch 'hotfix/patches'
2 parents dfd54e3 + a3ad8c2 commit eece627

File tree

11 files changed

+598
-38
lines changed

11 files changed

+598
-38
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Change Log
22
===============================================================================
3+
Version 2.0.3 *(2015-11-21)*
4+
----------------------------
5+
* Fixed: Unable to enter decimal amounts in split editor
6+
* Fixed: Split editor shows wrong imbalance when editing transaction
7+
* Fixed: Auto-backups not correctly generated
8+
39
Version 2.0.2 *(2015-11-20)*
410
----------------------------
511
* Fixed: Exporting to external service does not work in some devices

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ apply plugin: 'io.fabric'
55

66
def versionMajor = 2
77
def versionMinor = 0
8-
def versionPatch = 2
9-
def versionBuild = 2
8+
def versionPatch = 3
9+
def versionBuild = 0
1010

1111
def buildTime() {
1212
def df = new SimpleDateFormat("yyyyMMdd HH:mm 'UTC'")

app/src/androidTest/java/org/gnucash/android/test/ui/TransactionsActivityTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,6 @@ public void testDefaultTransactionType(){
380380

381381
onView(withId(R.id.fab_create_transaction)).perform(click());
382382
onView(withId(R.id.input_transaction_type)).check(matches(allOf(isChecked(), withText(R.string.label_spend))));
383-
Espresso.pressBack();
384-
//now validate the other case
385-
386-
setDefaultTransactionType(TransactionType.DEBIT);
387-
388-
onView(withId(R.id.fab_create_transaction)).perform(click());
389-
onView(withId(R.id.input_transaction_type)).check(matches(allOf(not(isChecked()), withText(R.string.label_receive))));
390-
Espresso.pressBack();
391383
}
392384

393385
private void setDefaultTransactionType(TransactionType type) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.database.SQLException;
2525
import android.database.sqlite.SQLiteDatabase;
2626
import android.graphics.Color;
27+
import android.os.Build;
2728
import android.preference.PreferenceManager;
2829
import android.support.annotation.NonNull;
2930
import android.util.Log;
@@ -33,6 +34,7 @@
3334
import com.uservoice.uservoicesdk.Config;
3435
import com.uservoice.uservoicesdk.UserVoice;
3536

37+
import org.gnucash.android.BuildConfig;
3638
import org.gnucash.android.R;
3739
import org.gnucash.android.db.AccountsDbAdapter;
3840
import org.gnucash.android.db.CommoditiesDbAdapter;
@@ -108,6 +110,9 @@ public void onCreate(){
108110
Config config = new Config("gnucash.uservoice.com");
109111
config.setTopicId(107400);
110112
config.setForumId(320493);
113+
config.putUserTrait("app_version_name", BuildConfig.VERSION_NAME);
114+
config.putUserTrait("app_version_code", BuildConfig.VERSION_CODE);
115+
config.putUserTrait("android_version", Build.VERSION.RELEASE);
111116
// config.identifyUser("USER_ID", "User Name", "[email protected]");
112117
UserVoice.init(config, this);
113118

app/src/main/java/org/gnucash/android/export/xml/GncXmlExporter.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,11 @@ private void exportTransactions(XmlSerializer xmlSerializer, boolean exportTempl
360360
ArrayList<String> slotValue = new ArrayList<>();
361361

362362
String notes = cursor.getString(cursor.getColumnIndexOrThrow("trans_notes"));
363-
boolean exported = cursor.getInt(cursor.getColumnIndexOrThrow("trans_exported")) == 1;
364363
if (notes != null && notes.length() > 0) {
365364
slotKey.add(GncXmlHelper.KEY_NOTES);
366365
slotType.add(GncXmlHelper.ATTR_VALUE_STRING);
367366
slotValue.add(notes);
368367
}
369-
if (!exported) {
370-
slotKey.add(GncXmlHelper.KEY_EXPORTED);
371-
slotType.add(GncXmlHelper.ATTR_VALUE_STRING);
372-
slotValue.add("false");
373-
}
374368

375369
String scheduledActionUID = cursor.getString(cursor.getColumnIndexOrThrow("trans_from_sched_action"));
376370
if (scheduledActionUID != null && !scheduledActionUID.isEmpty()){
@@ -826,14 +820,14 @@ public String getExportMimeType(){
826820
*/
827821
public static boolean createBackup(){
828822
try {
829-
new File(BACKUP_FOLDER_PATH).mkdirs();
830823
FileOutputStream fileOutputStream = new FileOutputStream(getBackupFilePath());
831824
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
832825
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(bufferedOutputStream);
833826
OutputStreamWriter writer = new OutputStreamWriter(gzipOutputStream);
834827

835828
ExportParams params = new ExportParams(ExportFormat.XML);
836829
new GncXmlExporter(params).generateExport(writer);
830+
writer.close();
837831
return true;
838832
} catch (IOException | ExporterException e) {
839833
Crashlytics.logException(e);
@@ -849,6 +843,7 @@ public static boolean createBackup(){
849843
* @see #BACKUP_FOLDER_PATH
850844
*/
851845
private static String getBackupFilePath(){
846+
new File(BACKUP_FOLDER_PATH).mkdirs();
852847
return BACKUP_FOLDER_PATH + buildExportFilename(ExportFormat.XML) + ".zip";
853848
}
854849
}

app/src/main/java/org/gnucash/android/importer/ImportAsyncTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ protected Boolean doInBackground(Uri... uris) {
7474
GncXmlImporter.parse(accountInputStream);
7575
} catch (Exception exception){
7676
Log.e(ImportAsyncTask.class.getName(), "" + exception.getMessage());
77+
Crashlytics.log("Could not open: " + uris[0].toString());
7778
Crashlytics.logException(exception);
7879
exception.printStackTrace();
7980

app/src/main/java/org/gnucash/android/ui/common/BaseDrawerActivity.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ public void onConfigurationChanged(Configuration newConfig) {
121121

122122
@Override
123123
public boolean onOptionsItemSelected(MenuItem item) {
124-
if (!mDrawerLayout.isDrawerOpen(mNavigationView))
125-
mDrawerLayout.openDrawer(mNavigationView);
126-
else
127-
mDrawerLayout.closeDrawer(mNavigationView);
124+
if (item.getItemId() == android.R.id.home){
125+
if (!mDrawerLayout.isDrawerOpen(mNavigationView))
126+
mDrawerLayout.openDrawer(mNavigationView);
127+
else
128+
mDrawerLayout.closeDrawer(mNavigationView);
129+
return true;
130+
}
128131

129132
return super.onOptionsItemSelected(item);
130133
}
@@ -133,6 +136,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
133136
* Handler for the navigation drawer items
134137
* */
135138
protected void onDrawerMenuItemClicked(int itemId) {
139+
136140
switch (itemId){
137141
case R.id.nav_item_open: { //Open... files
138142
AccountsActivity.startXmlFileChooser(this);
@@ -148,8 +152,13 @@ protected void onDrawerMenuItemClicked(int itemId) {
148152
}
149153
break;
150154

151-
case R.id.nav_item_reports:
152-
startActivity(new Intent(this, ReportsActivity.class));
155+
case R.id.nav_item_reports: {
156+
if (!(this instanceof AccountsActivity) || !(this instanceof ReportsActivity))
157+
this.finish();
158+
Intent intent = new Intent(this, ReportsActivity.class);
159+
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
160+
startActivity(intent);
161+
}
153162
break;
154163

155164
case R.id.nav_item_scheduled_actions: { //show scheduled transactions
@@ -159,9 +168,8 @@ protected void onDrawerMenuItemClicked(int itemId) {
159168
}
160169
break;
161170

162-
case R.id.nav_item_export:{
171+
case R.id.nav_item_export:
163172
AccountsActivity.openExportFragment(this);
164-
}
165173
break;
166174

167175
case R.id.nav_item_settings: //Settings activity

app/src/main/java/org/gnucash/android/ui/transaction/SplitEditorFragment.java

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.support.v7.app.AppCompatActivity;
2828
import android.text.Editable;
2929
import android.text.TextWatcher;
30+
import android.util.Log;
3031
import android.view.LayoutInflater;
3132
import android.view.Menu;
3233
import android.view.MenuInflater;
@@ -42,6 +43,11 @@
4243
import android.widget.TextView;
4344
import android.widget.Toast;
4445

46+
import com.crashlytics.android.Crashlytics;
47+
48+
import net.objecthunter.exp4j.Expression;
49+
import net.objecthunter.exp4j.ExpressionBuilder;
50+
4551
import org.gnucash.android.R;
4652
import org.gnucash.android.db.AccountsDbAdapter;
4753
import org.gnucash.android.db.CommoditiesDbAdapter;
@@ -140,6 +146,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
140146
if (!splitList.isEmpty()) {
141147
//aha! there are some splits. Let's load those instead
142148
loadSplitViews(splitList);
149+
mImbalanceWatcher.afterTextChanged(null);
143150
} else {
144151
final String currencyCode = mAccountsDbAdapter.getAccountCurrencyCode(mAccountUID);
145152
Split split = new Split(new Money(mBaseAmount.abs(), Commodity.getInstance(currencyCode)), mAccountUID);
@@ -149,9 +156,9 @@ public void onActivityCreated(Bundle savedInstanceState) {
149156
View view = addSplitView(split);
150157
view.findViewById(R.id.input_accounts_spinner).setEnabled(false);
151158
view.findViewById(R.id.btn_remove_split).setVisibility(View.GONE);
159+
TransactionsActivity.displayBalance(mImbalanceTextView, new Money(mBaseAmount.negate(), mCommodity));
152160
}
153161

154-
TransactionsActivity.displayBalance(mImbalanceTextView, new Money(mBaseAmount.negate(), mCommodity));
155162
}
156163

157164
@Override
@@ -287,14 +294,43 @@ public void onClick(View view) {
287294
}
288295

289296
accountsSpinner.setOnItemSelectedListener(new SplitAccountListener(splitTypeSwitch, this));
290-
splitTypeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
297+
splitTypeSwitch.addOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
291298
@Override
292299
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
293300
mImbalanceWatcher.afterTextChanged(null);
294301
}
295302
});
296303
splitAmountEditText.addTextChangedListener(mImbalanceWatcher);
297304
}
305+
306+
/**
307+
* Returns the value of the amount in the splitAmountEditText field without setting the value to the view
308+
* <p>If the expression in the view is currently incomplete or invalid, null is returned.
309+
* This method is used primarily for computing the imbalance</p>
310+
* @return Value in the split item amount field, or {@link BigDecimal#ZERO} if the expression is empty or invalid
311+
*/
312+
public BigDecimal getAmountValue(){
313+
String amountString = splitAmountEditText.getCleanString();
314+
if (amountString.isEmpty())
315+
return BigDecimal.ZERO;
316+
317+
ExpressionBuilder expressionBuilder = new ExpressionBuilder(amountString);
318+
Expression expression;
319+
320+
try {
321+
expression = expressionBuilder.build();
322+
} catch (RuntimeException e) {
323+
return BigDecimal.ZERO;
324+
}
325+
326+
if (expression != null && expression.validate().isValid()) {
327+
return new BigDecimal(expression.evaluate());
328+
} else {
329+
Log.v(SplitEditorFragment.this.getClass().getSimpleName(),
330+
"Incomplete expression for updating imbalance: " + expression);
331+
return BigDecimal.ZERO;
332+
}
333+
}
298334
}
299335

300336
/**
@@ -406,16 +442,12 @@ public void afterTextChanged(Editable editable) {
406442

407443
for (View splitItem : mSplitItemViewList) {
408444
SplitViewHolder viewHolder = (SplitViewHolder) splitItem.getTag();
409-
viewHolder.splitAmountEditText.removeTextChangedListener(this);
410-
BigDecimal amount = viewHolder.splitAmountEditText.getValue();
411-
if (amount != null) {
412-
if (viewHolder.splitTypeSwitch.isChecked()) {
413-
imbalance = imbalance.subtract(amount);
414-
} else {
415-
imbalance = imbalance.add(amount);
416-
}
445+
BigDecimal amount = viewHolder.getAmountValue().abs();
446+
if (viewHolder.splitTypeSwitch.isChecked()) {
447+
imbalance = imbalance.subtract(amount);
448+
} else {
449+
imbalance = imbalance.add(amount);
417450
}
418-
viewHolder.splitAmountEditText.addTextChangedListener(this);
419451
}
420452

421453
TransactionsActivity.displayBalance(mImbalanceTextView, new Money(imbalance.negate(), mCommodity));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ private void initializeViewsWithTransaction(){
456456
//when autocompleting, only change the amount if the user has not manually changed it already
457457
mAmountEditText.setValue(mTransaction.getBalance(mAccountUID).asBigDecimal());
458458
}
459-
mCurrencyTextView.setText(mTransaction.getCurrency().getSymbol(Locale.getDefault()));
459+
mCurrencyTextView.setText(mTransaction.getCurrency().getSymbol());
460460
mNotesEditText.setText(mTransaction.getNote());
461461
mDateTextView.setText(DATE_FORMATTER.format(mTransaction.getTimeMillis()));
462462
mTimeTextView.setText(TIME_FORMATTER.format(mTransaction.getTimeMillis()));

app/src/main/java/org/gnucash/android/ui/util/widget/TransactionTypeSwitch.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.gnucash.android.model.TransactionType;
3030

3131
import java.math.BigDecimal;
32+
import java.util.ArrayList;
33+
import java.util.List;
3234

3335
/**
3436
* A special type of {@link android.widget.ToggleButton} which displays the appropriate CREDIT/DEBIT labels for the
@@ -38,6 +40,8 @@
3840
public class TransactionTypeSwitch extends SwitchCompat {
3941
private AccountType mAccountType = AccountType.EXPENSE;
4042

43+
List<OnCheckedChangeListener> mOnCheckedChangeListeners = new ArrayList<>();
44+
4145
public TransactionTypeSwitch(Context context, AttributeSet attrs, int defStyle) {
4246
super(context, attrs, defStyle);
4347
}
@@ -113,6 +117,14 @@ public void setAmountFormattingListener(CalculatorEditText amoutView, TextView c
113117
setOnCheckedChangeListener(new OnTypeChangedListener(amoutView, currencyTextView));
114118
}
115119

120+
/**
121+
* Add listeners to be notified when the checked status changes
122+
* @param checkedChangeListener Checked change listener
123+
*/
124+
public void addOnCheckedChangeListener(OnCheckedChangeListener checkedChangeListener){
125+
mOnCheckedChangeListeners.add(checkedChangeListener);
126+
}
127+
116128
/**
117129
* Toggles the button checked based on the movement caused by the transaction type for the specified account
118130
* @param transactionType {@link org.gnucash.android.model.TransactionType} of the split
@@ -123,7 +135,7 @@ public void setChecked(TransactionType transactionType){
123135

124136
/**
125137
* Returns the account type associated with this button
126-
* @return
138+
* @return Type of account
127139
*/
128140
public AccountType getAccountType(){
129141
return mAccountType;
@@ -173,6 +185,10 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
173185
}
174186

175187
}
188+
189+
for (OnCheckedChangeListener listener : mOnCheckedChangeListeners) {
190+
listener.onCheckedChanged(compoundButton, isChecked);
191+
}
176192
}
177193
}
178194
}

0 commit comments

Comments
 (0)