Skip to content

Commit

Permalink
Display book statistics in Book list (BookManager)
Browse files Browse the repository at this point in the history
Fix: crash when switching books due to refresh of non-attached fragment
Fix warning string when creating default accounts to say existing accounts will not be deleted
  • Loading branch information
codinguser committed Aug 17, 2016
1 parent 62242ff commit 9b531e5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
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
12 changes: 11 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<string name="title_all_accounts">All</string>
<string name="summary_create_default_accounts">Creates default GnuCash commonly-used account structure</string>
<string name="title_create_default_accounts">Create default accounts</string>
<string name="msg_confirm_create_default_accounts_setting">All existing accounts and transactions on the device will be deleted.\n\nAre you sure you want to proceed?</string>
<string name="msg_confirm_create_default_accounts_setting">A new book will be opened with the default accounts\n\nYour current accounts and transactions will not be modified!</string>
<string name="menu_scheduled_transactions">Scheduled Transactions</string>
<string name="msg_confirm_create_default_accounts_first_run">Welcome to GnuCash Android! \nYou can either create
a hierarchy of commonly-used accounts, or import your own GnuCash account structure. \n\nBoth options are also
Expand Down Expand Up @@ -457,4 +457,14 @@
<string name="toast_transaction_has_no_splits_and_cannot_open">The selected transaction has no splits and cannot be opened</string>
<string name="label_split_count">%1$d splits</string>
<string name="label_inside_account_with_name">in %1$s</string>

<plurals name="book_account_stats">
<item quantity="one">%d account</item>
<item quantity="other">%d accounts</item>
</plurals>

<plurals name="book_transaction_stats">
<item quantity="one">%d transaction</item>
<item quantity="other">%d transactions</item>
</plurals>
</resources>

0 comments on commit 9b531e5

Please sign in to comment.