- holder.selectionCb.setVisibility(selectionActive ? View.VISIBLE : View.GONE);
- holder.selectionCb.setChecked(!acc.isHiddenToBe());
-
- holder.row.setTag(R.id.POS, position);
- }
-
- @NonNull
- @Override
- public LedgerRowHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- View row = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.account_summary_row, parent, false);
- return new LedgerRowHolder(row);
- }
-
- @Override
- public int getItemCount() {
- return Data.accounts.get().size();
- }
- public void startSelection() {
- for (LedgerAccount acc : Data.accounts.get()) acc.setHiddenToBe(acc.isHidden());
- this.selectionActive = true;
- notifyDataSetChanged();
- }
-
- public void stopSelection() {
- this.selectionActive = false;
- notifyDataSetChanged();
- }
-
- public boolean isSelectionActive() {
- return selectionActive;
- }
-
- public void selectItem(int position) {
- LedgerAccount acc = Data.accounts.get().get(position);
- acc.toggleHiddenToBe();
- toggleChildrenOf(acc, acc.isHiddenToBe());
- notifyDataSetChanged();
- }
- void toggleChildrenOf(LedgerAccount parent, boolean hiddenToBe) {
- for (LedgerAccount acc : Data.accounts.get()) {
- String acc_parent = acc.getParentName();
- if ((acc_parent != null) && acc.getParentName().equals(parent.getName())) {
- acc.setHiddenToBe(hiddenToBe);
- toggleChildrenOf(acc, hiddenToBe);
- }
- }
- }