+
+ 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 list view");
+ progressBar = mActivity.findViewById(R.id.transaction_list_progress_bar);
+ if (progressBar == null)
+ throw new RuntimeException("Can't get hold on the transaction list progress bar");
+ progressLayout = mActivity.findViewById(R.id.transaction_progress_layout);
+ if (progressLayout == null) throw new RuntimeException(
+ "Can't get hold on the transaction list progress bar layout");
+ tvLastUpdate = mActivity.findViewById(R.id.transactions_last_update);
+ updateLastUpdateText();
+ model = ViewModelProviders.of(this).get(TransactionListViewModel.class);
+ modelAdapter = new TransactionListAdapter(model);
+
+ RecyclerView root = mActivity.findViewById(R.id.transaction_root);
+ root.setAdapter(modelAdapter);
+
+ LinearLayoutManager llm = new LinearLayoutManager(mActivity);
+
+ llm.setOrientation(LinearLayoutManager.VERTICAL);
+ root.setLayoutManager(llm);
+
+ swiper.setOnRefreshListener(() -> {
+ Log.d("ui", "refreshing transactions via swipe");
+ update_transactions();
+ });
+
+ 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);
+ bTransactionListCancelDownload =
+ mActivity.findViewById(R.id.transaction_list_cancel_download);
+
+ TransactionListFragment me = this;
+ MLDB.hook_autocompletion_adapter(mActivity, accNameFilter, "accounts", "name");
+ accNameFilter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ Log.d("tmp", "direct onItemClick");
+ model.reloadTransactions(me);
+ MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position);
+ modelAdapter.setBoldAccountName(mc.getString(1));
+ modelAdapter.notifyDataSetChanged();
+ Globals.hideSoftKeyboard(mActivity);
+ }
+ });
+
+ updateLastUpdateText();
+ long last_update = MLDB.get_option_value(mActivity, MLDB.OPT_TRANSACTION_LIST_STAMP, 0L);
+ Log.d("transactions", String.format("Last update = %d", last_update));
+ if (last_update == 0) {
+ update_transactions();
+ }
+ else {
+ model.reloadTransactions(this);
+ }
+ }
+ @Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ inflater.inflate(R.menu.transaction_list, menu);
+
+ menuTransactionListFilter = menu.findItem(R.id.menu_transaction_list_filter);
+ if ((menuTransactionListFilter == null)) throw new AssertionError();
+
+ super.onCreateOptionsMenu(menu, inflater);
+ }
+ private void update_transactions() {
+ retrieveTransactionsTask = new RetrieveTransactionsTask(new WeakReference<>(this));
+
+ RetrieveTransactionsTask.Params params = new RetrieveTransactionsTask.Params(
+ PreferenceManager.getDefaultSharedPreferences(mActivity));
+
+ retrieveTransactionsTask.execute(params);
+ bTransactionListCancelDownload.setEnabled(true);
+ }
+ public void onRetrieveStart() {
+ progressBar.setIndeterminate(true);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progressBar.setProgress(0, false);
+ else progressBar.setProgress(0);
+ progressLayout.setVisibility(View.VISIBLE);
+ }
+ public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
+ if ((progress.getTotal() == RetrieveTransactionsTask.Progress.INDETERMINATE) ||
+ (progress.getTotal() == 0))
+ {
+ progressBar.setIndeterminate(true);
+ }
+ else {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ progressBar.setMin(0);
+ }
+ progressBar.setMax(progress.getTotal());
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ progressBar.setProgress(progress.getProgress(), true);
+ }
+ else progressBar.setProgress(progress.getProgress());
+ progressBar.setIndeterminate(false);
+ }