Skip to content

Commit 84aba53

Browse files
committed
Fixed: transaction description field does not proceed to next input on clicking "next" (closes #116)
Sorted sub-accounts in alphabetical order Use full qualified account names in WidgetConfigurationActivity dialog Prevent setting an account's parent to one of it's children
1 parent 03ff751 commit 84aba53

4 files changed

Lines changed: 40 additions & 24 deletions

File tree

app/res/layout/fragment_new_transaction.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
android:ems="10"
3535
android:layout_marginBottom="@dimen/dialog_padding"
3636
android:inputType="textCapSentences"
37+
android:imeOptions="actionNext"
38+
android:nextFocusDown="@+id/input_transaction_amount"
3739
style="@style/ListItemText" />
3840

3941
<LinearLayout
@@ -62,6 +64,7 @@
6264
android:layout_marginBottom="@dimen/dialog_padding"
6365
android:hint="@string/label_transaction_amount"
6466
android:inputType="number"
67+
android:nextFocusDown="@+id/input_description"
6568
android:textColor="@color/debit_red"
6669
style="@style/ListItemText" />
6770

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,15 @@ public long getAccountID(String uid){
203203
/**
204204
* Returns the unique ID of the parent account of the account with unique ID <code>uid</code>
205205
* If the account has no parent, null is returned
206-
* @param uid Unique Identifier of account whose parent is to be returned
206+
* @param uid Unique Identifier of account whose parent is to be returned. Should not be null
207207
* @return DB record UID of the parent account, null if the account has no parent
208208
*/
209209
public String getParentAccountUID(String uid){
210210
Cursor cursor = mDb.query(DatabaseHelper.ACCOUNTS_TABLE_NAME,
211211
new String[] {DatabaseHelper.KEY_ROW_ID, DatabaseHelper.KEY_PARENT_ACCOUNT_UID},
212-
DatabaseHelper.KEY_UID + " = '" + uid + "'", null, null, null, null);
212+
DatabaseHelper.KEY_UID + " = ?",
213+
new String[]{uid},
214+
null, null, null, null);
213215
String result = null;
214216
if (cursor != null && cursor.moveToFirst()){
215217
Log.d(TAG, "Account already exists. Returning existing id");
@@ -432,14 +434,15 @@ public Cursor fetchSubAccounts(long accountId){
432434
null,
433435
DatabaseHelper.KEY_PARENT_ACCOUNT_UID + " = ?",
434436
new String[]{getAccountUID(accountId)},
435-
null, null, null);
437+
null, null, DatabaseHelper.KEY_NAME + " ASC");
436438
}
437439

438440
/**
439441
* Returns the top level accounts i.e. accounts with no parent or with the GnuCash ROOT account as parent
440442
* @return Cursor to the top level accounts
441443
*/
442444
public Cursor fetchTopLevelAccounts(){
445+
//condition which selects accounts with no parent, whose UID is not ROOT and whose name is not ROOT
443446
StringBuilder condition = new StringBuilder("(");
444447
condition.append(DatabaseHelper.KEY_PARENT_ACCOUNT_UID + " IS NULL");
445448
condition.append(" OR ");

app/src/org/gnucash/android/ui/accounts/AddAccountFragment.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.actionbarsherlock.view.Menu;
5050
import com.actionbarsherlock.view.MenuInflater;
5151
import com.actionbarsherlock.view.MenuItem;
52+
import org.gnucash.android.util.QualifiedAccountNameCursorAdapter;
5253

5354
/**
5455
* Fragment used for creating and editing accounts
@@ -163,22 +164,23 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
163164
public void onActivityCreated(Bundle savedInstanceState) {
164165
super.onActivityCreated(savedInstanceState);
165166

166-
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
167+
ArrayAdapter<String> currencyArrayAdapter = new ArrayAdapter<String>(
167168
getActivity(),
168169
android.R.layout.simple_spinner_item,
169170
getResources().getStringArray(R.array.currency_names));
170-
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
171-
mCurrencySpinner.setAdapter(arrayAdapter);
172-
173-
loadParentAccountList();
174-
loadAccountTypesList();
171+
currencyArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
172+
mCurrencySpinner.setAdapter(currencyArrayAdapter);
175173

176174
mSelectedAccountId = getArguments().getLong(TransactionsListFragment.SELECTED_ACCOUNT_ID);
177175
if (mSelectedAccountId > 0) {
178176
mAccount = mAccountsDbAdapter.getAccount(mSelectedAccountId);
179177
getSherlockActivity().getSupportActionBar().setTitle(R.string.title_edit_account);
180178
}
181179

180+
//need to load the cursor adapters for the spinners before initializing the views
181+
loadParentAccountList();
182+
loadAccountTypesList();
183+
182184
if (mAccount != null){
183185
initializeViewsWithAccount(mAccount);
184186
} else {
@@ -268,26 +270,38 @@ public boolean onOptionsItemSelected(MenuItem item) {
268270

269271
return false;
270272
}
271-
273+
274+
/**
275+
* Loads the list of possible accounts which can be set as a parent account and initializes the spinner
276+
*/
272277
private void loadParentAccountList(){
273-
String condition = DatabaseHelper.KEY_ROW_ID + "!=" + mSelectedAccountId;
278+
String condition = null;
279+
if (mAccount != null){ //if editing an account
280+
// limit cyclic account hierarchies. Still technically possible since we don't forbid descendant accounts
281+
condition = "(" + DatabaseHelper.KEY_PARENT_ACCOUNT_UID + " IS NULL "
282+
+ " OR " + DatabaseHelper.KEY_PARENT_ACCOUNT_UID + " != '" + mAccount.getUID() + "')"
283+
+ " AND " + DatabaseHelper.KEY_ROW_ID + "!=" + mSelectedAccountId;
284+
//TODO: Limit all descendants of the account to eliminate the possibility of cyclic hierarchy
285+
}
286+
274287
mCursor = mAccountsDbAdapter.fetchAccounts(condition);
275-
if (mCursor.getCount() <= 0){
288+
if (mCursor == null || mCursor.getCount() <= 0){
276289
final View view = getView();
277290
view.findViewById(R.id.layout_parent_account).setVisibility(View.GONE);
278291
view.findViewById(R.id.label_parent_account).setVisibility(View.GONE);
279292
}
280293

281-
String[] from = new String[] {DatabaseHelper.KEY_NAME};
282-
int[] to = new int[] {android.R.id.text1};
283-
mCursorAdapter = new SimpleCursorAdapter(
294+
mCursorAdapter = new QualifiedAccountNameCursorAdapter(
284295
getActivity(),
285296
android.R.layout.simple_spinner_item,
286-
mCursor, from, to, 0);
297+
mCursor);
287298
mCursorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
288299
mParentAccountSpinner.setAdapter(mCursorAdapter);
289300
}
290301

302+
/**
303+
* Loads the list of account types into the account type selector spinner
304+
*/
291305
private void loadAccountTypesList(){
292306
String[] accountTypes = getResources().getStringArray(R.array.account_type_entry_values);
293307
ArrayAdapter<String> accountTypesAdapter = new ArrayAdapter<String>(

app/src/org/gnucash/android/ui/widget/WidgetConfigurationActivity.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import android.widget.RemoteViews;
4747
import android.widget.Spinner;
4848
import android.widget.Toast;
49+
import org.gnucash.android.util.QualifiedAccountNameCursorAdapter;
4950

5051
/**
5152
* Activity for configuration which account to diplay on a widget.
@@ -70,9 +71,7 @@ public void onCreate(Bundle savedInstanceState) {
7071
mAccountsSpinner = (Spinner) findViewById(R.id.input_accounts_spinner);
7172
mOkButton = (Button) findViewById(R.id.btn_save);
7273
mCancelButton = (Button) findViewById(R.id.btn_cancel);
73-
74-
String[] from = new String[] {DatabaseHelper.KEY_NAME};
75-
int[] to = new int[] {android.R.id.text1};
74+
7675
mAccountsDbAdapter = new AccountsDbAdapter(this);
7776
Cursor cursor = mAccountsDbAdapter.fetchAllRecords();
7877

@@ -81,12 +80,9 @@ public void onCreate(Bundle savedInstanceState) {
8180
finish();
8281
}
8382

84-
mCursorAdapter = new SimpleCursorAdapter(this,
83+
mCursorAdapter = new QualifiedAccountNameCursorAdapter(this,
8584
android.R.layout.simple_spinner_item,
86-
cursor,
87-
from,
88-
to,
89-
0);
85+
cursor);
9086
mCursorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
9187
mAccountsSpinner.setAdapter(mCursorAdapter);
9288

0 commit comments

Comments
 (0)