smilecs
02/12/2019, 9:12 AMSharedPreference
operation with a Rx
call?
kinda something like
fun save(key: String, value: String) {
sharedPreferences.edit().putString(key, value).apply()
}
fun saveSingle(key: String, value: String): Single<String> = Single.create {
try {
save(key, value)
it.onSuccess(value)
} catch (e: Exception) {
it.onError(Failure.Error(e.localizedMessage))
}
}
gildor
02/12/2019, 9:13 AMsmilecs
02/12/2019, 9:14 AMgildor
02/12/2019, 9:15 AMsmilecs
02/12/2019, 9:15 AMgildor
02/12/2019, 9:17 AMSingle.fromCallable
, which is mostly the same, but without wrapping to Failure.Error
gildor
02/12/2019, 9:17 AMFailure.Error
is bad style, because you lose stack trace and cause of exceptionsmilecs
02/12/2019, 9:19 AMSingle.fromCallable
will check it out as wellgildor
02/12/2019, 9:22 AMsmilecs
02/12/2019, 9:27 AMdewildte
02/12/2019, 3:36 PMMap
(over simplification I know) so it can be used from the main thread without issue.
That said though it is not a database so be very careful with how much you store in it.