-
- 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;
+ this.accountExpanderContainer =
+ itemView.findViewById(R.id.account_row_amounts_expander_container);
+
+ itemView.setOnLongClickListener(this::onItemLongClick);
+ tvAccountName.setOnLongClickListener(this::onItemLongClick);
+ tvAccountAmounts.setOnLongClickListener(this::onItemLongClick);
+ expanderContainer.setOnLongClickListener(this::onItemLongClick);
+ expander.setOnLongClickListener(this::onItemLongClick);
+ row.setOnLongClickListener(this::onItemLongClick);
+ }
+ private boolean onItemLongClick(View v) {
+ MainActivity activity = (MainActivity) v.getContext();
+ AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ View row;
+ int id = v.getId();
+ switch (id) {
+ case R.id.account_summary_row:
+ row = v;
+ break;
+ case R.id.account_row_acc_amounts:
+ case R.id.account_row_amounts_expander_container:
+ row = (View) v.getParent();
+ break;
+ case R.id.account_row_acc_name:
+ case R.id.account_expander_container:
+ row = (View) v.getParent()
+ .getParent();
+ break;
+ case R.id.account_expander:
+ row = (View) v.getParent()
+ .getParent()
+ .getParent();
+ break;
+ default:
+ Log.e("error",
+ String.format("Don't know how to handle long click on id %d", id));
+ return false;
+ }
+ LedgerAccount acc = (LedgerAccount) 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;