catch NPE

This commit is contained in:
Milos Kozak 2021-11-08 16:38:07 +01:00
parent 7cd136bf23
commit a5955b86f9
3 changed files with 12 additions and 6 deletions

View file

@ -650,11 +650,7 @@ public class ComboPlugin extends PumpPluginBase implements Pump, Constraints {
}
private void incrementBolusCount() {
try {
sp.putLong(R.string.combo_boluses_delivered, sp.getLong(R.string.combo_boluses_delivered, 0L) + 1);
} catch (Exception e) {
// ignore
}
sp.incLong(R.string.combo_boluses_delivered);
}
public Long getTbrsSet() {

View file

@ -26,6 +26,7 @@ interface SP {
fun getInt(key: String, defaultValue: Int): Int
fun getLong(@StringRes resourceID: Int, defaultValue: Long): Long
fun getLong(key: String, defaultValue: Long): Long
fun incLong(@StringRes resourceID: Int)
fun putBoolean(key: String, value: Boolean)
fun putBoolean(@StringRes resourceID: Int, value: Boolean)
fun putDouble(key: String, value: Double)

View file

@ -82,7 +82,11 @@ class SPImplementation @Inject constructor(
return try {
sharedPreferences.getLong(rh.gs(resourceID), defaultValue)
} catch (e: Exception) {
SafeParse.stringToLong(sharedPreferences.getString(rh.gs(resourceID), defaultValue.toString()))
try {
SafeParse.stringToLong(sharedPreferences.getString(rh.gs(resourceID), defaultValue.toString()))
} catch (e: Exception) {
defaultValue
}
}
}
@ -98,6 +102,11 @@ class SPImplementation @Inject constructor(
}
}
override fun incLong(resourceID: Int) {
val value = getLong(resourceID, 0) + 1L
sharedPreferences.edit().putLong(rh.gs(resourceID), value).apply()
}
override fun putBoolean(key: String, value: Boolean) = sharedPreferences.edit().putBoolean(key, value).apply()
override fun putBoolean(resourceID: Int, value: Boolean) =