+ }
+ 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();
+ bTransactionListCancelDownload.setEnabled(false);
+ }
+ public void onRetrieveRunningChanged(Boolean running) {
+ final View progressLayout = findViewById(R.id.transaction_progress_layout);
+ if (running) {
+ 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);
+ }
+ progressLayout.setVisibility(View.VISIBLE);
+ }
+ else {
+ progressLayout.setVisibility(View.GONE);
+ }
+ }
+ public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
+ ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar);
+
+ if (progress.getState() == RetrieveTransactionsTask.ProgressState.FINISHED) {
+ Logger.debug("progress", "Done");
+ findViewById(R.id.transaction_progress_layout).setVisibility(View.GONE);
+
+ mainModel.transactionRetrievalDone();
+
+ if (progress.getError() != null) {
+ Snackbar.make(mViewPager, progress.getError(), Snackbar.LENGTH_LONG)
+ .show();
+ return;
+ }
+
+ return;
+ }
+
+
+ bTransactionListCancelDownload.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);
+ findViewById(R.id.transaction_progress_layout).setVisibility(View.VISIBLE);
+
+ if (progress.isIndeterminate() || (progress.getTotal() <= 0)) {
+ progressBar.setIndeterminate(true);
+ Logger.debug("progress", "indeterminate");
+ }
+ else {
+ if (progressBar.isIndeterminate()) {
+ progressBar.setIndeterminate(false);
+ }
+// Logger.debug("progress",
+// String.format(Locale.US, "%d/%d", progress.getProgress(), progress.getTotal
+// ()));
+ progressBar.setMax(progress.getTotal());
+ // for some reason animation doesn't work - no progress is shown (stick at 0)
+ // on lineageOS 14.1 (Nougat, 7.1.2)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ progressBar.setProgress(progress.getProgress(), false);
+ else
+ progressBar.setProgress(progress.getProgress());
+ }
+ }
+ public void fabShouldShow() {
+ if ((profile != null) && profile.isPostingPermitted() && !drawer.isOpen())
+ fab.show();
+ else
+ fabHide();
+ }
+ public void fabHide() {
+ fab.hide();
+ }
+
+ public static class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ SectionsPagerAdapter(FragmentManager fm) {
+ super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
+ }
+
+ @NotNull
+ @Override
+ public Fragment getItem(int position) {
+ Logger.debug("main",
+ String.format(Locale.ENGLISH, "Switching to fragment %d", position));
+ switch (position) {
+ case 0:
+// debug("flow", "Creating account summary fragment");
+ return new AccountSummaryFragment();
+ case 1:
+ return new TransactionListFragment();
+ default:
+ throw new IllegalStateException(
+ String.format("Unexpected fragment index: " + "%d", position));
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return 2;
+ }
+ }