+
+ mainModel.getUpdateError()
+ .observe(this, (error) -> {
+ if (error == null)
+ return;
+
+ Snackbar.make(mViewPager, error, Snackbar.LENGTH_LONG)
+ .show();
+ mainModel.clearUpdateError();
+ });
+ }
+ private void scheduleDataRetrievalIfStale(long lastUpdate) {
+ long now = new Date().getTime();
+ if ((lastUpdate == 0) || (now > (lastUpdate + (24 * 3600 * 1000)))) {
+ if (lastUpdate == 0)
+ Logger.debug("db::", "WEB data never fetched. scheduling a fetch");
+ else
+ Logger.debug("db", String.format(Locale.ENGLISH,
+ "WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
+ lastUpdate / 1000f, now / 1000f));
+
+ mainModel.scheduleTransactionListRetrieval();
+ }
+ }
+ private void createShortcuts(List<MobileLedgerProfile> list) {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1)
+ return;
+
+ ShortcutManager sm = getSystemService(ShortcutManager.class);
+ List<ShortcutInfo> shortcuts = new ArrayList<>();
+ int i = 0;
+ for (MobileLedgerProfile p : list) {
+ if (shortcuts.size() >= sm.getMaxShortcutCountPerActivity())
+ break;
+
+ if (!p.isPostingPermitted())
+ continue;
+
+ final ShortcutInfo.Builder builder =
+ new ShortcutInfo.Builder(this, "new_transaction_" + p.getUuid());
+ ShortcutInfo si = builder.setShortLabel(p.getName())
+ .setIcon(Icon.createWithResource(this,
+ R.drawable.thick_plus_icon))
+ .setIntent(new Intent(Intent.ACTION_VIEW, null, this,
+ NewTransactionActivity.class).putExtra("profile_uuid",
+ p.getUuid()))
+ .setRank(i)
+ .build();
+ shortcuts.add(si);
+ i++;
+ }
+ sm.setDynamicShortcuts(shortcuts);