+ public void updateLastUpdateTextFromDB() {
+ {
+ final MobileLedgerProfile profile = Data.profile.get();
+ long last_update =
+ (profile != null) ? profile.getLongOption(MLDB.OPT_LAST_SCRAPE, 0L) : 0;
+
+ Log.d("transactions", String.format("Last update = %d", last_update));
+ if (last_update == 0) {
+ Data.lastUpdateDate.set(null);
+ }
+ else {
+ Data.lastUpdateDate.set(new Date(last_update));
+ }
+ }
+ }
+ public void scheduleTransactionListRetrieval() {
+ if (Data.profile.get() == null) return;
+
+ retrieveTransactionsTask = new RetrieveTransactionsTask(new WeakReference<>(this));
+
+ retrieveTransactionsTask.execute();
+ bTransactionListCancelDownload.setEnabled(true);
+ }
+ public void onStopTransactionRefreshClick(View view) {
+ Log.d("interactive", "Cancelling transactions refresh");
+ if (retrieveTransactionsTask != null) retrieveTransactionsTask.cancel(false);
+ bTransactionListCancelDownload.setEnabled(false);
+ }
+ public void onRetrieveDone(String error) {
+ progressLayout.setVisibility(View.GONE);
+
+ if (error == null) {
+ updateLastUpdateTextFromDB();
+
+ new RefreshDescriptionsTask().execute();
+ }
+ else Toast.makeText(this, error, Toast.LENGTH_LONG).show();
+ }
+ public void onRetrieveStart() {
+ progressBar.setIndeterminate(true);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progressBar.setProgress(0, false);
+ else progressBar.setProgress(0);
+ progressLayout.setVisibility(View.VISIBLE);
+ }
+ public void onRetrieveProgress(RetrieveTransactionsTask.Progress progress) {
+ 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 navProfilesClicked(View view) {
+ drawer.closeDrawers();
+ Intent intent = new Intent(this, ProfileListActivity.class);
+ startActivity(intent);
+ }
+ public class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ public SectionsPagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ Log.d("main", String.format("Switching to fragment %d", position));
+ switch (position) {
+ case 0:
+ 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;
+ }
+ }