+ long lastUpdate = profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L);
+
+ Logger.debug("transactions", String.format(Locale.ENGLISH, "Last update = %d", lastUpdate));
+ if (lastUpdate == 0) {
+ Data.lastUpdateLiveData.postValue(null);
+ }
+ else {
+ Data.lastUpdateLiveData.postValue(new Date(lastUpdate));
+ }
+
+ // this is unfortunate, but it appears we need a two-stage rocket to make
+ // a value reach a recycler view item holder. first stage is a regular
+ // LiveData that can be observed by an activity (this).
+ // the second stage forwards the changes, in the UI thread, to the
+ // observable value, observed by the view holders.
+ // view holders can't observe the LiveData because they don't have
+ // access to lifecycle owners. oh, also the value is updated by a thread
+ // so it must be tunnelled by an activity for it to reach the view
+ // holders in the UI thread
+ Data.lastUpdateLiveData.observe(this, date -> runOnUiThread(
+ () -> Data.lastUpdate.set((date == null) ? 0 : date.getTime())));
+ scheduleDataRetrievalIfStale(lastUpdate);
+
+ }
+ 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;
+ }
+ }