+ model = ViewModelProviders.of(this).get(AccountSummaryViewModel.class);
+ List<LedgerAccount> accounts = model.getAccounts();
+ modelAdapter = new AccountSummaryAdapter(accounts);
+
+ RecyclerView root = findViewById(R.id.account_root);
+ root.setAdapter(modelAdapter);
+
+ LinearLayoutManager llm = new LinearLayoutManager(this);
+ llm.setOrientation(LinearLayoutManager.VERTICAL);
+ root.setLayoutManager(llm);
+
+ root.addOnItemTouchListener(new RecyclerItemListener(this, root, new RecyclerItemListener.RecyclerTouchListener() {
+ @Override
+ public void onClickItem(View v, int position) {
+ Log.d("list", String.format("item %d clicked", position));
+ if (modelAdapter.isSelectionActive()) {
+ modelAdapter.selectItem(position);
+ }
+ }
+
+ @Override
+ public void onLongClickItem(View v, int position) {
+ Log.d("list", String.format("item %d long-clicked", position));
+ modelAdapter.startSelection();
+ if (optMenu != null) {
+ optMenu.findItem(R.id.menu_acc_summary_cancel_selection).setVisible(true);
+ optMenu.findItem(R.id.menu_acc_summary_confirm_selection).setVisible(true);
+ optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(false);
+ }
+ {
+ FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.btn_add_transaction);
+ if (fab != null) fab.hide();
+ }
+ }
+ }));
+
+ root.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ if (dy < 0) ((FloatingActionButton) findViewById(R.id.btn_add_transaction)).show();
+ if (dy > 0) ((FloatingActionButton) findViewById(R.id.btn_add_transaction)).hide();
+ }
+ });
+ ((SwipeRefreshLayout) findViewById(R.id.account_swiper)).setOnRefreshListener(() -> {
+ Log.d("ui", "refreshing accounts via swipe");
+ update_accounts(true);
+ });