+ long last_update = profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L);
+
+ debug("transactions", String.format(Locale.ENGLISH, "Last update = %d", last_update));
+ if (last_update == 0) {
+ Data.lastUpdateDate.postValue(null);
+ }
+ else {
+ Data.lastUpdateDate.postValue(new Date(last_update));
+ }
+ }
+ public void onStopTransactionRefreshClick(View view) {
+ debug("interactive", "Cancelling transactions refresh");
+ Data.stopTransactionsRetrieval();
+ bTransactionListCancelDownload.setEnabled(false);
+ }
+ public void onRetrieveDone(String error) {
+ Data.transactionRetrievalDone();
+ findViewById(R.id.transaction_progress_layout).setVisibility(View.GONE);
+
+ if (error == null) {
+ updateLastUpdateTextFromDB();
+
+ new RefreshDescriptionsTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ TransactionListViewModel.scheduleTransactionListReload();
+ }
+ else
+ Snackbar.make(mViewPager, error, Snackbar.LENGTH_LONG)
+ .show();
+ }
+ public void onRetrieveStart() {
+ ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
+ bTransactionListCancelDownload.setEnabled(true);
+ ColorStateList csl = Colors.getColorStateList();
+ progressBar.setIndeterminateTintList(csl);
+ progressBar.setProgressTintList(csl);
+ progressBar.setIndeterminate(true);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ progressBar.setProgress(0, false);
+ else
+ progressBar.setProgress(0);
+ findViewById(R.id.transaction_progress_layout).setVisibility(View.VISIBLE);
+ }
+ public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
+ ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
+ 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);
+ }
+ }
+ public void fabShouldShow() {
+ if ((profile != null) && profile.isPostingPermitted() && !drawer.isOpen())
+ fab.show();
+ }
+ public void fabHide() {
+ fab.hide();
+ }
+ public void onAccountSummaryRowViewClicked(View view) {
+ ViewGroup row;
+ if (view.getId() == R.id.account_expander)
+ row = (ViewGroup) view.getParent()
+ .getParent();
+ else
+ row = (ViewGroup) view.getParent();
+
+ LedgerAccount acc = (LedgerAccount) row.getTag();
+ switch (view.getId()) {
+ case R.id.account_row_acc_name:
+ case R.id.account_expander:
+ case R.id.account_expander_container:
+ debug("accounts", "Account expander clicked");
+ if (!acc.hasSubAccounts())
+ return;
+
+ boolean wasExpanded = acc.isExpanded();
+
+ View arrow = row.findViewById(R.id.account_expander_container);
+
+ arrow.clearAnimation();
+ ViewPropertyAnimator animator = arrow.animate();
+
+ acc.toggleExpanded();
+ DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
+ new Object[]{acc.isExpanded(), acc.getName(), profile.getUuid()
+ });
+
+ if (wasExpanded) {
+ debug("accounts", String.format("Collapsing account '%s'", acc.getName()));
+ arrow.setRotation(0);
+ animator.rotationBy(180);
+
+ // removing all child accounts from the view
+ int start = -1, count = 0;
+ try (LockHolder ignored = Data.accounts.lockForWriting()) {
+ for (int i = 0; i < Data.accounts.size(); i++) {
+ if (acc.isParentOf(Data.accounts.get(i))) {
+// debug("accounts", String.format("Found a child '%s' at position
+// %d",
+// Data.accounts.get(i).getName(), i));
+ if (start == -1) {
+ start = i;
+ }
+ count++;
+ }
+ else {
+ if (start != -1) {
+// debug("accounts",
+// String.format("Found a non-child '%s' at position %d",
+// Data.accounts.get(i).getName(), i));
+ break;
+ }
+ }
+ }
+
+ if (start != -1) {
+ for (int j = 0; j < count; j++) {
+// debug("accounts", String.format("Removing item %d: %s", start + j,
+// Data.accounts.get(start).getName()));
+ Data.accounts.removeQuietly(start);
+ }
+
+ mAccountSummaryFragment.modelAdapter.notifyItemRangeRemoved(start,
+ count);
+ }
+ }
+ }
+ else {
+ debug("accounts", String.format("Expanding account '%s'", acc.getName()));
+ arrow.setRotation(180);
+ animator.rotationBy(-180);
+ List<LedgerAccount> children = profile.loadVisibleChildAccountsOf(acc);
+ try (LockHolder ignored = Data.accounts.lockForWriting()) {
+ int parentPos = Data.accounts.indexOf(acc);
+ if (parentPos != -1) {
+ // may have disappeared in a concurrent refresh operation
+ Data.accounts.addAllQuietly(parentPos + 1, children);
+ mAccountSummaryFragment.modelAdapter.notifyItemRangeInserted(
+ parentPos + 1, children.size());
+ }
+ }
+ }
+ break;
+ case R.id.account_row_acc_amounts:
+ if (acc.getAmountCount() > AccountSummaryAdapter.AMOUNT_LIMIT) {
+ acc.toggleAmountsExpanded();
+ DbOpQueue.add(
+ "update accounts set amounts_expanded=? where name=? and profile=?",
+ new Object[]{acc.amountsExpanded(), acc.getName(), profile.getUuid()
+ });
+ Data.accounts.triggerItemChangedNotification(acc);
+ }
+ break;
+ }
+ }
+
+ public class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ SectionsPagerAdapter(FragmentManager fm) {
+ super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
+ }
+
+ @NotNull
+ @Override
+ public Fragment getItem(int position) {
+ debug("main", String.format(Locale.ENGLISH, "Switching to fragment %d", position));
+ switch (position) {
+ case 0:
+// debug("flow", "Creating account summary fragment");
+ return mAccountSummaryFragment = new AccountSummaryFragment();
+ case 1:
+ return new TransactionListFragment();
+ default:
+ throw new IllegalStateException(
+ String.format("Unexpected fragment index: " + "%d", position));
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return 2;
+ }
+ }