ProfileInterface rename
This commit is contained in:
parent
bb82f41b9e
commit
312136451b
23 changed files with 51 additions and 62 deletions
|
@ -381,7 +381,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
|||
if (!config.NSCLIENT && !config.PUMPCONTROL)
|
||||
activePlugin.activeAPS.let { fabricPrivacy.firebaseAnalytics.setUserProperty("Aps", it::class.java.simpleName) }
|
||||
activePlugin.activeBgSource.let { fabricPrivacy.firebaseAnalytics.setUserProperty("BgSource", it::class.java.simpleName) }
|
||||
fabricPrivacy.firebaseAnalytics.setUserProperty("Profile", activePlugin.activeProfileInterface.javaClass.simpleName)
|
||||
fabricPrivacy.firebaseAnalytics.setUserProperty("Profile", activePlugin.activeProfileSource.javaClass.simpleName)
|
||||
activePlugin.activeSensitivity.let { fabricPrivacy.firebaseAnalytics.setUserProperty("Sensitivity", it::class.java.simpleName) }
|
||||
activePlugin.activeInsulin.let { fabricPrivacy.firebaseAnalytics.setUserProperty("Insulin", it::class.java.simpleName) }
|
||||
// Add to crash log too
|
||||
|
|
|
@ -98,7 +98,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
|
||||
// Active profile
|
||||
profileList = activePlugin.activeProfileInterface.profile?.getProfileList() ?: ArrayList()
|
||||
profileList = activePlugin.activeProfileSource.profile?.getProfileList() ?: ArrayList()
|
||||
|
||||
binding.availableProfileList.setOnClickListener {
|
||||
PopupMenu(this, binding.availableProfileList).apply {
|
||||
|
@ -233,7 +233,7 @@ class ProfileHelperActivity : NoSplashAppCompatActivity() {
|
|||
ProfileType.MOTOL_DEFAULT -> defaultProfile.profile(age, tdd, weight, profileFunction.getUnits())
|
||||
ProfileType.DPV_DEFAULT -> defaultProfileDPV.profile(age, tdd, basalPct, profileFunction.getUnits())
|
||||
ProfileType.CURRENT -> profileFunction.getProfile()?.convertToNonCustomizedProfile()
|
||||
ProfileType.AVAILABLE_PROFILE -> activePlugin.activeProfileInterface.profile?.getSpecificProfile(profileList[profileUsed[tab]].toString())
|
||||
ProfileType.AVAILABLE_PROFILE -> activePlugin.activeProfileSource.profile?.getSpecificProfile(profileList[profileUsed[tab]].toString())
|
||||
ProfileType.PROFILE_SWITCH -> profileSwitch[profileSwitchUsed[tab]].profileObject?.convertToNonCustomizedProfile()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -41,7 +41,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
|||
|
||||
binding.id.text = InstanceId.instanceId()
|
||||
|
||||
val profileStore = activePlugin.activeProfileInterface.profile
|
||||
val profileStore = activePlugin.activeProfileSource.profile
|
||||
val profileList = profileStore?.getProfileList() ?: return
|
||||
binding.spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, profileList)
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
|
|||
import info.nightscout.androidaps.events.EventReloadProfileSwitchData;
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.ProfileSource;
|
||||
import info.nightscout.androidaps.interfaces.ProfileStore;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
|
@ -873,8 +873,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
if (trJson.has("profileJson"))
|
||||
profileSwitch.profileJson = trJson.getString("profileJson");
|
||||
else {
|
||||
ProfileInterface profileInterface = activePlugin.getActiveProfileInterface();
|
||||
ProfileStore store = profileInterface.getProfile();
|
||||
ProfileSource profileSource = activePlugin.getActiveProfileSource();
|
||||
ProfileStore store = profileSource.getProfile();
|
||||
if (store != null) {
|
||||
Profile profile = store.getSpecificProfile(profileSwitch.profileName);
|
||||
if (profile != null) {
|
||||
|
|
|
@ -198,7 +198,7 @@ class LoopDialog : DaggerDialogFragment() {
|
|||
}
|
||||
}
|
||||
val profile = profileFunction.getProfile()
|
||||
val profileStore = activePlugin.activeProfileInterface.profile
|
||||
val profileStore = activePlugin.activeProfileSource.profile
|
||||
|
||||
if (profile == null || profileStore == null) {
|
||||
ToastUtils.showToastInUiThread(ctx, resourceHelper.gs(R.string.noprofile))
|
||||
|
|
|
@ -68,7 +68,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
|||
|
||||
// profile
|
||||
context?.let { context ->
|
||||
val profileStore = activePlugin.activeProfileInterface.profile
|
||||
val profileStore = activePlugin.activeProfileSource.profile
|
||||
?: return
|
||||
val profileList = profileStore.getProfileList()
|
||||
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
||||
|
@ -103,7 +103,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
|||
|
||||
override fun submit(): Boolean {
|
||||
if (_binding == null) return false
|
||||
val profileStore = activePlugin.activeProfileInterface.profile
|
||||
val profileStore = activePlugin.activeProfileSource.profile
|
||||
?: return false
|
||||
|
||||
val actions: LinkedList<String> = LinkedList()
|
||||
|
|
|
@ -244,7 +244,7 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
|
||||
private fun initDialog() {
|
||||
val profile = profileFunction.getProfile()
|
||||
val profileStore = activePlugin.activeProfileInterface.profile
|
||||
val profileStore = activePlugin.activeProfileSource.profile
|
||||
|
||||
if (profile == null || profileStore == null) {
|
||||
ToastUtils.showToastInUiThread(ctx, resourceHelper.gs(R.string.noprofile))
|
||||
|
@ -283,7 +283,7 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
}
|
||||
|
||||
private fun calculateInsulin() {
|
||||
val profileStore = activePlugin.activeProfileInterface.profile
|
||||
val profileStore = activePlugin.activeProfileSource.profile
|
||||
if (binding.profile.selectedItem == null || profileStore == null)
|
||||
return // not initialized yet
|
||||
var profileName = binding.profile.selectedItem.toString()
|
||||
|
|
|
@ -69,7 +69,7 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
if (p.pluginDescription.alwaysEnabled && p.pluginDescription.neverVisible) continue
|
||||
savePref(p, type, true)
|
||||
if (type == PluginType.PUMP) {
|
||||
if (p is ProfileInterface) { // Store state of optional Profile interface
|
||||
if (p is ProfileSource) { // Store state of optional Profile interface
|
||||
savePref(p, PluginType.PROFILE, false)
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
val type = p.getType()
|
||||
loadPref(p, type, true)
|
||||
if (p.getType() == PluginType.PUMP) {
|
||||
if (p is ProfileInterface) {
|
||||
if (p is ProfileSource) {
|
||||
loadPref(p, PluginType.PROFILE, false)
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
PluginType.INSULIN -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(Insulin::class.java)
|
||||
PluginType.SENSITIVITY -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(Sensitivity::class.java)
|
||||
PluginType.APS -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(APS::class.java)
|
||||
PluginType.PROFILE -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(ProfileInterface::class.java)
|
||||
PluginType.PROFILE -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(ProfileSource::class.java)
|
||||
PluginType.BGSOURCE -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(BgSource::class.java)
|
||||
PluginType.TREATMENT -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(TreatmentsInterface::class.java)
|
||||
PluginType.PUMP -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(Pump::class.java)
|
||||
|
|
|
@ -17,7 +17,7 @@ class PluginStore @Inject constructor(
|
|||
|
||||
private var activeBgSourceStore: BgSource? = null
|
||||
private var activePumpStore: Pump? = null
|
||||
private var activeProfile: ProfileInterface? = null
|
||||
private var activeProfile: ProfileSource? = null
|
||||
private var activeAPSStore: APS? = null
|
||||
private var activeInsulinStore: Insulin? = null
|
||||
private var activeSensitivityStore: Sensitivity? = null
|
||||
|
@ -94,9 +94,9 @@ class PluginStore @Inject constructor(
|
|||
|
||||
// PluginType.PROFILE
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.PROFILE)
|
||||
activeProfile = getTheOneEnabledInArray(pluginsInCategory, PluginType.PROFILE) as ProfileInterface?
|
||||
activeProfile = getTheOneEnabledInArray(pluginsInCategory, PluginType.PROFILE) as ProfileSource?
|
||||
if (activeProfile == null) {
|
||||
activeProfile = getDefaultPlugin(PluginType.PROFILE) as ProfileInterface
|
||||
activeProfile = getDefaultPlugin(PluginType.PROFILE) as ProfileSource
|
||||
(activeProfile as PluginBase).setPluginEnabled(PluginType.PROFILE, true)
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting ProfileInterface")
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ class PluginStore @Inject constructor(
|
|||
override val activeBgSource: BgSource
|
||||
get() = activeBgSourceStore ?: checkNotNull(activeBgSourceStore) { "No bg source selected" }
|
||||
|
||||
override val activeProfileInterface: ProfileInterface
|
||||
override val activeProfileSource: ProfileSource
|
||||
get() = activeProfile ?: checkNotNull(activeProfile) { "No profile selected" }
|
||||
|
||||
override val activeInsulin: Insulin
|
||||
|
|
|
@ -265,7 +265,7 @@ class ActionsFragment : DaggerFragment() {
|
|||
val pump = activePlugin.activePump
|
||||
|
||||
profileSwitch?.visibility = (
|
||||
activePlugin.activeProfileInterface.profile != null &&
|
||||
activePlugin.activeProfileSource.profile != null &&
|
||||
pump.pumpDescription.isSetBasalProfileCapable &&
|
||||
pump.isInitialized() &&
|
||||
!pump.isSuspended()).toVisibility()
|
||||
|
|
|
@ -545,7 +545,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
private fun processPROFILE(divided: Array<String>, receivedSms: Sms) { // load profiles
|
||||
val anInterface = activePlugin.activeProfileInterface
|
||||
val anInterface = activePlugin.activeProfileSource
|
||||
val store = anInterface.profile
|
||||
if (store == null) {
|
||||
sendSMS(Sms(receivedSms.phoneNumber, resourceHelper.gs(R.string.notconfigured)))
|
||||
|
|
|
@ -46,7 +46,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
.description(R.string.description_profile_local)
|
||||
.setDefault(),
|
||||
aapsLogger, resourceHelper, injector
|
||||
), ProfileInterface {
|
||||
), ProfileSource {
|
||||
|
||||
private var rawProfile: ProfileStore? = null
|
||||
|
||||
|
@ -58,6 +58,7 @@ class LocalProfilePlugin @Inject constructor(
|
|||
}
|
||||
|
||||
class SingleProfile {
|
||||
|
||||
internal var name: String? = null
|
||||
internal var mgdl: Boolean = false
|
||||
internal var dia: Double = Constants.defaultDIA
|
||||
|
@ -350,12 +351,10 @@ class LocalProfilePlugin @Inject constructor(
|
|||
return ProfileStore(injector, json)
|
||||
}
|
||||
|
||||
override fun getProfile(): ProfileStore? {
|
||||
return rawProfile
|
||||
}
|
||||
override val profile: ProfileStore?
|
||||
get() = rawProfile
|
||||
|
||||
override fun getProfileName(): String {
|
||||
return DecimalFormatter.to2Decimal(rawProfile?.getDefaultProfile()?.percentageBasalSum()
|
||||
override val profileName: String
|
||||
get() = DecimalFormatter.to2Decimal(rawProfile?.getDefaultProfile()?.percentageBasalSum()
|
||||
?: 0.0) + "U "
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import info.nightscout.androidaps.events.EventProfileStoreChanged
|
|||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface
|
||||
import info.nightscout.androidaps.interfaces.ProfileSource
|
||||
import info.nightscout.androidaps.interfaces.ProfileStore
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -44,9 +44,12 @@ class NSProfilePlugin @Inject constructor(
|
|||
.showInList(!config.NSCLIENT)
|
||||
.description(R.string.description_profile_nightscout),
|
||||
aapsLogger, resourceHelper, injector
|
||||
), ProfileInterface {
|
||||
), ProfileSource {
|
||||
|
||||
private var profile: ProfileStore? = null
|
||||
override var profile: ProfileStore? = null
|
||||
|
||||
override val profileName: String?
|
||||
get() = profile?.getDefaultProfileName()
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
@ -71,13 +74,6 @@ class NSProfilePlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getProfile(): ProfileStore? {
|
||||
return profile
|
||||
}
|
||||
|
||||
override fun getProfileName(): String {
|
||||
return profile!!.getDefaultProfileName()!!
|
||||
}
|
||||
|
||||
// cannot be inner class because of needed injection
|
||||
class NSProfileWorker(
|
||||
|
|
|
@ -380,7 +380,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
profileSwitch.source = Source.USER;
|
||||
profileSwitch.profileName = profileFunction.getProfileName(System.currentTimeMillis(), false, false);
|
||||
profileSwitch.profileJson = profileFunction.getProfile().getData().toString();
|
||||
profileSwitch.profilePlugin = activePlugin.getActiveProfileInterface().getClass().getName();
|
||||
profileSwitch.profilePlugin = activePlugin.getActiveProfileSource().getClass().getName();
|
||||
profileSwitch.durationInMinutes = duration;
|
||||
profileSwitch.isCPP = percentage != 100 || timeShift != 0;
|
||||
profileSwitch.timeshift = timeShift;
|
||||
|
|
|
@ -173,7 +173,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
`when`(iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).thenReturn(IobTotal(0))
|
||||
`when`(treatmentsInterface.service).thenReturn(treatmentService)
|
||||
|
||||
`when`(activePlugin.activeProfileInterface).thenReturn(localProfilePlugin)
|
||||
`when`(activePlugin.activeProfileSource).thenReturn(localProfilePlugin)
|
||||
|
||||
`when`(profileFunction.getUnits()).thenReturn(Constants.MGDL)
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) {
|
|||
callback.result(PumpEnactResult(injector).success(true).comment(R.string.alreadyset))?.run()
|
||||
return
|
||||
}
|
||||
val profileStore = activePlugin.activeProfileInterface.profile ?: return
|
||||
val profileStore = activePlugin.activeProfileSource.profile ?: return
|
||||
if (profileStore.getSpecificProfile(inputProfileName.value) == null) {
|
||||
aapsLogger.error(LTag.AUTOMATION, "Selected profile does not exist! - ${inputProfileName.value}")
|
||||
callback.result(PumpEnactResult(injector).success(false).comment(R.string.notexists))?.run()
|
||||
|
@ -88,5 +88,5 @@ class ActionProfileSwitch(injector: HasAndroidInjector) : Action(injector) {
|
|||
return this
|
||||
}
|
||||
|
||||
override fun isValid(): Boolean = activePlugin.activeProfileInterface.profile?.getSpecificProfile(inputProfileName.value) != null
|
||||
override fun isValid(): Boolean = activePlugin.activeProfileSource.profile?.getSpecificProfile(inputProfileName.value) != null
|
||||
}
|
|
@ -15,7 +15,7 @@ class InputProfileName(private val resourceHelper: ResourceHelper, private val a
|
|||
var value: String = name
|
||||
|
||||
override fun addToLayout(root: LinearLayout) {
|
||||
val profileStore = activePlugin.activeProfileInterface.profile ?: return
|
||||
val profileStore = activePlugin.activeProfileSource.profile ?: return
|
||||
val profileList = profileStore.getProfileList()
|
||||
val adapter = ArrayAdapter(root.context, R.layout.spinner_centered, profileList)
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
|
|
|
@ -42,7 +42,7 @@ open class ActionsTestBase : TestBaseWithProfile() {
|
|||
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||
@Mock lateinit var configBuilder: ConfigBuilder
|
||||
@Mock lateinit var activePlugin: ActivePlugin
|
||||
@Mock lateinit var profilePlugin: ProfileInterface
|
||||
@Mock lateinit var profilePlugin: ProfileSource
|
||||
@Mock lateinit var smsCommunicatorPlugin: SmsCommunicator
|
||||
@Mock lateinit var loopPlugin: TestLoopPlugin
|
||||
@Mock lateinit var uel: UserEntryLogger
|
||||
|
@ -133,7 +133,7 @@ open class ActionsTestBase : TestBaseWithProfile() {
|
|||
testPumpPlugin = TestPumpPlugin(pluginDescription, aapsLogger, resourceHelper, injector)
|
||||
`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
|
||||
`when`(profileFunction.getUnits()).thenReturn(Constants.MGDL)
|
||||
`when`(activePlugin.activeProfileInterface).thenReturn(profilePlugin)
|
||||
`when`(activePlugin.activeProfileSource).thenReturn(profilePlugin)
|
||||
`when`(profilePlugin.profile).thenReturn(getValidProfileStore())
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ interface ActivePlugin {
|
|||
* Currently selected Profile plugin
|
||||
* Default LocalProfile
|
||||
*/
|
||||
val activeProfileInterface: ProfileInterface
|
||||
val activeProfileSource: ProfileSource
|
||||
|
||||
/**
|
||||
* Currently selected Insulin plugin
|
||||
|
|
|
@ -66,9 +66,8 @@ abstract class PluginBase(
|
|||
fun isDefault() = pluginDescription.defaultPlugin
|
||||
|
||||
/**
|
||||
* So far plugin can have it's main type + ConstraintInterface + ProfileInterface
|
||||
* So far plugin can have it's main type + ConstraintInterface
|
||||
* ConstraintInterface is enabled if main plugin is enabled
|
||||
* ProfileInterface can be enabled only if main interface is enable
|
||||
*/
|
||||
fun setPluginEnabled(type: PluginType, newState: Boolean) {
|
||||
if (type == pluginDescription.mainType) {
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Created by mike on 14.06.2016.
|
||||
*/
|
||||
public interface ProfileInterface {
|
||||
@Nullable
|
||||
ProfileStore getProfile();
|
||||
String getProfileName();
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
interface ProfileSource {
|
||||
|
||||
val profile: ProfileStore?
|
||||
val profileName: String?
|
||||
}
|
|
@ -42,7 +42,7 @@ class ProfileFunctionImplementation @Inject constructor(
|
|||
var profileName = resourceHelper.gs(R.string.noprofileselected)
|
||||
|
||||
val activeTreatments = activePlugin.activeTreatments
|
||||
val activeProfile = activePlugin.activeProfileInterface
|
||||
val activeProfile = activePlugin.activeProfileSource
|
||||
|
||||
val profileSwitch = activeTreatments.getProfileSwitchFromHistory(time)
|
||||
if (profileSwitch != null) {
|
||||
|
@ -75,7 +75,7 @@ class ProfileFunctionImplementation @Inject constructor(
|
|||
override fun getProfile(time: Long): Profile? = getProfile(time, activePlugin.activeTreatments)
|
||||
|
||||
override fun getProfile(time: Long, activeTreatments: TreatmentsInterface): Profile? {
|
||||
val activeProfile = activePlugin.activeProfileInterface
|
||||
val activeProfile = activePlugin.activeProfileSource
|
||||
|
||||
//log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time));
|
||||
val profileSwitch = activeTreatments.getProfileSwitchFromHistory(time)
|
||||
|
|
Loading…
Reference in a new issue