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 17, 2016
2 parents 7b345af + bc9159c commit a1076dd
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 238 deletions.
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 = 3
def versionBuild = 4

def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd HH:mm 'UTC'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public void testDeleteAccountMovingSubaccounts() {
withId(R.id.options_menu))).perform(click());
onView(withText(R.string.menu_delete)).perform(click());

//// FIXME: 17.08.2016 This enabled check fails during some test runs - not reliable, investigate why
onView(allOf(withParent(withId(R.id.accounts_options)),
withId(R.id.radio_move))).check(matches(isEnabled())).perform(click());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.text.TextUtils;
import android.util.Log;

import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.DatabaseSchema;
import org.gnucash.android.db.DatabaseSchema.AccountEntry;
import org.gnucash.android.db.DatabaseSchema.CommonColumns;
Expand Down Expand Up @@ -711,6 +712,19 @@ public boolean deleteRecord(@NonNull String uid){
return deleteRecord(getID(uid));
}

/**
* Deletes a book - removes the book record from the database and deletes the database file from the disk
* @param bookUID GUID of the book
* @return <code>true</code> if deletion was successful, <code>false</code> otherwise
* @see #deleteRecord(String)
*/
public boolean deleteBook(@NonNull String bookUID){
boolean result = GnuCashApplication.getAppContext().deleteDatabase(bookUID);
if (result) //delete the db entry only if the file deletion was successful
result &= deleteRecord(bookUID);
return result;
}

/**
* Returns an attribute from a specific column in the database for a specific record.
* <p>The attribute is returned as a string which can then be converted to another type if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ public void run() {

@Override
protected void onPostExecute(Boolean importSuccess) {
if (mDelegate != null)
mDelegate.onTaskComplete();

try {
if (mProgressDialog != null && mProgressDialog.isShowing())
mProgressDialog.dismiss();
Expand All @@ -142,5 +139,8 @@ protected void onPostExecute(Boolean importSuccess) {

if (mImportedBookUID != null)
GnuCashApplication.loadBook(mImportedBookUID);

if (mDelegate != null)
mDelegate.onTaskComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ protected void onNewIntent(Intent intent) {
setIntent(intent);
setCurrentTab();

getCurrentAccountListFragment().refresh();
int index = mViewPager.getCurrentItem();
Fragment fragment = (Fragment) mFragmentPageReferenceMap.get(index);
if (fragment != null)
((Refreshable)fragment).refresh();

handleOpenFileIntent(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@ public void refresh(String parentAccountUID) {
*/
@Override
public void refresh() {
if (!isDetached()) {
getLoaderManager().restartLoader(0, null, this);
}
getLoaderManager().restartLoader(0, null, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
Expand All @@ -43,8 +44,12 @@
import org.gnucash.android.R;
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.DatabaseCursorLoader;
import org.gnucash.android.db.DatabaseHelper;
import org.gnucash.android.db.DatabaseSchema.BookEntry;
import org.gnucash.android.db.adapter.AccountsDbAdapter;
import org.gnucash.android.db.adapter.BooksDbAdapter;
import org.gnucash.android.db.adapter.SplitsDbAdapter;
import org.gnucash.android.db.adapter.TransactionsDbAdapter;
import org.gnucash.android.ui.account.AccountsActivity;
import org.gnucash.android.ui.common.Refreshable;
import org.gnucash.android.util.PreferencesHelper;
Expand Down Expand Up @@ -159,8 +164,22 @@ public void bindView(View view, final Context context, Cursor cursor) {

TextView labelLastSync = (TextView) view.findViewById(R.id.label_last_sync);
labelLastSync.setText(R.string.label_last_export_time);
ImageView optionsMenu = (ImageView) view.findViewById(R.id.options_menu);

//retrieve some book statistics
DatabaseHelper dbHelper = new DatabaseHelper(GnuCashApplication.getAppContext(), bookUID);
SQLiteDatabase db = dbHelper.getReadableDatabase();
TransactionsDbAdapter trnAdapter = new TransactionsDbAdapter(db, new SplitsDbAdapter(db));
int transactionCount = (int) trnAdapter.getRecordsCount();
String transactionStats = getResources().getQuantityString(R.plurals.book_transaction_stats, transactionCount, transactionCount);

AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(db, trnAdapter);
int accountsCount = (int) accountsDbAdapter.getRecordsCount();
String accountStats = getResources().getQuantityString(R.plurals.book_account_stats, accountsCount, accountsCount);
String stats = accountStats + ", " + transactionStats;
TextView statsText = (TextView) view.findViewById(R.id.secondary_text);
statsText.setText(stats);

ImageView optionsMenu = (ImageView) view.findViewById(R.id.options_menu);
optionsMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -199,8 +218,7 @@ public void onClick(View v) {
dialogBuilder.setPositiveButton(getString(R.string.btn_delete_book), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
BooksDbAdapter.getInstance().deleteRecord(bookUID);
mContext.deleteDatabase(bookUID);
BooksDbAdapter.getInstance().deleteBook(bookUID);
refresh();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void createAccountsAndFinish() {
//save the UID of the active book, and then delete it after successful import
String bookUID = BooksDbAdapter.getInstance().getActiveBookUID();
AccountsActivity.createDefaultAccounts(mCurrencyCode, FirstRunWizardActivity.this);
BooksDbAdapter.getInstance().deleteRecord(bookUID); //a default book is usually created
BooksDbAdapter.getInstance().deleteBook(bookUID); //a default book is usually created
finish();
} else if (mAccountOptions.equals(getString(R.string.wizard_option_import_my_accounts))){
AccountsActivity.startXmlFileChooser(this);
Expand Down
Loading

0 comments on commit a1076dd

Please sign in to comment.