Skip to content
Snippets Groups Projects
Commit 316d61a4 authored by John Carlson's avatar John Carlson
Browse files

Try/catch on fetching accounts so that we do not get into a bad state

parent f5eb33a1
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -13,7 +13,7 @@ import com.squareup.moshi.Moshi
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Types.newParameterizedType
import com.squareup.moshi.Types
import timber.log.Timber
 
 
/**
Loading
Loading
@@ -46,15 +46,18 @@ object Prefs {
fun getAccounts(): MutableList<Account> {
val accountsJson = prefs.getString(KEY_ACCOUNTS, null)
if (!accountsJson.isNullOrEmpty()) {
val type = Types.newParameterizedType(List::class.java, Account::class.java)
val adapter = MoshiProvider.moshi.adapter<List<Account>>(type)
val accounts = adapter.fromJson(accountsJson)!!.toMutableList()
Collections.sort(accounts)
Collections.reverse(accounts)
return accounts
} else {
return ArrayList()
try {
val type = Types.newParameterizedType(List::class.java, Account::class.java)
val adapter = MoshiProvider.moshi.adapter<List<Account>>(type)
val accounts = adapter.fromJson(accountsJson)!!.toMutableList()
Collections.sort(accounts)
Collections.reverse(accounts)
return accounts
} catch (e: Exception) {
Timber.e(e)
}
}
return mutableListOf()
}
 
fun setAccounts(accounts: List<Account>) {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment