Exemple #1
0
  private void saveSettings() throws MessagingException {
    mFolder.setInTopGroup(mInTopGroup.isChecked());
    mFolder.setIntegrate(mIntegrate.isChecked());
    // We call getPushClass() because display class changes can affect push class when push class is
    // set to inherit
    FolderClass oldPushClass = mFolder.getPushClass();
    FolderClass oldDisplayClass = mFolder.getDisplayClass();
    mFolder.setDisplayClass(FolderClass.valueOf(mDisplayClass.getValue()));
    mFolder.setSyncClass(FolderClass.valueOf(mSyncClass.getValue()));
    mFolder.setPushClass(FolderClass.valueOf(mPushClass.getValue()));

    mFolder.save();

    FolderClass newPushClass = mFolder.getPushClass();
    FolderClass newDisplayClass = mFolder.getDisplayClass();

    if (oldPushClass != newPushClass
        || (newPushClass != FolderClass.NO_CLASS && oldDisplayClass != newDisplayClass)) {
      MailService.actionRestartPushers(getApplication(), null);
    }
  }
Exemple #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String folderName = (String) getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);

    try {
      LocalStore localStore = mAccount.getLocalStore();
      mFolder = localStore.getFolder(folderName);
      mFolder.open(OpenMode.READ_WRITE);
    } catch (MessagingException me) {
      Log.e(K9.LOG_TAG, "Unable to edit folder " + folderName + " preferences", me);
      return;
    }

    boolean isPushCapable = false;
    Store store = null;
    try {
      store = mAccount.getRemoteStore();
      isPushCapable = store.isPushCapable();
    } catch (Exception e) {
      Log.e(K9.LOG_TAG, "Could not get remote store", e);
    }

    addPreferencesFromResource(R.xml.folder_settings_preferences);

    Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
    category.setTitle(folderName);

    mInTopGroup = (CheckBoxPreference) findPreference(PREFERENCE_IN_TOP_GROUP);
    mInTopGroup.setChecked(mFolder.isInTopGroup());
    mIntegrate = (CheckBoxPreference) findPreference(PREFERENCE_INTEGRATE);
    mIntegrate.setChecked(mFolder.isIntegrate());

    mDisplayClass = (ListPreference) findPreference(PREFERENCE_DISPLAY_CLASS);
    mDisplayClass.setValue(mFolder.getDisplayClass().name());
    mDisplayClass.setSummary(mDisplayClass.getEntry());
    mDisplayClass.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDisplayClass.findIndexOfValue(summary);
            mDisplayClass.setSummary(mDisplayClass.getEntries()[index]);
            mDisplayClass.setValue(summary);
            return false;
          }
        });

    mSyncClass = (ListPreference) findPreference(PREFERENCE_SYNC_CLASS);
    mSyncClass.setValue(mFolder.getRawSyncClass().name());
    mSyncClass.setSummary(mSyncClass.getEntry());
    mSyncClass.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mSyncClass.findIndexOfValue(summary);
            mSyncClass.setSummary(mSyncClass.getEntries()[index]);
            mSyncClass.setValue(summary);
            return false;
          }
        });

    mPushClass = (ListPreference) findPreference(PREFERENCE_PUSH_CLASS);
    mPushClass.setEnabled(isPushCapable);
    mPushClass.setValue(mFolder.getRawPushClass().name());
    mPushClass.setSummary(mPushClass.getEntry());
    mPushClass.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mPushClass.findIndexOfValue(summary);
            mPushClass.setSummary(mPushClass.getEntries()[index]);
            mPushClass.setValue(summary);
            return false;
          }
        });
  }