+ private void createShortcuts() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
+
+ List<ShortcutInfo> shortcuts = new ArrayList<>();
+ try (LockHolder lh = Data.profiles.lockForReading()) {
+ for (int i = 0; i < Data.profiles.size(); i++) {
+ MobileLedgerProfile p = Data.profiles.get(i);
+ if (!p.isPostingPermitted()) continue;
+
+ ShortcutInfo si = new ShortcutInfo.Builder(this, "new_transaction_" + p.getUuid())
+ .setShortLabel(p.getName())
+ .setIcon(Icon.createWithResource(this, R.drawable.svg_thick_plus_white))
+ .setIntent(new Intent(Intent.ACTION_VIEW, null, this,
+ NewTransactionActivity.class).putExtra("profile_uuid", p.getUuid()))
+ .setRank(i).build();
+ shortcuts.add(si);
+ }
+ }
+ ShortcutManager sm = getSystemService(ShortcutManager.class);
+ sm.setDynamicShortcuts(shortcuts);
+ }
+ private void onProfileListChanged(Object arg) {
+ findViewById(R.id.nav_profile_list).setMinimumHeight(
+ (int) (getResources().getDimension(R.dimen.thumb_row_height) *
+ Data.profiles.size()));
+
+ Log.d("profiles", "profile list changed");
+ if (arg == null) mProfileListAdapter.notifyDataSetChanged();
+ else mProfileListAdapter.notifyItemChanged((int) arg);
+
+ createShortcuts();
+ }
+ private void onProfileChanged(Object arg) {
+ MobileLedgerProfile profile = Data.profile.get();
+ MainActivity.this.runOnUiThread(() -> {
+
+ boolean haveProfile = profile != null;
+ findViewById(R.id.no_profiles_layout).setVisibility(haveProfile ? View.GONE : View.VISIBLE);
+ findViewById(R.id.pager_layout)
+ .setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);
+
+ Data.transactions.clear();
+ Log.d("transactions", "requesting list reload");
+ TransactionListViewModel.scheduleTransactionListReload();
+
+ Data.accounts.clear();
+ AccountSummaryViewModel.scheduleAccountListReload();
+
+ if (profile == null) MainActivity.this.setTitle(R.string.app_name);
+ else MainActivity.this.setTitle(profile.getName());
+ MainActivity.this.updateLastUpdateTextFromDB();
+ int old_index = -1;
+ int new_index = -1;
+ if (arg != null) {
+ MobileLedgerProfile old = (MobileLedgerProfile) arg;
+ old_index = Data.getProfileIndex(old);
+ new_index = Data.getProfileIndex(profile);
+ }
+
+ if ((old_index != -1) && (new_index != -1)) {
+ mProfileListAdapter.notifyItemChanged(old_index);
+ mProfileListAdapter.notifyItemChanged(new_index);
+ }
+ else mProfileListAdapter.notifyDataSetChanged();
+
+ MainActivity.this.collapseProfileList();
+
+ int newProfileTheme = (profile == null) ? -1 : profile.getThemeId();
+ if (newProfileTheme != Colors.profileThemeId) {
+ Log.d("profiles", String.format("profile theme %d → %d", Colors.profileThemeId,
+ newProfileTheme));
+ MainActivity.this.profileThemeChanged();
+ Colors.profileThemeId = newProfileTheme;
+ // profileThemeChanged would restart the activity, so no need to reload the
+ // data sets below
+ return;
+ }
+ drawer.closeDrawers();
+
+ if (profile == null) {
+ mToolbar.setSubtitle(null);
+ fab.hide();
+ }
+ else {
+ if (profile.isPostingPermitted()) {
+ mToolbar.setSubtitle(null);
+ fab.show();
+ }
+ else {
+ mToolbar.setSubtitle(R.string.profile_subitlte_read_only);
+ fab.hide();
+ }
+ }
+
+ updateLastUpdateTextFromDB();
+
+ scheduleDataRetrievalIfStale();
+ });
+ }