+ private void onProfileListChanged(List<Profile> newList) {
+ if ((newList == null) || newList.isEmpty()) {
+ b.noProfilesLayout.setVisibility(View.VISIBLE);
+ b.mainAppLayout.setVisibility(View.GONE);
+ return;
+ }
+
+ b.mainAppLayout.setVisibility(View.VISIBLE);
+ b.noProfilesLayout.setVisibility(View.GONE);
+
+ b.navProfileList.setMinimumHeight(
+ (int) (getResources().getDimension(R.dimen.thumb_row_height) * newList.size()));
+
+ Logger.debug("profiles", "profile list changed");
+ mProfileListAdapter.setProfileList(newList);
+
+ createShortcuts(newList);
+
+ final Profile currentProfile = Data.getProfile();
+ Profile replacementProfile = null;
+ if (currentProfile != null) {
+ for (Profile p : newList) {
+ if (p.getId() == currentProfile.getId()) {
+ replacementProfile = p;
+ break;
+ }
+ }
+ }
+
+ if (replacementProfile == null) {
+ Logger.debug(TAG, "Switching profile because the current is no longer available");
+ Data.setCurrentProfile(newList.get(0));
+ }
+ else {
+ Data.setCurrentProfile(replacementProfile);
+ }
+ }
+ /**
+ * called when the current profile has changed
+ */
+ private void onProfileChanged(@Nullable Profile newProfile) {
+ if (this.profile != null) {
+ if (this.profile.equals(newProfile))
+ return;
+ }
+
+ boolean haveProfile = newProfile != null;
+
+ if (haveProfile)
+ setTitle(newProfile.getName());
+ else
+ setTitle(R.string.app_name);
+
+ int newProfileTheme = haveProfile ? newProfile.getTheme() : Colors.DEFAULT_HUE_DEG;
+ if (newProfileTheme != Colors.profileThemeId) {
+ Logger.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;
+ }
+
+ final boolean sameProfileId = (newProfile != null) && (this.profile != null) &&
+ this.profile.getId() == newProfile.getId();
+
+ this.profile = newProfile;
+
+ b.noProfilesLayout.setVisibility(haveProfile ? View.GONE : View.VISIBLE);
+ b.pagerLayout.setVisibility(haveProfile ? View.VISIBLE : View.VISIBLE);