Log messages when saving to disk.

This commit is contained in:
Vitor Pamplona
2024-06-05 18:21:20 -04:00
parent ad281c7607
commit 1a56b2bf68

View File

@@ -244,7 +244,8 @@ object LocalPreferences {
* deleted * deleted
*/ */
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
suspend fun updatePrefsForLogout(accountInfo: AccountInfo) = suspend fun updatePrefsForLogout(accountInfo: AccountInfo) {
Log.d("LocalPreferences", "Saving to encrypted storage updatePrefsForLogout")
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val userPrefs = encryptedPreferences(accountInfo.npub) val userPrefs = encryptedPreferences(accountInfo.npub)
userPrefs.edit().clear().commit() userPrefs.edit().clear().commit()
@@ -257,6 +258,7 @@ object LocalPreferences {
updateCurrentAccount(savedAccounts().elementAt(0).npub) updateCurrentAccount(savedAccounts().elementAt(0).npub)
} }
} }
}
suspend fun updatePrefsForLogin(account: Account) { suspend fun updatePrefsForLogin(account: Account) {
setCurrentAccount(account) setCurrentAccount(account)
@@ -267,7 +269,8 @@ object LocalPreferences {
return savedAccounts() return savedAccounts()
} }
suspend fun saveToEncryptedStorage(account: Account) = suspend fun saveToEncryptedStorage(account: Account) {
Log.d("LocalPreferences", "Saving to encrypted storage")
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
checkNotInMainThread() checkNotInMainThread()
@@ -345,6 +348,7 @@ object LocalPreferences {
} }
.apply() .apply()
} }
}
suspend fun loadCurrentAccountFromEncryptedStorage(): Account? { suspend fun loadCurrentAccountFromEncryptedStorage(): Account? {
return currentAccount()?.let { loadCurrentAccountFromEncryptedStorage(it) } return currentAccount()?.let { loadCurrentAccountFromEncryptedStorage(it) }
@@ -354,6 +358,7 @@ object LocalPreferences {
sharedSettings: Settings, sharedSettings: Settings,
prefs: SharedPreferences = encryptedPreferences(), prefs: SharedPreferences = encryptedPreferences(),
) { ) {
Log.d("LocalPreferences", "Saving to shared settings")
with(prefs.edit()) { with(prefs.edit()) {
putString(PrefKeys.SHARED_SETTINGS, Event.mapper.writeValueAsString(sharedSettings)) putString(PrefKeys.SHARED_SETTINGS, Event.mapper.writeValueAsString(sharedSettings))
apply() apply()
@@ -361,6 +366,7 @@ object LocalPreferences {
} }
suspend fun loadSharedSettings(prefs: SharedPreferences = encryptedPreferences()): Settings? { suspend fun loadSharedSettings(prefs: SharedPreferences = encryptedPreferences()): Settings? {
Log.d("LocalPreferences", "Load shared settings")
with(prefs) { with(prefs) {
return try { return try {
getString(PrefKeys.SHARED_SETTINGS, "{}")?.let { Event.mapper.readValue<Settings>(it) } getString(PrefKeys.SHARED_SETTINGS, "{}")?.let { Event.mapper.readValue<Settings>(it) }
@@ -395,8 +401,10 @@ object LocalPreferences {
} }
} }
suspend fun innerLoadCurrentAccountFromEncryptedStorage(npub: String?): Account? = suspend fun innerLoadCurrentAccountFromEncryptedStorage(npub: String?): Account? {
withContext(Dispatchers.IO) { Log.d("LocalPreferences", "Load account from file")
return withContext(Dispatchers.IO) {
checkNotInMainThread() checkNotInMainThread()
return@withContext with(encryptedPreferences(npub)) { return@withContext with(encryptedPreferences(npub)) {
@@ -618,4 +626,5 @@ object LocalPreferences {
return@with account return@with account
} }
} }
}
} }