Search in sources :

Example 1 with StorageEditor

use of com.fsck.k9.preferences.StorageEditor in project k-9 by k9mail.

the class MigrationTo42 method from41MoveFolderPreferences.

public static void from41MoveFolderPreferences(MigrationsHelper migrationsHelper) {
    try {
        LocalStore localStore = migrationsHelper.getLocalStore();
        Storage storage = migrationsHelper.getStorage();
        long startTime = System.currentTimeMillis();
        StorageEditor editor = storage.edit();
        List<? extends Folder> folders = localStore.getPersonalNamespaces(true);
        for (Folder folder : folders) {
            if (folder instanceof LocalFolder) {
                LocalFolder lFolder = (LocalFolder) folder;
                lFolder.save(editor);
            }
        }
        editor.commit();
        long endTime = System.currentTimeMillis();
        Timber.i("Putting folder preferences for %d folders back into Preferences took %d ms", folders.size(), endTime - startTime);
    } catch (Exception e) {
        Timber.e(e, "Could not replace Preferences in upgrade from DB_VERSION 41");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) Storage(com.fsck.k9.preferences.Storage) LocalStore(com.fsck.k9.mailstore.LocalStore) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 2 with StorageEditor

use of com.fsck.k9.preferences.StorageEditor in project k-9 by k9mail.

the class MessageListFragment method changeSort.

/**
     * Change the sort type and sort order used for the message list.
     *
     * @param sortType
     *         Specifies which field to use for sorting the message list.
     * @param sortAscending
     *         Specifies the sort order. If this argument is {@code null} the default search order
     *         for the sort type is used.
     */
// FIXME: Don't save the changes in the UI thread
private void changeSort(SortType sortType, Boolean sortAscending) {
    this.sortType = sortType;
    Account account = this.account;
    if (account != null) {
        account.setSortType(this.sortType);
        if (sortAscending == null) {
            this.sortAscending = account.isSortAscending(this.sortType);
        } else {
            this.sortAscending = sortAscending;
        }
        account.setSortAscending(this.sortType, this.sortAscending);
        sortDateAscending = account.isSortAscending(SortType.SORT_DATE);
        account.save(preferences);
    } else {
        K9.setSortType(this.sortType);
        if (sortAscending == null) {
            this.sortAscending = K9.isSortAscending(this.sortType);
        } else {
            this.sortAscending = sortAscending;
        }
        K9.setSortAscending(this.sortType, this.sortAscending);
        sortDateAscending = K9.isSortAscending(SortType.SORT_DATE);
        StorageEditor editor = preferences.getStorage().edit();
        K9.save(editor);
        editor.commit();
    }
    reSort();
}
Also used : Account(com.fsck.k9.Account) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 3 with StorageEditor

use of com.fsck.k9.preferences.StorageEditor in project k-9 by k9mail.

the class Prefs method saveSettings.

private void saveSettings() {
    Storage storage = Preferences.getPreferences(this).getStorage();
    K9.setK9Theme(themeNameToId(mTheme.getValue()));
    K9.setUseFixedMessageViewTheme(mFixedMessageTheme.isChecked());
    K9.setK9MessageViewThemeSetting(themeNameToId(mMessageTheme.getValue()));
    K9.setK9ComposerThemeSetting(themeNameToId(mComposerTheme.getValue()));
    K9.setAnimations(mAnimations.isChecked());
    K9.setGesturesEnabled(mGestures.isChecked());
    K9.setUseVolumeKeysForNavigation(mVolumeNavigation.getCheckedItems()[0]);
    K9.setUseVolumeKeysForListNavigation(mVolumeNavigation.getCheckedItems()[1]);
    K9.setStartIntegratedInbox(!mHideSpecialAccounts.isChecked() && mStartIntegratedInbox.isChecked());
    K9.setNotificationHideSubject(NotificationHideSubject.valueOf(mNotificationHideSubject.getValue()));
    int index = 0;
    K9.setConfirmDelete(mConfirmActions.getCheckedItems()[index++]);
    K9.setConfirmDeleteStarred(mConfirmActions.getCheckedItems()[index++]);
    if (NotificationController.platformSupportsExtendedNotifications()) {
        K9.setConfirmDeleteFromNotification(mConfirmActions.getCheckedItems()[index++]);
    }
    K9.setConfirmSpam(mConfirmActions.getCheckedItems()[index++]);
    K9.setConfirmDiscardMessage(mConfirmActions.getCheckedItems()[index++]);
    K9.setConfirmMarkAllRead(mConfirmActions.getCheckedItems()[index++]);
    K9.setMeasureAccounts(mMeasureAccounts.isChecked());
    K9.setCountSearchMessages(mCountSearch.isChecked());
    K9.setHideSpecialAccounts(mHideSpecialAccounts.isChecked());
    K9.setMessageListPreviewLines(Integer.parseInt(mPreviewLines.getValue()));
    K9.setMessageListCheckboxes(mCheckboxes.isChecked());
    K9.setMessageListStars(mStars.isChecked());
    K9.setShowCorrespondentNames(mShowCorrespondentNames.isChecked());
    K9.setMessageListSenderAboveSubject(mSenderAboveSubject.isChecked());
    K9.setShowContactName(mShowContactName.isChecked());
    K9.setShowContactPicture(mShowContactPicture.isChecked());
    K9.setColorizeMissingContactPictures(mColorizeMissingContactPictures.isChecked());
    K9.setUseBackgroundAsUnreadIndicator(mBackgroundAsUnreadIndicator.isChecked());
    K9.setThreadedViewEnabled(mThreadedView.isChecked());
    K9.setChangeContactNameColor(mChangeContactNameColor.isChecked());
    K9.setMessageViewFixedWidthFont(mFixedWidth.isChecked());
    K9.setMessageViewReturnToList(mReturnToList.isChecked());
    K9.setMessageViewShowNext(mShowNext.isChecked());
    K9.setAutofitWidth(mAutofitWidth.isChecked());
    K9.setQuietTimeEnabled(mQuietTimeEnabled.isChecked());
    boolean[] enabledRefileActions = mVisibleRefileActions.getCheckedItems();
    K9.setMessageViewDeleteActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_DELETE]);
    K9.setMessageViewArchiveActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_ARCHIVE]);
    K9.setMessageViewMoveActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_MOVE]);
    K9.setMessageViewCopyActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_COPY]);
    K9.setMessageViewSpamActionVisible(enabledRefileActions[VISIBLE_REFILE_ACTIONS_SPAM]);
    K9.setNotificationDuringQuietTimeEnabled(!mDisableNotificationDuringQuietTime.isChecked());
    K9.setQuietTimeStarts(mQuietTimeStarts.getTime());
    K9.setQuietTimeEnds(mQuietTimeEnds.getTime());
    K9.setWrapFolderNames(mWrapFolderNames.isChecked());
    if (mNotificationQuickDelete != null) {
        K9.setNotificationQuickDeleteBehaviour(NotificationQuickDelete.valueOf(mNotificationQuickDelete.getValue()));
    }
    if (mLockScreenNotificationVisibility != null) {
        K9.setLockScreenNotificationVisibility(K9.LockScreenNotificationVisibility.valueOf(mLockScreenNotificationVisibility.getValue()));
    }
    K9.setSplitViewMode(SplitViewMode.valueOf(mSplitViewMode.getValue()));
    K9.setAttachmentDefaultPath(mAttachmentPathPreference.getSummary().toString());
    boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue());
    if (!K9.isDebug() && mDebugLogging.isChecked()) {
        Toast.makeText(this, R.string.debug_logging_enabled, Toast.LENGTH_LONG).show();
    }
    K9.setDebug(mDebugLogging.isChecked());
    K9.DEBUG_SENSITIVE = mSensitiveLogging.isChecked();
    K9.setHideUserAgent(mHideUserAgent.isChecked());
    K9.setHideTimeZone(mHideTimeZone.isChecked());
    K9.setOpenPgpProvider(mOpenPgpProvider.getValue());
    K9.setOpenPgpSupportSignOnly(mOpenPgpSupportSignOnly.isChecked());
    StorageEditor editor = storage.edit();
    K9.save(editor);
    editor.commit();
    if (needsRefresh) {
        MailService.actionReset(this, null);
    }
}
Also used : Storage(com.fsck.k9.preferences.Storage) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 4 with StorageEditor

use of com.fsck.k9.preferences.StorageEditor in project k-9 by k9mail.

the class RemoteControlService method startService.

@Override
public int startService(final Intent intent, final int startId) {
    Timber.i("RemoteControlService started with startId = %d", startId);
    final Preferences preferences = Preferences.getPreferences(this);
    if (RESCHEDULE_ACTION.equals(intent.getAction())) {
        Timber.i("RemoteControlService requesting MailService poll reschedule");
        MailService.actionReschedulePoll(this, null);
    }
    if (PUSH_RESTART_ACTION.equals(intent.getAction())) {
        Timber.i("RemoteControlService requesting MailService push restart");
        MailService.actionRestartPushers(this, null);
    } else if (RemoteControlService.SET_ACTION.equals(intent.getAction())) {
        Timber.i("RemoteControlService got request to change settings");
        execute(getApplication(), new Runnable() {

            public void run() {
                try {
                    boolean needsReschedule = false;
                    boolean needsPushRestart = false;
                    String uuid = intent.getStringExtra(K9_ACCOUNT_UUID);
                    boolean allAccounts = intent.getBooleanExtra(K9_ALL_ACCOUNTS, false);
                    if (allAccounts) {
                        Timber.i("RemoteControlService changing settings for all accounts");
                    } else {
                        Timber.i("RemoteControlService changing settings for account with UUID %s", uuid);
                    }
                    List<Account> accounts = preferences.getAccounts();
                    for (Account account : accounts) {
                        //warning: account may not be isAvailable()
                        if (allAccounts || account.getUuid().equals(uuid)) {
                            Timber.i("RemoteControlService changing settings for account %s", account.getDescription());
                            String notificationEnabled = intent.getStringExtra(K9_NOTIFICATION_ENABLED);
                            String ringEnabled = intent.getStringExtra(K9_RING_ENABLED);
                            String vibrateEnabled = intent.getStringExtra(K9_VIBRATE_ENABLED);
                            String pushClasses = intent.getStringExtra(K9_PUSH_CLASSES);
                            String pollClasses = intent.getStringExtra(K9_POLL_CLASSES);
                            String pollFrequency = intent.getStringExtra(K9_POLL_FREQUENCY);
                            if (notificationEnabled != null) {
                                account.setNotifyNewMail(Boolean.parseBoolean(notificationEnabled));
                            }
                            if (ringEnabled != null) {
                                account.getNotificationSetting().setRing(Boolean.parseBoolean(ringEnabled));
                            }
                            if (vibrateEnabled != null) {
                                account.getNotificationSetting().setVibrate(Boolean.parseBoolean(vibrateEnabled));
                            }
                            if (pushClasses != null) {
                                needsPushRestart |= account.setFolderPushMode(FolderMode.valueOf(pushClasses));
                            }
                            if (pollClasses != null) {
                                needsReschedule |= account.setFolderSyncMode(FolderMode.valueOf(pollClasses));
                            }
                            if (pollFrequency != null) {
                                String[] allowedFrequencies = getResources().getStringArray(R.array.account_settings_check_frequency_values);
                                for (String allowedFrequency : allowedFrequencies) {
                                    if (allowedFrequency.equals(pollFrequency)) {
                                        Integer newInterval = Integer.parseInt(allowedFrequency);
                                        needsReschedule |= account.setAutomaticCheckIntervalMinutes(newInterval);
                                    }
                                }
                            }
                            account.save(Preferences.getPreferences(RemoteControlService.this));
                        }
                    }
                    Timber.i("RemoteControlService changing global settings");
                    String backgroundOps = intent.getStringExtra(K9_BACKGROUND_OPERATIONS);
                    if (K9RemoteControl.K9_BACKGROUND_OPERATIONS_ALWAYS.equals(backgroundOps) || K9RemoteControl.K9_BACKGROUND_OPERATIONS_NEVER.equals(backgroundOps) || K9RemoteControl.K9_BACKGROUND_OPERATIONS_WHEN_CHECKED_AUTO_SYNC.equals(backgroundOps)) {
                        BACKGROUND_OPS newBackgroundOps = BACKGROUND_OPS.valueOf(backgroundOps);
                        boolean needsReset = K9.setBackgroundOps(newBackgroundOps);
                        needsPushRestart |= needsReset;
                        needsReschedule |= needsReset;
                    }
                    String theme = intent.getStringExtra(K9_THEME);
                    if (theme != null) {
                        K9.setK9Theme(K9RemoteControl.K9_THEME_DARK.equals(theme) ? K9.Theme.DARK : K9.Theme.LIGHT);
                    }
                    Storage storage = preferences.getStorage();
                    StorageEditor editor = storage.edit();
                    K9.save(editor);
                    editor.commit();
                    if (needsReschedule) {
                        Intent i = new Intent(RemoteControlService.this, RemoteControlService.class);
                        i.setAction(RESCHEDULE_ACTION);
                        long nextTime = System.currentTimeMillis() + 10000;
                        BootReceiver.scheduleIntent(RemoteControlService.this, nextTime, i);
                    }
                    if (needsPushRestart) {
                        Intent i = new Intent(RemoteControlService.this, RemoteControlService.class);
                        i.setAction(PUSH_RESTART_ACTION);
                        long nextTime = System.currentTimeMillis() + 10000;
                        BootReceiver.scheduleIntent(RemoteControlService.this, nextTime, i);
                    }
                } catch (Exception e) {
                    Timber.e(e, "Could not handle K9_SET");
                    Toast toast = Toast.makeText(RemoteControlService.this, e.getMessage(), Toast.LENGTH_LONG);
                    toast.show();
                }
            }
        }, RemoteControlService.REMOTE_CONTROL_SERVICE_WAKE_LOCK_TIMEOUT, startId);
    }
    return START_NOT_STICKY;
}
Also used : Account(com.fsck.k9.Account) Intent(android.content.Intent) StorageEditor(com.fsck.k9.preferences.StorageEditor) BACKGROUND_OPS(com.fsck.k9.K9.BACKGROUND_OPS) Storage(com.fsck.k9.preferences.Storage) Toast(android.widget.Toast) Preferences(com.fsck.k9.Preferences)

Example 5 with StorageEditor

use of com.fsck.k9.preferences.StorageEditor in project k-9 by k9mail.

the class MailService method reschedulePoll.

private void reschedulePoll(final boolean hasConnectivity, final boolean doBackground, boolean considerLastCheckEnd) {
    if (!(hasConnectivity && doBackground)) {
        Timber.i("No connectivity, canceling check for %s", getApplication().getPackageName());
        nextCheck = -1;
        cancel();
        return;
    }
    Preferences prefs = Preferences.getPreferences(MailService.this);
    Storage storage = prefs.getStorage();
    int previousInterval = storage.getInt(PREVIOUS_INTERVAL, -1);
    long lastCheckEnd = storage.getLong(LAST_CHECK_END, -1);
    long now = System.currentTimeMillis();
    if (lastCheckEnd > now) {
        Timber.i("The database claims that the last time mail was checked was in the future (%tc). To try to get " + "things back to normal, the last check time has been reset to: %tc", lastCheckEnd, now);
        lastCheckEnd = now;
    }
    int shortestInterval = -1;
    for (Account account : prefs.getAvailableAccounts()) {
        if (account.getAutomaticCheckIntervalMinutes() != -1 && account.getFolderSyncMode() != FolderMode.NONE && (account.getAutomaticCheckIntervalMinutes() < shortestInterval || shortestInterval == -1)) {
            shortestInterval = account.getAutomaticCheckIntervalMinutes();
        }
    }
    StorageEditor editor = storage.edit();
    editor.putInt(PREVIOUS_INTERVAL, shortestInterval);
    editor.commit();
    if (shortestInterval == -1) {
        Timber.i("No next check scheduled for package %s", getApplication().getPackageName());
        nextCheck = -1;
        pollingRequested = false;
        cancel();
    } else {
        long delay = (shortestInterval * (60 * 1000));
        long base = (previousInterval == -1 || lastCheckEnd == -1 || !considerLastCheckEnd ? System.currentTimeMillis() : lastCheckEnd);
        long nextTime = base + delay;
        Timber.i("previousInterval = %d, shortestInterval = %d, lastCheckEnd = %tc, considerLastCheckEnd = %b", previousInterval, shortestInterval, lastCheckEnd, considerLastCheckEnd);
        nextCheck = nextTime;
        pollingRequested = true;
        try {
            Timber.i("Next check for package %s scheduled for %tc", getApplication().getPackageName(), nextTime);
        } catch (Exception e) {
            // I once got a NullPointerException deep in new Date();
            Timber.e(e, "Exception while logging");
        }
        Intent i = new Intent(this, MailService.class);
        i.setAction(ACTION_CHECK_MAIL);
        BootReceiver.scheduleIntent(MailService.this, nextTime, i);
    }
}
Also used : Account(com.fsck.k9.Account) Storage(com.fsck.k9.preferences.Storage) Intent(android.content.Intent) Preferences(com.fsck.k9.Preferences) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Aggregations

StorageEditor (com.fsck.k9.preferences.StorageEditor)14 Preferences (com.fsck.k9.Preferences)6 Storage (com.fsck.k9.preferences.Storage)6 Account (com.fsck.k9.Account)5 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 NetworkType (com.fsck.k9.mail.NetworkType)2 InvalidSettingValueException (com.fsck.k9.preferences.Settings.InvalidSettingValueException)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 Toast (android.widget.Toast)1 BACKGROUND_OPS (com.fsck.k9.K9.BACKGROUND_OPS)1 ServerSettingsSerializer (com.fsck.k9.ServerSettingsSerializer)1 Folder (com.fsck.k9.mail.Folder)1 ServerSettings (com.fsck.k9.mail.ServerSettings)1 LocalFolder (com.fsck.k9.mailstore.LocalFolder)1 LocalStore (com.fsck.k9.mailstore.LocalStore)1 SpecialLocalFoldersCreator (com.fsck.k9.mailstore.SpecialLocalFoldersCreator)1 IOException (java.io.IOException)1 Collections.emptyMap (java.util.Collections.emptyMap)1