+
+ mProfileListAdapter.notifyDataSetChanged();
+ });
+
+ LinearLayoutManager llm = new LinearLayoutManager(this);
+
+ llm.setOrientation(RecyclerView.VERTICAL);
+ root.setLayoutManager(llm);
+
+ profileListHeadMore.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
+ profileListHeadCancel.setOnClickListener((v) -> mProfileListAdapter.flipEditingProfiles());
+ profileListHeadMoreAndCancel.setOnClickListener(
+ (v) -> mProfileListAdapter.flipEditingProfiles());
+ if (drawerListener == null) {
+ drawerListener = new DrawerLayout.SimpleDrawerListener() {
+ @Override
+ public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
+ if (slideOffset > 0.2)
+ fabHide();
+ }
+ @Override
+ public void onDrawerClosed(View drawerView) {
+ super.onDrawerClosed(drawerView);
+ mProfileListAdapter.setAnimationsEnabled(false);
+ mProfileListAdapter.editingProfiles.setValue(false);
+ Data.drawerOpen.setValue(false);
+ fabShouldShow();
+ }
+ @Override
+ public void onDrawerOpened(View drawerView) {
+ super.onDrawerOpened(drawerView);
+ mProfileListAdapter.setAnimationsEnabled(true);
+ Data.drawerOpen.setValue(true);
+ fabHide();
+ }
+ };
+ drawer.addDrawerListener(drawerListener);
+ }
+
+ Data.drawerOpen.observe(this, open -> {
+ if (open)
+ drawer.open();
+ else
+ drawer.close();
+ });
+ }
+ private void scheduleDataRetrievalIfStale(Date lastUpdate) {
+ long now = new Date().getTime();
+ if ((lastUpdate == null) || (now > (lastUpdate.getTime() + (24 * 3600 * 1000)))) {
+ if (lastUpdate == null)
+ debug("db::", "WEB data never fetched. scheduling a fetch");
+ else
+ debug("db", String.format(Locale.ENGLISH,
+ "WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
+ lastUpdate.getTime() / 1000f, now / 1000f));
+
+ Data.scheduleTransactionListRetrieval(this);
+ }
+ }
+ 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);
+ }
+ private void onProfileListChanged(List<MobileLedgerProfile> newList) {
+ if ((newList == null) || newList.isEmpty()) {
+ findViewById(R.id.no_profiles_layout).setVisibility(View.VISIBLE);
+ findViewById(R.id.main_app_layout).setVisibility(View.GONE);
+ return;
+ }
+
+ findViewById(R.id.main_app_layout).setVisibility(View.VISIBLE);
+ findViewById(R.id.no_profiles_layout).setVisibility(View.GONE);
+
+ findViewById(R.id.nav_profile_list).setMinimumHeight(
+ (int) (getResources().getDimension(R.dimen.thumb_row_height) * newList.size()));
+
+ debug("profiles", "profile list changed");
+ mProfileListAdapter.notifyDataSetChanged();
+
+ createShortcuts(newList);
+ }
+ /**
+ * called when the current profile has changed
+ */
+ private void onProfileChanged(MobileLedgerProfile profile) {
+ if (this.profile == null) {
+ if (profile == null)
+ return;