+
+ swiper = mActivity.findViewById(R.id.transaction_swipe);
+ if (swiper == null) throw new RuntimeException("Can't get hold on the swipe layout");
+ root = mActivity.findViewById(R.id.transaction_root);
+ if (root == null)
+ throw new RuntimeException("Can't get hold on the transaction value view");
+ modelAdapter = new TransactionListAdapter();
+ root.setAdapter(modelAdapter);
+
+ FloatingActionButton fab = mActivity.findViewById(R.id.btn_add_transaction);
+
+ mActivity.fabShouldShow();
+ root.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ if (dy < 0) mActivity.fabShouldShow();
+ if (dy > 0) fab.hide();
+ }
+ });
+
+ LinearLayoutManager llm = new LinearLayoutManager(mActivity);
+
+ llm.setOrientation(LinearLayoutManager.VERTICAL);
+ root.setLayoutManager(llm);
+
+ swiper.setOnRefreshListener(() -> {
+ debug("ui", "refreshing transactions via swipe");
+ mActivity.scheduleTransactionListRetrieval();
+ });
+
+ Colors.themeWatch.observe(this, this::themeChanged);
+ swiper.setColorSchemeColors(Colors.primary);
+
+ vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter);
+ accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name);
+
+ MLDB.hookAutocompletionAdapter(mActivity, accNameFilter, "accounts", "name", true);
+ accNameFilter.setOnItemClickListener((parent, view, position, id) -> {
+// debug("tmp", "direct onItemClick");
+ MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position);
+ Data.accountFilter.setValue(mc.getString(1));
+ Globals.hideSoftKeyboard(mActivity);
+ });
+
+ Data.accountFilter.observe(this, this::onAccountNameFilterChanged);
+
+ TransactionListViewModel.updating.addObserver(
+ (o, arg) -> swiper.setRefreshing(TransactionListViewModel.updating.get()));
+ TransactionListViewModel.updateError.addObserver((o, arg) -> {
+ String err = TransactionListViewModel.updateError.get();
+ if (err == null) return;
+
+ Toast.makeText(mActivity, err, Toast.LENGTH_SHORT).show();
+ TransactionListViewModel.updateError.set(null);
+ });
+ Data.transactions.addObserver(
+ (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
+
+ mActivity.findViewById(R.id.clearAccountNameFilter).setOnClickListener(v -> {
+ Data.accountFilter.setValue(null);
+ vAccountFilter.setVisibility(View.GONE);
+ menuTransactionListFilter.setVisible(true);
+ Globals.hideSoftKeyboard(mActivity);
+ });
+ }
+ private void onAccountNameFilterChanged(String accName) {
+ final String fieldText = accNameFilter.getText().toString();
+ if ((accName == null) && (fieldText.equals(""))) return;
+
+ if (accNameFilter != null) {
+ accNameFilter.setText(accName, false);
+ }
+ final boolean filterActive = (accName != null) && !accName.isEmpty();
+ if (vAccountFilter != null) {
+ vAccountFilter.setVisibility(filterActive ? View.VISIBLE : View.GONE);
+ }
+ if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(!filterActive);
+
+ TransactionListViewModel.scheduleTransactionListReload();
+