- class LedgerRowHolder extends RecyclerView.ViewHolder {
- CheckBox selectionCb;
- TextView tvAccountName, tvAccountAmounts;
- ConstraintLayout row;
- View vTrailer;
- FrameLayout expanderContainer;
- ImageView expander;
- public LedgerRowHolder(@NonNull View itemView) {
- super(itemView);
- this.row = itemView.findViewById(R.id.account_summary_row);
- this.tvAccountName = itemView.findViewById(R.id.account_row_acc_name);
- this.tvAccountAmounts = itemView.findViewById(R.id.account_row_acc_amounts);
- this.selectionCb = itemView.findViewById(R.id.account_row_check);
- this.vTrailer = itemView.findViewById(R.id.account_summary_trailer);
- this.expanderContainer = itemView.findViewById(R.id.account_expander_container);
- this.expander = itemView.findViewById(R.id.account_expander);
-
- MainActivity activity = (MainActivity) row.getContext();
-
- expanderContainer.addOnLayoutChangeListener(
- (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
- int w = right - left;
- int h = bottom - top;
- if (h > w) {
- int p = (h - w) / 2;
- v.setPadding(0, p, 0, p);
- }
- else v.setPadding(0, 0, 0, 0);
- });
-
- itemView.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- AlertDialog.Builder builder = new AlertDialog.Builder(itemView.getContext());
- LedgerAccount acc =
- (LedgerAccount) v.findViewById(R.id.account_summary_row).getTag();
- builder.setTitle(acc.getName());
- builder.setItems(R.array.acc_ctx_menu, (dialog, which) -> {
- switch(which) {
- case 0:
- // show transactions
- activity.showAccountTransactions(acc);
- break;
- }
- dialog.dismiss();
- });
- builder.show();
- return true;
+ account.toggleAmountsExpanded();
+ if (account.amountsExpanded()) {
+ b.accountRowAccAmounts.setText(account.getAmountsString());
+ b.accountRowAmountsExpanderContainer.setVisibility(View.GONE);
+ }
+ else {
+ b.accountRowAccAmounts.setText(account.getAmountsString(AMOUNT_LIMIT));
+ b.accountRowAmountsExpanderContainer.setVisibility(View.VISIBLE);
+ }
+
+ AsyncTask.execute(() -> {
+ Account dbo = account.toDBO();
+ DB.get()
+ .getAccountDAO()
+ .updateSync(dbo);
+ });
+ }
+ private boolean onItemLongClick(View v) {
+ MainActivity activity = (MainActivity) v.getContext();
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ final String accountName = getAccount().getName();
+ builder.setTitle(accountName);
+ builder.setItems(R.array.acc_ctx_menu, (dialog, which) -> {
+ if (which == 0) {// show transactions
+ activity.showAccountTransactions(accountName);