From 1a84adf339a3e6617a7981d454520952cc17e09d Mon Sep 17 00:00:00 2001 From: Daniel Schaal Date: Thu, 28 May 2020 17:50:26 +0200 Subject: [PATCH] Move Preference Editor in apply block --- .../schaal/ocreader/OCReaderApplication.kt | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/email/schaal/ocreader/OCReaderApplication.kt b/app/src/main/java/email/schaal/ocreader/OCReaderApplication.kt index bb304be5..262c12bc 100644 --- a/app/src/main/java/email/schaal/ocreader/OCReaderApplication.kt +++ b/app/src/main/java/email/schaal/ocreader/OCReaderApplication.kt @@ -19,8 +19,8 @@ package email.schaal.ocreader import android.app.Application -import androidx.preference.PreferenceManager import androidx.appcompat.app.AppCompatDelegate +import androidx.preference.PreferenceManager import email.schaal.ocreader.database.Queries import email.schaal.ocreader.database.model.Item @@ -32,22 +32,21 @@ class OCReaderApplication : Application() { super.onCreate() val preferences = PreferenceManager.getDefaultSharedPreferences(this) - val editor = preferences.edit() - - // Migrate to apptoken - if(preferences.contains(Preferences.PASSWORD.key)) { - editor - .remove(Preferences.USERNAME.key) - .remove(Preferences.PASSWORD.key) - .remove(Preferences.URL.key) - } - - // Migrate updatedAt to lastModified - if(Preferences.SORT_FIELD.getString(preferences) == "updatedAt") - editor.putString(Preferences.SORT_FIELD.key, Item::lastModified.name) - - editor.putBoolean(Preferences.SYS_SYNC_RUNNING.key, false) - .apply() + + preferences.edit().apply { + // Migrate to apptoken + if (preferences.contains(Preferences.PASSWORD.key)) { + remove(Preferences.USERNAME.key) + remove(Preferences.PASSWORD.key) + remove(Preferences.URL.key) + } + + // Migrate updatedAt to lastModified + if (Preferences.SORT_FIELD.getString(preferences) == "updatedAt") + putString(Preferences.SORT_FIELD.key, Item::lastModified.name) + + putBoolean(Preferences.SYS_SYNC_RUNNING.key, false) + }.apply() AppCompatDelegate.setDefaultNightMode(Preferences.getNightMode(preferences))