+ if (b.drawerLayout.isDrawerOpen(GravityCompat.START)) {
+ b.drawerLayout.closeDrawer(GravityCompat.START);
+ }
+ else {
+ if (mBackMeansToAccountList && (b.mainPager.getCurrentItem() == 1)) {
+ mainModel.getAccountFilter()
+ .setValue(null);
+ showAccountSummaryFragment();
+ mBackMeansToAccountList = false;
+ }
+ else {
+ Logger.debug("fragments", String.format(Locale.ENGLISH, "manager stack: %d",
+ getSupportFragmentManager().getBackStackEntryCount()));
+
+ super.onBackPressed();
+ }
+ }
+ }
+ public void updateLastUpdateTextFromDB() {
+ if (profile == null)
+ return;
+
+ long lastUpdate = profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L);
+
+ Logger.debug("transactions", String.format(Locale.ENGLISH, "Last update = %d", lastUpdate));
+ 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.set("----");
+ Data.lastAccountsUpdateText.set("----");
+ }
+ else {
+ Data.lastTransactionsUpdateText.set(
+ String.format(Objects.requireNonNull(Data.locale.getValue()),
+ templateForTransactions,
+ transactionCount == null ? 0 : transactionCount,
+ DateUtils.formatDateTime(this, lastUpdate.getTime(), formatFlags)));
+ Data.lastAccountsUpdateText.set(
+ 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);
+ }
+ else {
+ b.transactionListProgressBar.setProgress(0);
+ }
+ b.transactionProgressLayout.setVisibility(View.VISIBLE);
+ }
+ else {
+ b.transactionProgressLayout.setVisibility(View.GONE);
+ }
+ }
+ public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
+ if (progress.getState() == RetrieveTransactionsTask.ProgressState.FINISHED) {
+ Logger.debug("progress", "Done");
+ b.transactionProgressLayout.setVisibility(View.GONE);
+
+ mainModel.transactionRetrievalDone();
+
+ String error = progress.getError();
+ if (error != null) {
+ if (error.equals(RetrieveTransactionsTask.Result.ERR_JSON_PARSER_ERROR))
+ error = getResources().getString(R.string.err_json_parser_error);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage(error);
+ builder.setPositiveButton(R.string.btn_profile_options, (dialog, which) -> {
+ Logger.debug("error", "will start profile editor");
+ MobileLedgerProfile.startEditProfileActivity(this, profile);
+ });
+ builder.create()
+ .show();
+ return;
+ }
+
+ return;
+ }
+
+
+ b.transactionListCancelDownload.setEnabled(true);
+// ColorStateList csl = Colors.getColorStateList();
+// progressBar.setIndeterminateTintList(csl);
+// progressBar.setProgressTintList(csl);
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+// progressBar.setProgress(0, false);
+// else
+// progressBar.setProgress(0);
+ b.transactionProgressLayout.setVisibility(View.VISIBLE);
+
+ if (progress.isIndeterminate() || (progress.getTotal() <= 0)) {
+ b.transactionListProgressBar.setIndeterminate(true);
+ Logger.debug("progress", "indeterminate");