Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: SP refactor #3733

Open
wants to merge 56 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e898638
Merge branch 'dev' of https://github.com/nightscout/AndroidAPS into rl
MilosKozak Dec 16, 2024
9247767
RL -> kt
MilosKozak Dec 16, 2024
90e7e81
SP -> Preferences #1
MilosKozak Jan 10, 2025
d3d9215
SP -> Preferences #2
MilosKozak Jan 10, 2025
1da1a2d
SP -> Preferences #3
MilosKozak Jan 11, 2025
078ae35
SP -> Preferences #4
MilosKozak Jan 11, 2025
ca6d514
SP -> Preferences #5
MilosKozak Jan 11, 2025
76ec1e0
SP -> Preferences #6
MilosKozak Jan 11, 2025
42a383c
SP -> Preferences #7
MilosKozak Jan 11, 2025
c9c466e
SP -> Preferences #8
MilosKozak Jan 11, 2025
4445d4e
SP -> Preferences #9
MilosKozak Jan 12, 2025
485bdd0
SP -> Preferences #10
MilosKozak Jan 12, 2025
cadd391
Merge branch 'dev' into sprefactor
MilosKozak Jan 13, 2025
5fb825a
SP -> Preferences #10
MilosKozak Jan 14, 2025
fa16fed
Merge remote-tracking branch 'origin/dev' into sprefactor
MilosKozak Jan 14, 2025
3e4b97b
Merge branch 'dev' into sprefactor
MilosKozak Jan 15, 2025
1d617b8
Merge branch 'dev' into rl
MilosKozak Jan 17, 2025
a5b3318
RL: resolve nullability
MilosKozak Jan 17, 2025
9b7938c
RL: kotlin cleanup
MilosKozak Jan 19, 2025
f04dc20
Merge branch 'dev' into sprefactor
MilosKozak Jan 20, 2025
f798220
fix tests
MilosKozak Jan 20, 2025
8fe7feb
Merge branch 'rl' into sprefactor
MilosKozak Jan 21, 2025
ebb4994
Medtronic,RL: migrate preferences
MilosKozak Jan 21, 2025
2b738f1
SP -> Preferences #12
MilosKozak Jan 22, 2025
3256617
SP -> Preferences #13
MilosKozak Jan 22, 2025
ab1f604
Cleanup
MilosKozak Jan 22, 2025
70237e1
Merge remote-tracking branch 'origin/dev' into sprefactor
MilosKozak Jan 22, 2025
4928192
Dash: preferences -> Key
MilosKozak Jan 23, 2025
00459ed
MDT: fix keys (inc)
MilosKozak Jan 23, 2025
dc535d3
Merge branch 'sprefactor' of https://github.com/nightscout/AndroidAPS…
MilosKozak Jan 23, 2025
4912e04
Merge remote-tracking branch 'origin/dev' into sprefactor
MilosKozak Jan 23, 2025
335781f
OmnipodErosPumpPlugin -> kt
MilosKozak Jan 24, 2025
0f50816
Merge remote-tracking branch 'origin/dev' into sprefactor
MilosKozak Jan 29, 2025
8cb5a45
Merge remote-tracking branch 'origin/dev' into sprefactor
MilosKozak Feb 8, 2025
23fb7df
SP -> Preferences #14
MilosKozak Feb 8, 2025
656a3d2
Merge remote-tracking branch 'origin/dev' into sprefactor
MilosKozak Feb 8, 2025
08c268e
SP -> Preferences #15
MilosKozak Feb 8, 2025
8686804
fix tests
MilosKozak Feb 9, 2025
cc90ed9
remove unused files
MilosKozak Feb 9, 2025
57f838b
SP -> Preferences #16
MilosKozak Feb 9, 2025
a309471
SP -> Preferences #17
MilosKozak Feb 9, 2025
dab13ce
SP -> Preferences #18
MilosKozak Feb 9, 2025
f72c587
SP -> Preferences #19
MilosKozak Feb 9, 2025
e98b0c6
SP -> Preferences #20
MilosKozak Feb 9, 2025
be64ae9
SP -> Preferences #21
MilosKozak Feb 9, 2025
7ebdc1d
SP -> Preferences #22
MilosKozak Feb 9, 2025
9f6f9af
SP -> Preferences #23
MilosKozak Feb 9, 2025
e483660
SP -> Preferences #24
MilosKozak Feb 10, 2025
496064e
SP -> Preferences #25
MilosKozak Feb 10, 2025
d3e9cb0
fix tests
MilosKozak Feb 10, 2025
f889629
Merge remote-tracking branch 'origin/dev' into sprefactor
MilosKozak Feb 17, 2025
0e05035
Merge branch 'dev' into sprefactor
MilosKozak Feb 20, 2025
72613da
Merge branch 'sprefactor' of https://github.com/nightscout/AndroidAPS…
MilosKozak Feb 21, 2025
be89334
Merge branch 'dev' into sprefactor
MilosKozak Feb 22, 2025
0eb507d
PluginBaseWithPreferences::beforeImport & afterImport
MilosKozak Feb 22, 2025
5ee5add
Merge branch 'dev' into sprefactor
MilosKozak Feb 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MDT: fix keys (inc)
  • Loading branch information
MilosKozak committed Jan 23, 2025
commit 00459ed501587643d3e74738590634d0c5b27324
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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 incLong(key: String)
fun putBoolean(key: String, value: Boolean)
fun putBoolean(@StringRes resourceID: Int, value: Boolean)
fun putDouble(key: String, value: Double)
Expand All @@ -76,7 +76,7 @@ interface SP {
fun putLong(@StringRes resourceID: Int, value: Long)
fun putInt(key: String, value: Int)
fun putInt(@StringRes resourceID: Int, value: Int)
fun incInt(@StringRes resourceID: Int)
fun incInt(key: String)
fun putString(@StringRes resourceID: Int, value: String)
fun putString(key: String, value: String)
}
8 changes: 8 additions & 0 deletions core/keys/src/main/kotlin/app/aaps/core/keys/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ interface Preferences {
*/
fun get(key: LongPreferenceKey): Long

/**
* Increment [Long] value in [android.content.SharedPreferences]
*
* @param key [LongNonPreferenceKey] enum
* @param value value
*/
fun inc(key: LongNonPreferenceKey)

/**
* Get [String] value from [android.content.SharedPreferences]
* *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class PreferencesImpl @Inject constructor(
}

override fun inc(key: IntNonPreferenceKey) {
sp.putInt(key.key, get(key) + 1)
sp.incInt(key.key)
}

override fun get(key: IntPreferenceKey): Int =
Expand All @@ -170,6 +170,10 @@ class PreferencesImpl @Inject constructor(
override fun get(key: LongNonPreferenceKey): Long =
sp.getLong(key.key, key.defaultValue)

override fun inc(key: LongNonPreferenceKey) {
sp.incLong(key.key)
}

override fun getIfExists(key: LongNonPreferenceKey): Long? =
if (sp.contains(key.key)) sp.getLong(key.key, key.defaultValue) else null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,14 @@ class InternalSP(
}
}

override fun incLong(resourceID: Int) {
val value = getLong(resourceID, 0) + 1L
sharedPreferences.edit().putLong(context.getString(resourceID), value).apply()
override fun incLong(key: String) {
val value = getLong(key, 0) + 1L
sharedPreferences.edit().putLong(key, value).apply()
}

override fun incInt(key: String) {
val value = getInt(key, 0) + 1
sharedPreferences.edit().putInt(key, value).apply()
}

override fun putBoolean(key: String, value: Boolean) = sharedPreferences.edit().putBoolean(key, value).apply()
Expand All @@ -197,11 +202,6 @@ class InternalSP(
override fun putInt(resourceID: Int, value: Int) =
sharedPreferences.edit().putInt(context.getString(resourceID), value).apply()

override fun incInt(resourceID: Int) {
val value = getInt(resourceID, 0) + 1
sharedPreferences.edit().putInt(context.getString(resourceID), value).apply()
}

override fun putString(resourceID: Int, value: String) =
sharedPreferences.edit().putString(context.getString(resourceID), value).apply()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ import app.aaps.pump.medtronic.driver.MedtronicPumpStatus
import app.aaps.pump.medtronic.events.EventMedtronicPumpConfigurationChanged
import app.aaps.pump.medtronic.events.EventMedtronicPumpValuesChanged
import app.aaps.pump.medtronic.keys.MedtronicBooleanPreferenceKey
import app.aaps.pump.medtronic.keys.MedtronicIntNonKey
import app.aaps.pump.medtronic.keys.MedtronicIntPreferenceKey
import app.aaps.pump.medtronic.keys.MedtronicLongNonKey
import app.aaps.pump.medtronic.keys.MedtronicStringPreferenceKey
Expand Down Expand Up @@ -150,7 +149,7 @@ class MedtronicPumpPlugin @Inject constructor(
ownPreferences = listOf(
RileylinkBooleanPreferenceKey::class.java, RileyLinkDoubleKey::class.java, RileyLinkIntentPreferenceKey::class.java,
RileyLinkLongKey::class.java, RileyLinkStringKey::class.java, RileyLinkStringPreferenceKey::class.java,
MedtronicBooleanPreferenceKey::class.java, MedtronicIntNonKey::class.java, MedtronicIntPreferenceKey::class.java,
MedtronicBooleanPreferenceKey::class.java, MedtronicIntPreferenceKey::class.java,
MedtronicLongNonKey::class.java, MedtronicStringPreferenceKey::class.java
),
PumpType.MEDTRONIC_522_722, // we default to most basic model, correct model from config is loaded later
Expand Down Expand Up @@ -675,7 +674,7 @@ class MedtronicPumpPlugin @Inject constructor(

// we subtract insulin, exact amount will be visible with next remainingInsulin update.
medtronicPumpStatus.reservoirRemainingUnits = medtronicPumpStatus.reservoirRemainingUnits - detailedBolusInfo.insulin
preferences.inc(if (detailedBolusInfo.bolusType === BS.Type.SMB) MedtronicIntNonKey.SmbBoluses else MedtronicIntNonKey.StandardBoluses)
preferences.inc(if (detailedBolusInfo.bolusType === BS.Type.SMB) MedtronicLongNonKey.SmbBoluses else MedtronicLongNonKey.StandardBoluses)

// calculate time for bolus and set driver to busy for that time
val bolusTime = (detailedBolusInfo.insulin * 42.0).toInt()
Expand Down Expand Up @@ -787,7 +786,7 @@ class MedtronicPumpPlugin @Inject constructor(
medtronicPumpStatus.runningTBRWithTemp = tempData
pumpSyncStorage.addTemporaryBasalRateWithTempId(tempData, true, this)

preferences.inc(MedtronicIntNonKey.TbrsSet)
preferences.inc(MedtronicLongNonKey.TbrsSet)
finishAction("TBR")
instantiator.providePumpEnactResult().success(true).enacted(true) //
.absolute(absoluteRate).duration(durationInMinutes)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ enum class MedtronicLongNonKey(
override val defaultValue: Long,
) : LongNonPreferenceKey {

TbrsSet("medtronic_tbrs_set", 0),
SmbBoluses("medtronic_smb_boluses_delivered", 0),
StandardBoluses("medtronic_std_boluses_delivered", 0),
FirstPumpUse("medtronic_first_pump_use", 0),
LastGoodPumpCommunicationTime("medtronic_lastGoodPumpCommunicationTime", 0L),
LastPumpHistoryEntry("medtronic_pump_history_entry", 0L),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ class SPImpl @Inject constructor(
SafeParse.stringToLong(sharedPreferences.getString(key, defaultValue.toString()), defaultValue)
}

override fun incLong(resourceID: Int) {
val value = getLong(resourceID, 0) + 1L
sharedPreferences.edit().putLong(context.getString(resourceID), value).apply()
override fun incLong(key: String) {
val value = getLong(key, 0) + 1L
sharedPreferences.edit().putLong(key, value).apply()
}

override fun putBoolean(key: String, value: Boolean) = sharedPreferences.edit().putBoolean(key, value).apply()
Expand All @@ -187,9 +187,9 @@ class SPImpl @Inject constructor(
override fun putInt(resourceID: Int, value: Int) =
sharedPreferences.edit().putInt(context.getString(resourceID), value).apply()

override fun incInt(resourceID: Int) {
val value = getInt(resourceID, 0) + 1
sharedPreferences.edit().putInt(context.getString(resourceID), value).apply()
override fun incInt(key: String) {
val value = getInt(key, 0) + 1
sharedPreferences.edit().putInt(key, value).apply()
}

override fun putString(resourceID: Int, value: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class PreferencesImpl @Inject constructor(
}

override fun inc(key: IntNonPreferenceKey) {
sp.putInt(key.key, get(key) + 1)
sp.incInt(key.key)
}

override fun get(key: IntPreferenceKey): Int = sp.getInt(key.key, key.defaultValue)
Expand All @@ -139,6 +139,10 @@ class PreferencesImpl @Inject constructor(

override fun get(key: LongPreferenceKey): Long = sp.getLong(key.key, key.defaultValue)

override fun inc(key: LongNonPreferenceKey) {
sp.incLong(key.key)
}

override fun remove(key: NonPreferenceKey) {
sp.remove(key.key)
}
Expand Down