Skip to content

Commit 9d0e8a5

Browse files
committed
Merge pull request #161 from fefe982/develop
Fixed: refresh accounts view after exporting and deleting all transactions Fixed: Some more minor leaks and one zh translation error
2 parents 8c95f3b + 5827d61 commit 9d0e8a5

8 files changed

Lines changed: 33 additions & 6 deletions

File tree

app/res/values-zh/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<string name="title_edit_transaction">修改交易</string>
4747
<string name="label_transaction_description">备注</string>
4848
<string name="menu_move">移动</string>
49-
<string name="title_selected">%1$d 已删除</string>
49+
<string name="title_selected">%1$d 已选中</string>
5050
<string name="label_transactions_total">合计:</string>
5151
<string name="label_export_destination">导出到</string>
5252
<string name="title_export_dialog">导出交易资料</string>
@@ -351,7 +351,6 @@
351351
<string name="label_default_transfer_account">默认的转账帐户</string>
352352
<string name="label_account_color_and_type">科目颜色和类型</string>
353353
<plurals name="label_sub_accounts">
354-
<item quantity="one">%d 子科目</item>
355354
<item quantity="other">%d 子科目</item>
356355
</plurals>
357356
<string-array name="account_type_entry_values">

app/src/org/gnucash/android/db/AccountsDbAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public boolean destructiveDeleteAccount(long rowId){
165165
result &= mTransactionsAdapter.deleteRecord(id);
166166
}
167167
result &= deleteRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
168+
c.close();
168169
return result;
169170
}
170171

app/src/org/gnucash/android/export/ExporterTask.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ protected void onPostExecute(Boolean exportResult) {
167167

168168
if (mExportParams.shouldDeleteTransactionsAfterExport()){
169169
android.support.v4.app.FragmentManager fragmentManager = ((FragmentActivity)mContext).getSupportFragmentManager();
170-
Fragment currentFragment = fragmentManager
171-
.findFragmentByTag(AccountsActivity.FRAGMENT_ACCOUNTS_LIST);
170+
Fragment currentFragment = ((AccountsActivity)mContext).getCurrentAccountListFragment();
171+
172172
TransactionsDeleteConfirmationDialogFragment alertFragment =
173173
TransactionsDeleteConfirmationDialogFragment.newInstance(R.string.title_confirm_delete, 0);
174174
alertFragment.setTargetFragment(currentFragment, 0);
@@ -218,6 +218,7 @@ private void writeQifExternalStorage(String qif) throws IOException {
218218
writer.write(qif);
219219

220220
writer.flush();
221+
writer.close();
221222
}
222223

223224
/**

app/src/org/gnucash/android/export/ofx/OfxExporter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public OfxExporter(Context context, boolean exportAll) {
5959
mAccountsList = exportAll ? dbAdapter.getAllAccounts() : dbAdapter.getExportableAccounts();
6060
mExportAll = exportAll;
6161
mContext = context;
62+
dbAdapter.close();
6263
}
6364

6465
/**

app/src/org/gnucash/android/ui/account/AccountFormFragment.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public class AccountFormFragment extends SherlockFragment {
8080
* Accounts database adapter
8181
*/
8282
private AccountsDbAdapter mAccountsDbAdapter;
83+
84+
/**
85+
* Whether the AccountsDbAdapter is created inside this class.
86+
* If so, it should be also closed by this class
87+
*/
88+
private boolean mReleaseDbAdapter = false;
8389

8490
/**
8591
* List of all currency codes (ISO 4217) supported by the app
@@ -191,6 +197,7 @@ public AccountFormFragment() {
191197
static public AccountFormFragment newInstance(AccountsDbAdapter dbAdapter){
192198
AccountFormFragment f = new AccountFormFragment();
193199
f.mAccountsDbAdapter = dbAdapter;
200+
f.mReleaseDbAdapter = false;
194201
return f;
195202
}
196203

@@ -199,6 +206,7 @@ public void onCreate(Bundle savedInstanceState) {
199206
super.onCreate(savedInstanceState);
200207
setHasOptionsMenu(true);
201208
if (mAccountsDbAdapter == null){
209+
mReleaseDbAdapter = true;
202210
mAccountsDbAdapter = new AccountsDbAdapter(getSherlockActivity());
203211
}
204212

@@ -660,8 +668,14 @@ public void onDestroy() {
660668
super.onDestroyView();
661669
if (mParentAccountCursor != null)
662670
mParentAccountCursor.close();
663-
//do not close the database adapter. We got it from the activity,
664-
//the activity will take care of it.
671+
// The mAccountsDbAdapter should only be closed when it is not passed in
672+
// by other Activities.
673+
if (mReleaseDbAdapter == true && mAccountsDbAdapter != null) {
674+
mAccountsDbAdapter.close();
675+
}
676+
if (mDefaultTransferAccountCursorAdapter != null) {
677+
mDefaultTransferAccountCursorAdapter.getCursor().close();
678+
}
665679
}
666680

667681
private void saveAccount() {

app/src/org/gnucash/android/ui/account/AccountsActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ public int getCount() {
205205
}
206206
}
207207

208+
public AccountsListFragment getCurrentAccountListFragment(){
209+
int index = mPager.getCurrentItem();
210+
return (AccountsListFragment)(mFragmentPageReferenceMap.get(index));
211+
}
212+
208213

209214
@Override
210215
public void onCreate(Bundle savedInstanceState) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ private void updateTransferAccountsList(){
420420
+ "' AND " + DatabaseHelper.KEY_PLACEHOLDER + " = 0"
421421
+ ")";
422422

423+
if (mCursor != null) {
424+
mCursor.close();
425+
}
423426
mCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(conditions);
424427

425428
mCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(),
@@ -543,6 +546,8 @@ public void onAccountChanged(long newAccountId){
543546
}
544547

545548
updateTransferAccountsList();
549+
550+
accountsDbAdapter.close();
546551
}
547552

548553
/**

app/src/org/gnucash/android/ui/transaction/dialog/TransactionsDeleteConfirmationDialogFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
6262
} else {
6363
adapter.deleteRecord(rowId);
6464
}
65+
adapter.close();
6566
if (getTargetFragment() instanceof AccountsListFragment){
6667
((AccountsListFragment)getTargetFragment()).refresh();
6768
}

0 commit comments

Comments
 (0)