+
+ 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");
+ model = ViewModelProviders.of(this).get(TransactionListViewModel.class);
+ modelAdapter = new TransactionListAdapter();
+
+ modelAdapter.setBoldAccountName(mShowOnlyAccountName);
+ root.setAdapter(modelAdapter);
+
+ FloatingActionButton fab = mActivity.findViewById(R.id.btn_add_transaction);
+
+ fab.show();
+ root.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ if (dy < 0) fab.show();
+ if (dy > 0) fab.hide();
+ }
+ });
+
+ LinearLayoutManager llm = new LinearLayoutManager(mActivity);
+
+ llm.setOrientation(LinearLayoutManager.VERTICAL);
+ root.setLayoutManager(llm);
+
+ swiper.setOnRefreshListener(() -> {
+ Log.d("ui", "refreshing transactions via swipe");
+ mActivity.scheduleTransactionListRetrieval();
+ });
+
+ swiper.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);
+
+ vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter);
+ accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name);
+
+ TransactionListFragment me = this;
+ MLDB.hookAutocompletionAdapter(mActivity, accNameFilter, "accounts", "name", true);
+ accNameFilter.setOnItemClickListener((parent, view, position, id) -> {
+// Log.d("tmp", "direct onItemClick");
+ TransactionListViewModel.scheduleTransactionListReload();
+ MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position);
+ accountFilter.set(mc.getString(1));
+ Globals.hideSoftKeyboard(mActivity);
+ });
+
+ accountFilter.addObserver((o, arg) -> {
+ String accountName = accountFilter.get();
+ modelAdapter.setBoldAccountName(accountName);
+ setShowOnlyAccountName(accountName);
+ TransactionListViewModel.scheduleTransactionListReload();
+ if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(false);
+ });
+
+ Data.profile.addObserver((o, arg) -> mActivity.runOnUiThread(() -> {
+ Log.d("transactions", "requesting list reload");
+ TransactionListViewModel.scheduleTransactionListReload();
+ }));
+
+ TransactionListViewModel.scheduleTransactionListReload();
+ TransactionListViewModel.updating.addObserver(
+ (o, arg) -> swiper.setRefreshing(TransactionListViewModel.updating.get()));
+ TransactionListViewModel.updateError.addObserver(new Observer() {
+ @Override
+ public void update(Observable o, Object 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 -> {
+ vAccountFilter.setVisibility(View.GONE);
+ if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(true);
+ accountFilter.set(null);
+ accNameFilter.setText(null);
+ TransactionListViewModel.scheduleTransactionListReload();
+ Globals.hideSoftKeyboard(mActivity);
+ });