32
32
import android .support .v4 .view .MenuItemCompat ;
33
33
import android .support .v7 .app .ActionBar ;
34
34
import android .support .v7 .app .AppCompatActivity ;
35
- import android .support .v7 .preference .PreferenceManager ;
36
35
import android .support .v7 .widget .GridLayoutManager ;
37
36
import android .support .v7 .widget .LinearLayoutManager ;
38
37
import android .support .v7 .widget .PopupMenu ;
@@ -484,27 +483,39 @@ public AccountViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
484
483
485
484
@ Override
486
485
public void onBindViewHolderCursor (final AccountViewHolder holder , final Cursor cursor ) {
486
+
487
487
final String accountUID = cursor .getString (cursor .getColumnIndexOrThrow (DatabaseSchema .AccountEntry .COLUMN_UID ));
488
+
488
489
mAccountsDbAdapter = AccountsDbAdapter .getInstance ();
489
- holder .accoundId = mAccountsDbAdapter .getID (accountUID );
490
490
491
+ holder .accoundId = mAccountsDbAdapter .getID (accountUID );
491
492
holder .accountName .setText (cursor .getString (cursor .getColumnIndexOrThrow (DatabaseSchema .AccountEntry .COLUMN_NAME )));
493
+
492
494
int subAccountCount = mAccountsDbAdapter .getSubAccountCount (accountUID );
495
+
493
496
if (subAccountCount > 0 ) {
494
497
holder .description .setVisibility (View .VISIBLE );
495
- String text = getResources ().getQuantityString (R .plurals .label_sub_accounts , subAccountCount , subAccountCount );
498
+ String text = getResources ().getQuantityString (R .plurals .label_sub_accounts ,
499
+ subAccountCount ,
500
+ subAccountCount );
496
501
holder .description .setText (text );
497
- } else
502
+
503
+ } else {
498
504
holder .description .setVisibility (View .GONE );
505
+ }
499
506
500
507
// add a summary of transactions to the account view
501
508
502
- // Make sure the balance task is truly multithread
509
+ // Make sure the balance task is truly multithread
503
510
new AccountBalanceTask (holder .accountBalance ).executeOnExecutor (AsyncTask .THREAD_POOL_EXECUTOR ,
504
- accountUID );
511
+ accountUID );
505
512
506
513
String accountColor = cursor .getString (cursor .getColumnIndexOrThrow (DatabaseSchema .AccountEntry .COLUMN_COLOR_CODE ));
507
- int colorCode = accountColor == null ? Color .TRANSPARENT : Color .parseColor (accountColor );
514
+
515
+ int colorCode = accountColor == null
516
+ ? Color .TRANSPARENT
517
+ : Color .parseColor (accountColor );
518
+
508
519
holder .colorStripView .setBackgroundColor (colorCode );
509
520
510
521
boolean isPlaceholderAccount = mAccountsDbAdapter .isPlaceholderAccount (accountUID );
@@ -515,21 +526,30 @@ public void onBindViewHolderCursor(final AccountViewHolder holder, final Cursor
515
526
516
527
@ Override
517
528
public void onClick (View v ) {
518
- Intent intent = new Intent (getActivity (), FormActivity .class );
529
+
530
+ Intent intent = new Intent (getActivity (),
531
+ FormActivity .class );
519
532
intent .setAction (Intent .ACTION_INSERT_OR_EDIT );
520
- intent .putExtra (UxArgument .SELECTED_ACCOUNT_UID , accountUID );
521
- intent .putExtra (UxArgument .FORM_TYPE , FormActivity .FormType .TRANSACTION .name ());
533
+ intent .putExtra (UxArgument .SELECTED_ACCOUNT_UID ,
534
+ accountUID );
535
+ intent .putExtra (UxArgument .FORM_TYPE ,
536
+ FormActivity .FormType .TRANSACTION .name ());
522
537
getActivity ().startActivity (intent );
523
538
}
524
539
});
525
540
}
526
541
527
- List <Budget > budgets = BudgetsDbAdapter .getInstance ().getAccountBudgets (accountUID );
542
+ List <Budget > budgets = BudgetsDbAdapter .getInstance ()
543
+ .getAccountBudgets (accountUID );
528
544
//TODO: include fetch only active budgets
529
- if (budgets .size () == 1 ){
530
- Budget budget = budgets .get (0 );
531
- Money balance = mAccountsDbAdapter .getAccountBalance (accountUID , budget .getStartofCurrentPeriod (), budget .getEndOfCurrentPeriod ());
532
- double budgetProgress = balance .divide (budget .getAmount (accountUID )).asBigDecimal ().doubleValue () * 100 ;
545
+ if (budgets .size () == 1 ) {
546
+ Budget budget = budgets .get (0 );
547
+ Money balance = mAccountsDbAdapter .getAccountBalance (accountUID ,
548
+ budget .getStartofCurrentPeriod (),
549
+ budget .getEndOfCurrentPeriod ());
550
+ double budgetProgress = balance .divide (budget .getAmount (accountUID ))
551
+ .asBigDecimal ()
552
+ .doubleValue () * 100 ;
533
553
534
554
holder .budgetIndicator .setVisibility (View .VISIBLE );
535
555
holder .budgetIndicator .setProgress ((int ) budgetProgress );
@@ -538,7 +558,7 @@ public void onClick(View v) {
538
558
}
539
559
540
560
541
- if (mAccountsDbAdapter .isFavoriteAccount (accountUID )){
561
+ if (mAccountsDbAdapter .isFavoriteAccount (accountUID )) {
542
562
holder .favoriteStatus .setImageResource (R .drawable .ic_star_black_24dp );
543
563
} else {
544
564
holder .favoriteStatus .setImageResource (R .drawable .ic_star_border_black_24dp );
@@ -547,23 +567,29 @@ public void onClick(View v) {
547
567
holder .favoriteStatus .setOnClickListener (new View .OnClickListener () {
548
568
@ Override
549
569
public void onClick (View v ) {
570
+
550
571
boolean isFavoriteAccount = mAccountsDbAdapter .isFavoriteAccount (accountUID );
551
572
552
573
ContentValues contentValues = new ContentValues ();
553
- contentValues .put (DatabaseSchema .AccountEntry .COLUMN_FAVORITE , !isFavoriteAccount );
554
- mAccountsDbAdapter .updateRecord (accountUID , contentValues );
555
-
556
- int drawableResource = !isFavoriteAccount ?
557
- R .drawable .ic_star_black_24dp : R .drawable .ic_star_border_black_24dp ;
574
+ contentValues .put (DatabaseSchema .AccountEntry .COLUMN_FAVORITE ,
575
+ !isFavoriteAccount );
576
+ mAccountsDbAdapter .updateRecord (accountUID ,
577
+ contentValues );
578
+
579
+ int drawableResource = !isFavoriteAccount
580
+ ? R .drawable .ic_star_black_24dp
581
+ : R .drawable .ic_star_border_black_24dp ;
558
582
holder .favoriteStatus .setImageResource (drawableResource );
559
- if (mDisplayMode == DisplayMode .FAVORITES )
583
+ if (mDisplayMode == DisplayMode .FAVORITES ) {
560
584
refresh ();
585
+ }
561
586
}
562
587
});
563
588
564
589
holder .itemView .setOnClickListener (new View .OnClickListener () {
565
590
@ Override
566
591
public void onClick (View v ) {
592
+
567
593
onListItemClick (accountUID );
568
594
}
569
595
});
0 commit comments