From cac33a2e9188f031baf40cc95b989f0d0b3a6993 Mon Sep 17 00:00:00 2001 From: Tony Mantler Date: Wed, 12 Mar 2014 15:05:50 -0700 Subject: [PATCH] Allow entry into account settings when inbox is null b/13436061 Change-Id: I544aa55000a91fe121de9bc7963eb89115d4758d --- .../setup/AccountSettingsFragment.java | 95 +++++++++++-------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/src/com/android/email/activity/setup/AccountSettingsFragment.java b/src/com/android/email/activity/setup/AccountSettingsFragment.java index 628410f8f..59c76a48f 100644 --- a/src/com/android/email/activity/setup/AccountSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountSettingsFragment.java @@ -129,6 +129,10 @@ public class AccountSettingsFragment extends PreferenceFragment private Ringtone mRingtone; + /** + * This may be null if the account exists but the inbox has not yet been created in the database + * (waiting for initial sync) + */ private FolderPreferences mInboxFolderPreferences; // The ID of the account being edited @@ -453,14 +457,18 @@ public class AccountSettingsFragment extends PreferenceFragment final Folder inbox = (Folder) data.get(AccountLoader.RESULT_KEY_INBOX); - if (mUiAccount == null || mAccount == null || inbox == null) { + if (mUiAccount == null || mAccount == null) { mSaveOnExit = false; mCallback.abandonEdit(); return; } - mInboxFolderPreferences = - new FolderPreferences(mContext, mUiAccount.getEmailAddress(), inbox, true); + if (inbox == null) { + mInboxFolderPreferences = null; + } else { + mInboxFolderPreferences = + new FolderPreferences(mContext, mUiAccount.getEmailAddress(), inbox, true); + } if (!mSaveOnExit) { loadSettings(); } @@ -532,8 +540,10 @@ public class AccountSettingsFragment extends PreferenceFragment final AccountPreferences accountPreferences = new AccountPreferences(mContext, mUiAccount.getEmailAddress()); - NotificationUtils.moveNotificationSetting( - accountPreferences, mInboxFolderPreferences); + if (mInboxFolderPreferences != null) { + NotificationUtils.moveNotificationSetting( + accountPreferences, mInboxFolderPreferences); + } final String protocol = mAccount.getProtocol(mContext); final EmailServiceInfo info = EmailServiceUtils.getServiceInfo(mContext, protocol); @@ -672,45 +682,50 @@ public class AccountSettingsFragment extends PreferenceFragment } } - final CheckBoxPreference inboxNotify = (CheckBoxPreference) findPreference( - FolderPreferences.PreferenceKeys.NOTIFICATIONS_ENABLED); - inboxNotify.setChecked(mInboxFolderPreferences.areNotificationsEnabled()); - inboxNotify.setOnPreferenceChangeListener(this); - - mInboxRingtone = findPreference(FolderPreferences.PreferenceKeys.NOTIFICATION_RINGTONE); - final String ringtoneUri = mInboxFolderPreferences.getNotificationRingtoneUri(); - if (!TextUtils.isEmpty(ringtoneUri)) { - mRingtone = RingtoneManager.getRingtone(getActivity(), Uri.parse(ringtoneUri)); - } - setRingtoneSummary(); - mInboxRingtone.setOnPreferenceChangeListener(this); - mInboxRingtone.setOnPreferenceClickListener(new OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(final Preference preference) { - showRingtonePicker(); - - return true; - } - }); - final PreferenceCategory notificationsCategory = (PreferenceCategory) findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS); - notificationsCategory.setEnabled(true); - // Set the vibrator value, or hide it on devices w/o a vibrator - mInboxVibrate = (CheckBoxPreference) findPreference( - FolderPreferences.PreferenceKeys.NOTIFICATION_VIBRATE); - if (mInboxVibrate != null) { - mInboxVibrate.setChecked( - mInboxFolderPreferences.isNotificationVibrateEnabled()); - Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); - if (vibrator.hasVibrator()) { - // When the value is changed, update the setting. - mInboxVibrate.setOnPreferenceChangeListener(this); - } else { - // No vibrator present. Remove the preference altogether. - notificationsCategory.removePreference(mInboxVibrate); + if (mInboxFolderPreferences != null) { + final CheckBoxPreference inboxNotify = (CheckBoxPreference) findPreference( + FolderPreferences.PreferenceKeys.NOTIFICATIONS_ENABLED); + inboxNotify.setChecked(mInboxFolderPreferences.areNotificationsEnabled()); + inboxNotify.setOnPreferenceChangeListener(this); + + mInboxRingtone = findPreference(FolderPreferences.PreferenceKeys.NOTIFICATION_RINGTONE); + final String ringtoneUri = mInboxFolderPreferences.getNotificationRingtoneUri(); + if (!TextUtils.isEmpty(ringtoneUri)) { + mRingtone = RingtoneManager.getRingtone(getActivity(), Uri.parse(ringtoneUri)); } + setRingtoneSummary(); + mInboxRingtone.setOnPreferenceChangeListener(this); + mInboxRingtone.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(final Preference preference) { + showRingtonePicker(); + + return true; + } + }); + + notificationsCategory.setEnabled(true); + + // Set the vibrator value, or hide it on devices w/o a vibrator + mInboxVibrate = (CheckBoxPreference) findPreference( + FolderPreferences.PreferenceKeys.NOTIFICATION_VIBRATE); + if (mInboxVibrate != null) { + mInboxVibrate.setChecked( + mInboxFolderPreferences.isNotificationVibrateEnabled()); + Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); + if (vibrator.hasVibrator()) { + // When the value is changed, update the setting. + mInboxVibrate.setOnPreferenceChangeListener(this); + } else { + // No vibrator present. Remove the preference altogether. + notificationsCategory.removePreference(mInboxVibrate); + } + } + } else { + notificationsCategory.setEnabled(false); } final Preference retryAccount = findPreference(PREFERENCE_POLICIES_RETRY_ACCOUNT);