+ createShortcuts(newList);
+ }
+ /**
+ * called when the current profile has changed
+ */
+ private void onProfileChanged(MobileLedgerProfile profile) {
+ if (this.profile == null) {
+ if (profile == null)
+ return;
+ }
+ else {
+ if (this.profile.equals(profile))
+ return;
+ }
+
+ boolean haveProfile = profile != null;
+
+ if (haveProfile)
+ setTitle(profile.getName());
+ else
+ setTitle(R.string.app_name);
+
+ if (this.profile != null)
+ this.profile.getDisplayedAccounts()
+ .removeObservers(this);
+
+ this.profile = profile;
+
+ int newProfileTheme = haveProfile ? profile.getThemeHue() : -1;
+ if (newProfileTheme != Colors.profileThemeId) {
+ debug("profiles",
+ String.format(Locale.ENGLISH, "profile theme %d → %d", Colors.profileThemeId,
+ newProfileTheme));
+ Colors.profileThemeId = newProfileTheme;
+ profileThemeChanged();
+ // profileThemeChanged would restart the activity, so no need to reload the
+ // data sets below
+ return;
+ }
+
+ findViewById(R.id.no_profiles_layout).setVisibility(haveProfile ? View.GONE : View.VISIBLE);
+ findViewById(R.id.pager_layout).setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);
+
+ mProfileListAdapter.notifyDataSetChanged();
+
+ Data.transactions.clear();
+ debug("transactions", "requesting list reload");
+ TransactionListViewModel.scheduleTransactionListReload();
+
+ if (haveProfile) {
+ profile.scheduleAccountListReload();
+
+ if (profile.isPostingPermitted()) {
+ mToolbar.setSubtitle(null);
+ fab.show();
+ }
+ else {
+ mToolbar.setSubtitle(R.string.profile_subtitle_read_only);
+ fab.hide();
+ }
+ }
+ else {
+ mToolbar.setSubtitle(null);
+ fab.hide();
+ }
+
+ updateLastUpdateTextFromDB();
+ }
+ private void updateLastUpdateDisplay(Date newValue) {
+ LinearLayout l = findViewById(R.id.transactions_last_update_layout);
+ TextView v = findViewById(R.id.transactions_last_update);
+ if (newValue == null) {
+ l.setVisibility(View.INVISIBLE);
+ debug("main", "no last update date :(");
+ }
+ else {
+ final String text = DateFormat.getDateTimeInstance()
+ .format(newValue);
+ v.setText(text);
+ l.setVisibility(View.VISIBLE);
+ debug("main", String.format("Date formatted: %s", text));
+ }
+
+ scheduleDataRetrievalIfStale(newValue);
+ }
+ private void profileThemeChanged() {
+ storeThemeIdInPrefs(profile.getThemeHue());
+
+ // un-hook all observed LiveData
+ Data.removeProfileObservers(this);
+ Data.profiles.removeObservers(this);
+ Data.lastUpdateDate.removeObservers(this);
+
+ recreate();
+ }
+ private void storeThemeIdInPrefs(int themeId) {
+ // store the new theme id in the preferences
+ SharedPreferences prefs = getPreferences(MODE_PRIVATE);
+ SharedPreferences.Editor e = prefs.edit();
+ e.putInt(PREF_THEME_ID, themeId);
+ e.apply();
+ }
+ public void startEditProfileActivity(MobileLedgerProfile profile) {
+ Intent intent = new Intent(this, ProfileDetailActivity.class);
+ Bundle args = new Bundle();
+ if (profile != null) {
+ int index = Data.getProfileIndex(profile);
+ if (index != -1)
+ intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index);
+ }
+ intent.putExtras(args);
+ startActivity(intent, args);
+ }
+ private void setupProfile() {
+ MLDB.getOption(MLDB.OPT_PROFILE_UUID, null, new GetOptCallback() {
+ @Override
+ protected void onResult(String profileUUID) {
+ MobileLedgerProfile startupProfile;