Skip to content

Commit

Permalink
Merge branch 'develop' into release/v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
codinguser committed Aug 9, 2016
2 parents 8bd94ed + 1b4ce12 commit cee5600
Show file tree
Hide file tree
Showing 47 changed files with 97 additions and 125 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ Spanti Nicola <rydroid_dev@yahoo.com>
Jesse Shieh <jesse.shieh.pub@gmail.com>
Terry Chung <terrywmc@gmail.com>
Caesar Wirth <cjwirth@gmail.com>
Alceu Rodrigues Neto <alceurneto@gmail.com>
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'io.fabric'
def versionMajor = 2
def versionMinor = 1
def versionPatch = 0
def versionBuild = 1
def versionBuild = 2

def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd HH:mm 'UTC'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,15 @@ public void testMoveTransaction(){
@Test
public void editingSplit_shouldNotSetAmountToZero(){
setDoubleEntryEnabled(true);
setDefaultTransactionType(TransactionType.DEBIT);

mTransactionsDbAdapter.deleteAllRecords();

Account account = new Account("Z Account", Commodity.getInstance(CURRENCY_CODE));
mAccountsDbAdapter.addRecord(account, DatabaseAdapter.UpdateMethod.insert);

//create new transaction "Transaction Acct" --> "Transfer Account"
onView(withId(R.id.fab_create_transaction)).perform(click());

onView(withId(R.id.input_transaction_name)).perform(typeText("Test Split"));
onView(withId(R.id.input_transaction_amount)).perform(typeText("1024"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static BooksDbAdapter getBooksDbAdapter(){
* Loads the book with GUID {@code bookUID}
* @param bookUID GUID of the book to be loaded
*/
public static void loadBook(String bookUID){
public static void loadBook(@NonNull String bookUID){
mBooksDbAdapter.setActive(bookUID);
initDatabaseAdapters();
AccountsActivity.start(getAppContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,23 @@ public Book buildModelInstance(@NonNull Cursor cursor) {

/**
* Sets the book with unique identifier {@code uid} as active and all others as inactive
* <p>If the parameter is null, then the currently active book is not changed</p>
* @param bookUID Unique identifier of the book
* @return GUID of the currently active book
*/
public void setActive(String bookUID){
public String setActive(@NonNull String bookUID){
if (bookUID == null)
return BooksDbAdapter.getInstance().getActiveBookUID();

ContentValues contentValues = new ContentValues();
contentValues.put(BookEntry.COLUMN_ACTIVE, 0);
mDb.update(mTableName, contentValues, null, null); //disable all

contentValues.clear();
contentValues.put(BookEntry.COLUMN_ACTIVE, 1);
mDb.update(mTableName, contentValues, BookEntry.COLUMN_UID + " = ?", new String[]{bookUID});

return bookUID;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,10 @@ private int generateMissedScheduledTransactions(ScheduledAction scheduledAction)
transaction.setTime(lastRuntime);
transaction.setScheduledActionUID(scheduledAction.getUID());
mTransactionList.add(transaction);
//autobalance splits are generated with the currency of the transactions as the GUID
//so we add them to the mAutoBalanceSplits which will be updated to real GUIDs before saving
List<Split> autoBalanceSplits = transaction.getSplits(transaction.getCurrencyCode());
mAutoBalanceSplits.addAll(autoBalanceSplits);
scheduledAction.setExecutionCount(scheduledAction.getExecutionCount() + 1);
++generatedTransactionCount;
break;
Expand Down
28 changes: 12 additions & 16 deletions app/src/main/java/org/gnucash/android/importer/ImportAsyncTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
Expand All @@ -32,14 +32,10 @@

import org.gnucash.android.R;
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.DatabaseHelper;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.adapter.AccountsDbAdapter;
import org.gnucash.android.db.adapter.BooksDbAdapter;
import org.gnucash.android.ui.account.AccountsActivity;
import org.gnucash.android.ui.util.TaskDelegate;

import java.io.File;
import java.io.InputStream;

/**
Expand All @@ -51,6 +47,8 @@ public class ImportAsyncTask extends AsyncTask<Uri, Void, Boolean> {
private TaskDelegate mDelegate;
private ProgressDialog mProgressDialog;

private String mImportedBookUID;

public ImportAsyncTask(Activity context){
this.mContext = context;
}
Expand Down Expand Up @@ -79,10 +77,9 @@ protected void onPreExecute() {

@Override
protected Boolean doInBackground(Uri... uris) {
String bookUID = null;
try {
InputStream accountInputStream = mContext.getContentResolver().openInputStream(uris[0]);
bookUID = GncXmlImporter.parse(accountInputStream);
mImportedBookUID = GncXmlImporter.parse(accountInputStream);

} catch (Exception exception){
Log.e(ImportAsyncTask.class.getName(), "" + exception.getMessage());
Expand All @@ -101,12 +98,6 @@ public void run() {
}
});

//a database is always created at the beginning of import
//if there was an error during import, delete the created database
if (bookUID != null) {
mContext.deleteDatabase(bookUID);
}

return false;
}

Expand All @@ -117,12 +108,16 @@ public void run() {
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseSchema.BookEntry.COLUMN_DISPLAY_NAME, displayName);
contentValues.put(DatabaseSchema.BookEntry.COLUMN_SOURCE_URI, uris[0].toString());
BooksDbAdapter.getInstance().updateRecord(bookUID, contentValues);
BooksDbAdapter.getInstance().updateRecord(mImportedBookUID, contentValues);

cursor.close();
}

((GnuCashApplication)mContext.getApplication()).loadBook(bookUID);
//set the preferences to their default values
mContext.getSharedPreferences(mImportedBookUID, Context.MODE_PRIVATE)
.edit()
.putBoolean(mContext.getString(R.string.key_use_double_entry), true)
.apply();

return true;
}
Expand All @@ -145,6 +140,7 @@ protected void onPostExecute(Boolean importSuccess) {
int message = importSuccess ? R.string.toast_success_importing_accounts : R.string.toast_error_importing_accounts;
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();

AccountsActivity.start(mContext);
if (mImportedBookUID != null)
GnuCashApplication.loadBook(mImportedBookUID);
}
}
2 changes: 0 additions & 2 deletions app/src/main/java/org/gnucash/android/model/BudgetAmount.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import android.os.Parcel;
import android.os.Parcelable;

import org.gnucash.android.app.GnuCashApplication;

import java.math.BigDecimal;

/**
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/org/gnucash/android/model/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.gnucash.android.util.TimestampHelper;


import java.math.BigDecimal;
import java.math.MathContext;
import java.sql.Timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.gnucash.android.model;

import android.support.annotation.NonNull;

import org.joda.time.LocalDate;

import java.sql.Timestamp;
Expand Down Expand Up @@ -430,7 +432,7 @@ public Recurrence getRecurrence() {
* <p>This also sets the start period of the recurrence object, if there is one</p>
* @param recurrence {@link Recurrence} object
*/
public void setRecurrence(Recurrence recurrence) {
public void setRecurrence(@NonNull Recurrence recurrence) {
this.mRecurrence = recurrence;
//if we were parsing XML and parsed the start and end date from the scheduled action first,
//then use those over the values which might be gotten from the recurrence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,32 @@ public class SchedulerService extends IntentService {
public static final String LOG_TAG = "SchedulerService";

/**
* Creates an IntentService
*
* Wake lock for keeping the CPU on while export is in progress
*/
PowerManager.WakeLock mWakeLock;

public SchedulerService() {
super(LOG_TAG);
}

@Override
public void onCreate() {
super.onCreate();
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOG_TAG);
mWakeLock.acquire();
}

@Override
public void onDestroy() {
super.onDestroy();
if (mWakeLock.isHeld())
mWakeLock.release(); //whenever this service is destroyed, release the lock
}

@Override
protected void onHandleIntent(Intent intent) {
Log.i(LOG_TAG, "Starting scheduled action service");
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
LOG_TAG);
wakeLock.acquire();

ScheduledActionDbAdapter scheduledActionDbAdapter = GnuCashApplication.getScheduledEventDbAdapter();
List<ScheduledAction> scheduledActions = scheduledActionDbAdapter.getAllEnabledScheduledActions();
Expand All @@ -87,8 +99,6 @@ protected void onHandleIntent(Intent intent) {
}

Log.i(LOG_TAG, "Completed service @ " + SystemClock.elapsedRealtime());

wakeLock.release();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import android.widget.Spinner;

import org.gnucash.android.R;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.adapter.AccountsDbAdapter;
import org.gnucash.android.db.adapter.CommoditiesDbAdapter;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.adapter.DatabaseAdapter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.AccountType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,11 @@ private void init() {
boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);

if (firstRun){
startActivity(new Intent(this, FirstRunWizardActivity.class));
startActivity(new Intent(GnuCashApplication.getAppContext(), FirstRunWizardActivity.class));

//default to using double entry and save the preference explicitly
prefs.edit().putBoolean(getString(R.string.key_use_double_entry), true).apply();
finish();
} else {
getSDWritePermission();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

import org.gnucash.android.R;
import org.gnucash.android.app.GnuCashApplication;

import org.gnucash.android.db.DatabaseCursorLoader;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.adapter.AccountsDbAdapter;
Expand All @@ -60,10 +59,10 @@
import org.gnucash.android.model.Budget;
import org.gnucash.android.model.Money;
import org.gnucash.android.ui.common.FormActivity;
import org.gnucash.android.ui.common.Refreshable;
import org.gnucash.android.ui.common.UxArgument;
import org.gnucash.android.ui.util.AccountBalanceTask;
import org.gnucash.android.ui.util.CursorRecyclerAdapter;
import org.gnucash.android.ui.common.Refreshable;
import org.gnucash.android.ui.util.widget.EmptyRecyclerView;

import java.util.List;
Expand Down Expand Up @@ -289,6 +288,10 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {


@Override
/**
* Refresh the account list as a sublist of another account
* @param parentAccountUID GUID of the parent account
*/
public void refresh(String parentAccountUID) {
getArguments().putString(UxArgument.PARENT_ACCOUNT_UID, parentAccountUID);
refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

import org.gnucash.android.R;
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.adapter.AccountsDbAdapter;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.adapter.AccountsDbAdapter;
import org.gnucash.android.db.adapter.SplitsDbAdapter;
import org.gnucash.android.db.adapter.TransactionsDbAdapter;
import org.gnucash.android.model.AccountType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.gnucash.android.R;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.adapter.AccountsDbAdapter;
import org.gnucash.android.db.adapter.BudgetsDbAdapter;
import org.gnucash.android.model.BudgetAmount;
import org.gnucash.android.model.Commodity;
import org.gnucash.android.model.Money;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
import org.gnucash.android.model.BudgetAmount;
import org.gnucash.android.model.Money;
import org.gnucash.android.ui.common.FormActivity;
import org.gnucash.android.ui.common.Refreshable;
import org.gnucash.android.ui.common.UxArgument;
import org.gnucash.android.ui.transaction.TransactionsActivity;
import org.gnucash.android.ui.common.Refreshable;
import org.gnucash.android.ui.util.widget.EmptyRecyclerView;

import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.database.Cursor;
import android.inputmethodservice.KeyboardView;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.Fragment;
Expand Down Expand Up @@ -70,8 +69,6 @@
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.IllegalFormatCodePointException;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
import org.gnucash.android.model.BudgetAmount;
import org.gnucash.android.model.Money;
import org.gnucash.android.ui.common.FormActivity;
import org.gnucash.android.ui.common.Refreshable;
import org.gnucash.android.ui.common.UxArgument;
import org.gnucash.android.ui.util.CursorRecyclerAdapter;
import org.gnucash.android.ui.common.Refreshable;
import org.gnucash.android.ui.util.widget.EmptyRecyclerView;

import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;

import org.gnucash.android.R;
Expand All @@ -29,8 +27,6 @@
import org.gnucash.android.ui.common.FormActivity;
import org.gnucash.android.ui.common.UxArgument;

import butterknife.ButterKnife;

/**
* Activity for managing display and editing of budgets
*/
Expand Down
Loading

0 comments on commit cee5600

Please sign in to comment.