+ if (profile == null)
+ return;
+
+ DB.get()
+ .getOptionDAO()
+ .load(profile.getId(), Option.OPT_LAST_SCRAPE)
+ .observe(this, opt -> {
+ long lastUpdate = 0;
+ if (opt != null) {
+ try {
+ lastUpdate = Long.parseLong(opt.getValue());
+ }
+ catch (NumberFormatException ex) {
+ Logger.debug(TAG, String.format("Error parsing '%s' as long", opt.getValue()),
+ ex);
+ }
+ }
+
+ if (lastUpdate == 0) {
+ Data.lastUpdateDate.postValue(null);
+ }
+ else {
+ Data.lastUpdateDate.postValue(new Date(lastUpdate));
+ }
+
+ scheduleDataRetrievalIfStale(lastUpdate);
+ });
+ }
+ private void refreshLastUpdateInfo() {
+ final int formatFlags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
+ DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NUMERIC_DATE;
+ String templateForTransactions =
+ getResources().getString(R.string.transaction_count_summary);
+ String templateForAccounts = getResources().getString(R.string.account_count_summary);
+ Integer accountCount = Data.lastUpdateAccountCount.getValue();
+ Integer transactionCount = Data.lastUpdateTransactionCount.getValue();
+ Date lastUpdate = Data.lastUpdateDate.getValue();
+ if (lastUpdate == null) {
+ Data.lastTransactionsUpdateText.setValue("----");
+ Data.lastAccountsUpdateText.setValue("----");
+ }
+ else {
+ Data.lastTransactionsUpdateText.setValue(
+ String.format(Objects.requireNonNull(Data.locale.getValue()),
+ templateForTransactions,
+ transactionCount == null ? 0 : transactionCount,
+ DateUtils.formatDateTime(this, lastUpdate.getTime(), formatFlags)));
+ Data.lastAccountsUpdateText.setValue(
+ String.format(Objects.requireNonNull(Data.locale.getValue()),
+ templateForAccounts, accountCount == null ? 0 : accountCount,
+ DateUtils.formatDateTime(this, lastUpdate.getTime(), formatFlags)));
+ }
+ }
+ public void onStopTransactionRefreshClick(View view) {
+ Logger.debug("interactive", "Cancelling transactions refresh");
+ mainModel.stopTransactionsRetrieval();
+ b.transactionListCancelDownload.setEnabled(false);
+ }
+ public void onRetrieveRunningChanged(Boolean running) {
+ if (running) {
+ b.transactionListCancelDownload.setEnabled(true);
+ ColorStateList csl = Colors.getColorStateList();
+ b.transactionListProgressBar.setIndeterminateTintList(csl);
+ b.transactionListProgressBar.setProgressTintList(csl);
+ b.transactionListProgressBar.setIndeterminate(true);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ b.transactionListProgressBar.setProgress(0, false);