Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
Move Preference Editor in apply block
Browse files Browse the repository at this point in the history
  • Loading branch information
schaal committed May 28, 2020
1 parent ca67a6d commit 1a84adf
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions app/src/main/java/email/schaal/ocreader/OCReaderApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))

Expand Down

0 comments on commit 1a84adf

Please sign in to comment.