Tidepool: improve settings, upload & and enable

This commit is contained in:
Milos Kozak 2023-01-29 22:33:23 +01:00
parent 8db9891140
commit 26c0b7c896
28 changed files with 234 additions and 213 deletions

View file

@ -34,14 +34,14 @@ open class AppModule {
@PluginsListModule.PumpDriver pumpDrivers: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>, @PluginsListModule.PumpDriver pumpDrivers: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsListModule.NotNSClient notNsClient: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>, @PluginsListModule.NotNSClient notNsClient: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsListModule.APS aps: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>, @PluginsListModule.APS aps: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>,
@PluginsListModule.Unfinished unfinished: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>> //@PluginsListModule.Unfinished unfinished: Lazy<Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>>
) )
: List<@JvmSuppressWildcards PluginBase> { : List<@JvmSuppressWildcards PluginBase> {
val plugins = allConfigs.toMutableMap() val plugins = allConfigs.toMutableMap()
if (config.PUMPDRIVERS) plugins += pumpDrivers.get() if (config.PUMPDRIVERS) plugins += pumpDrivers.get()
if (config.APS) plugins += aps.get() if (config.APS) plugins += aps.get()
if (!config.NSCLIENT) plugins += notNsClient.get() if (!config.NSCLIENT) plugins += notNsClient.get()
if (config.isUnfinishedMode()) plugins += unfinished.get() //if (config.isUnfinishedMode()) plugins += unfinished.get()
return plugins.toList().sortedBy { it.first }.map { it.second } return plugins.toList().sortedBy { it.first }.map { it.second }
} }

View file

@ -318,7 +318,7 @@ abstract class PluginsListModule {
abstract fun bindNSClientV3Plugin(plugin: NSClientV3Plugin): PluginBase abstract fun bindNSClientV3Plugin(plugin: NSClientV3Plugin): PluginBase
@Binds @Binds
@Unfinished @NotNSClient
@IntoMap @IntoMap
@IntKey(360) @IntKey(360)
abstract fun bindTidepoolPlugin(plugin: TidepoolPlugin): PluginBase abstract fun bindTidepoolPlugin(plugin: TidepoolPlugin): PluginBase

View file

@ -45,7 +45,7 @@
<string name="mute5min">Mute for 5 minutes</string> <string name="mute5min">Mute for 5 minutes</string>
<string name="mute">Mute</string> <string name="mute">Mute</string>
<string name="success">Success</string> <string name="success">Success</string>
<string name="advancedsettings_title">Advanced Settings</string> <string name="advanced_settings_title">Advanced Settings</string>
<string name="extendedbolusdeliveryerror">Extended bolus delivery error</string> <string name="extendedbolusdeliveryerror">Extended bolus delivery error</string>
<string name="aps_mode_title">APS Mode</string> <string name="aps_mode_title">APS Mode</string>
<string name="extended_bolus">Extended bolus</string> <string name="extended_bolus">Extended bolus</string>

View file

@ -52,7 +52,7 @@
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="absorption_ama_advanced" android:key="absorption_ama_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advanced_settings_title">
<Preference android:summary="@string/openapsama_link_to_preference_json_doc_txt"> <Preference android:summary="@string/openapsama_link_to_preference_json_doc_txt">
<intent <intent

View file

@ -162,7 +162,7 @@
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="absorption_smb_advanced" android:key="absorption_smb_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advanced_settings_title">
<Preference android:summary="@string/openapsama_link_to_preference_json_doc_txt"> <Preference android:summary="@string/openapsama_link_to_preference_json_doc_txt">
<intent <intent

View file

@ -183,7 +183,7 @@
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="absorption_smb_advanced" android:key="absorption_smb_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advanced_settings_title">
<Preference android:summary="@string/openapsama_link_to_preference_json_doc_txt"> <Preference android:summary="@string/openapsama_link_to_preference_json_doc_txt">
<intent <intent

View file

@ -496,7 +496,7 @@
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="overview_advanced" android:key="overview_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advanced_settings_title">
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"

View file

@ -38,7 +38,7 @@
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="absorption_aaps_advanced" android:key="absorption_aaps_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advanced_settings_title">
<info.nightscout.core.validators.ValidatingEditTextPreference <info.nightscout.core.validators.ValidatingEditTextPreference
android:defaultValue="1.2" android:defaultValue="1.2"

View file

@ -37,7 +37,7 @@
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="absorption_oref1_advanced" android:key="absorption_oref1_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advanced_settings_title">
<info.nightscout.core.validators.ValidatingEditTextPreference <info.nightscout.core.validators.ValidatingEditTextPreference
android:defaultValue="1.2" android:defaultValue="1.2"

View file

@ -2,4 +2,4 @@ package info.nightscout.plugins.sync.nsShared.events
import info.nightscout.rx.events.Event import info.nightscout.rx.events.Event
class EventNSConnectivityOptionChanged(val blockingReason: String) : Event() class EventConnectivityOptionChanged(val blockingReason: String) : Event()

View file

@ -63,7 +63,7 @@ class NSClientPlugin @Inject constructor(
private val context: Context, private val context: Context,
private val fabricPrivacy: FabricPrivacy, private val fabricPrivacy: FabricPrivacy,
private val sp: SP, private val sp: SP,
private val nsClientReceiverDelegate: NsClientReceiverDelegate, private val receiverDelegate: ReceiverDelegate,
private val config: Config, private val config: Config,
private val dataSyncSelector: DataSyncSelector, private val dataSyncSelector: DataSyncSelector,
private val uiInteraction: UiInteraction, private val uiInteraction: UiInteraction,
@ -89,14 +89,14 @@ class NSClientPlugin @Inject constructor(
override var status = "" override var status = ""
var nsClientService: NSClientService? = null var nsClientService: NSClientService? = null
val isAllowed: Boolean val isAllowed: Boolean
get() = nsClientReceiverDelegate.allowed get() = receiverDelegate.allowed
val blockingReason: String val blockingReason: String
get() = nsClientReceiverDelegate.blockingReason get() = receiverDelegate.blockingReason
override fun onStart() { override fun onStart() {
context.bindService(Intent(context, NSClientService::class.java), mConnection, Context.BIND_AUTO_CREATE) context.bindService(Intent(context, NSClientService::class.java), mConnection, Context.BIND_AUTO_CREATE)
super.onStart() super.onStart()
nsClientReceiverDelegate.grabReceiversState() receiverDelegate.grabReceiversState()
disposable += rxBus disposable += rxBus
.toObservable(EventNSClientStatus::class.java) .toObservable(EventNSClientStatus::class.java)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)

View file

@ -4,7 +4,7 @@ import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.nsShared.events.EventNSConnectivityOptionChanged import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventChargingState import info.nightscout.rx.events.EventChargingState
@ -19,7 +19,7 @@ import javax.inject.Singleton
@OpenForTesting @OpenForTesting
@Singleton @Singleton
class NsClientReceiverDelegate @Inject constructor( class ReceiverDelegate @Inject constructor(
private val rxBus: RxBus, private val rxBus: RxBus,
private val rh: ResourceHelper, private val rh: ResourceHelper,
private val sp: SP, private val sp: SP,
@ -94,7 +94,7 @@ class NsClientReceiverDelegate @Inject constructor(
if (newAllowedState != allowed) { if (newAllowedState != allowed) {
allowed = newAllowedState allowed = newAllowedState
if (allowed) blockingReason = "" if (allowed) blockingReason = ""
rxBus.send(EventNSConnectivityOptionChanged(blockingReason)) rxBus.send(EventConnectivityOptionChanged(blockingReason))
} }
} }

View file

@ -31,9 +31,9 @@ import info.nightscout.interfaces.utils.JsonHelper.safeGetStringAllowNull
import info.nightscout.interfaces.workflow.WorkerClasses import info.nightscout.interfaces.workflow.WorkerClasses
import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl
import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
import info.nightscout.plugins.sync.nsShared.events.EventNSClientStatus import info.nightscout.plugins.sync.nsShared.events.EventNSClientStatus
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGUI import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGUI
import info.nightscout.plugins.sync.nsShared.events.EventNSConnectivityOptionChanged
import info.nightscout.plugins.sync.nsclient.NSClientPlugin import info.nightscout.plugins.sync.nsclient.NSClientPlugin
import info.nightscout.plugins.sync.nsclient.acks.NSAddAck import info.nightscout.plugins.sync.nsclient.acks.NSAddAck
import info.nightscout.plugins.sync.nsclient.acks.NSAuthAck import info.nightscout.plugins.sync.nsclient.acks.NSAuthAck
@ -149,7 +149,7 @@ class NSClientService : DaggerService() {
} }
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventNSConnectivityOptionChanged::class.java) .toObservable(EventConnectivityOptionChanged::class.java)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.subscribe({ .subscribe({
latestDateInReceivedData = 0 latestDateInReceivedData = 0

View file

@ -39,10 +39,10 @@ import info.nightscout.interfaces.workflow.WorkerClasses
import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.nsShared.NSClientFragment import info.nightscout.plugins.sync.nsShared.NSClientFragment
import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl
import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend import info.nightscout.plugins.sync.nsShared.events.EventNSClientResend
import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGUI import info.nightscout.plugins.sync.nsShared.events.EventNSClientUpdateGUI
import info.nightscout.plugins.sync.nsShared.events.EventNSConnectivityOptionChanged import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
import info.nightscout.plugins.sync.nsclient.NsClientReceiverDelegate
import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolus import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolus
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolusWizard import info.nightscout.plugins.sync.nsclientV3.extensions.toNSBolusWizard
@ -113,7 +113,7 @@ class NSClientV3Plugin @Inject constructor(
private val context: Context, private val context: Context,
private val fabricPrivacy: FabricPrivacy, private val fabricPrivacy: FabricPrivacy,
private val sp: SP, private val sp: SP,
private val nsClientReceiverDelegate: NsClientReceiverDelegate, private val receiverDelegate: ReceiverDelegate,
private val config: Config, private val config: Config,
private val dateUtil: DateUtil, private val dateUtil: DateUtil,
private val uiInteraction: UiInteraction, private val uiInteraction: UiInteraction,
@ -166,8 +166,8 @@ class NSClientV3Plugin @Inject constructor(
internal var nsAndroidClient: NSAndroidClient? = null internal var nsAndroidClient: NSAndroidClient? = null
private val isAllowed get() = nsClientReceiverDelegate.allowed private val isAllowed get() = receiverDelegate.allowed
private val blockingReason get() = nsClientReceiverDelegate.blockingReason private val blockingReason get() = receiverDelegate.blockingReason
val maxAge = T.days(77).msecs() val maxAge = T.days(77).msecs()
internal var newestDataOnServer: LastModified? = null // timestamp of last modification for every collection provided by server internal var newestDataOnServer: LastModified? = null // timestamp of last modification for every collection provided by server
@ -186,9 +186,9 @@ class NSClientV3Plugin @Inject constructor(
setClient("START") setClient("START")
nsClientReceiverDelegate.grabReceiversState() receiverDelegate.grabReceiversState()
disposable += rxBus disposable += rxBus
.toObservable(EventNSConnectivityOptionChanged::class.java) .toObservable(EventConnectivityOptionChanged::class.java)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.subscribe({ ev -> .subscribe({ ev ->
rxBus.send(EventNSClientNewLog("● CONNECTIVITY", ev.blockingReason)) rxBus.send(EventNSClientNewLog("● CONNECTIVITY", ev.blockingReason))

View file

@ -2,9 +2,14 @@ package info.nightscout.plugins.sync.tidepool
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ScrollView import android.widget.ScrollView
import androidx.core.view.MenuProvider
import androidx.lifecycle.Lifecycle
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.R
@ -15,12 +20,13 @@ import info.nightscout.plugins.sync.tidepool.events.EventTidepoolResetData
import info.nightscout.plugins.sync.tidepool.events.EventTidepoolUpdateGUI import info.nightscout.plugins.sync.tidepool.events.EventTidepoolUpdateGUI
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
import javax.inject.Inject import javax.inject.Inject
class TidepoolFragment : DaggerFragment() { class TidepoolFragment : DaggerFragment(), MenuProvider {
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@Inject lateinit var tidepoolPlugin: TidepoolPlugin @Inject lateinit var tidepoolPlugin: TidepoolPlugin
@ -28,6 +34,15 @@ class TidepoolFragment : DaggerFragment() {
@Inject lateinit var sp: SP @Inject lateinit var sp: SP
@Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rh: ResourceHelper
companion object {
const val ID_MENU_LOGIN = 530
const val ID_MENU_SEND_NOW = 531
const val ID_MENU_REMOVE_ALL = 532
const val ID_MENU_FULL_SYNC = 533
}
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
@ -39,15 +54,41 @@ class TidepoolFragment : DaggerFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
_binding = TidepoolFragmentBinding.inflate(inflater, container, false) _binding = TidepoolFragmentBinding.inflate(inflater, container, false)
requireActivity().addMenuProvider(this, viewLifecycleOwner, Lifecycle.State.RESUMED)
return binding.root return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
super.onViewCreated(view, savedInstanceState) menu.add(Menu.FIRST, ID_MENU_LOGIN, 0, rh.gs(info.nightscout.core.ui.R.string.login)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
binding.login.setOnClickListener { tidepoolUploader.doLogin(false) } menu.add(Menu.FIRST, ID_MENU_SEND_NOW, 0, rh.gs(R.string.upload_now)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
binding.uploadnow.setOnClickListener { rxBus.send(EventTidepoolDoUpload()) } menu.add(Menu.FIRST, ID_MENU_REMOVE_ALL, 0, rh.gs(R.string.remove_all)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
binding.removeall.setOnClickListener { rxBus.send(EventTidepoolResetData()) } menu.add(Menu.FIRST, ID_MENU_FULL_SYNC, 0, rh.gs(R.string.full_sync)).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
binding.resertstart.setOnClickListener { sp.putLong(R.string.key_tidepool_last_end, 0) } menu.setGroupDividerEnabled(true)
}
override fun onMenuItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
ID_MENU_LOGIN -> {
tidepoolUploader.doLogin(false)
true
}
ID_MENU_SEND_NOW -> {
rxBus.send(EventTidepoolDoUpload())
true
}
ID_MENU_REMOVE_ALL -> {
rxBus.send(EventTidepoolResetData())
true
}
ID_MENU_FULL_SYNC -> {
sp.putLong(R.string.key_tidepool_last_end, 0)
true
}
else -> false
} }
@Synchronized @Synchronized
@ -56,14 +97,16 @@ class TidepoolFragment : DaggerFragment() {
disposable += rxBus disposable += rxBus
.toObservable(EventTidepoolUpdateGUI::class.java) .toObservable(EventTidepoolUpdateGUI::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe({ .subscribe({ updateGui() }, fabricPrivacy::logException)
if (_binding == null) return@subscribe updateGui()
}
private fun updateGui() {
tidepoolPlugin.updateLog() tidepoolPlugin.updateLog()
binding.log.text = tidepoolPlugin.textLog _binding?.log?.text = tidepoolPlugin.textLog
binding.status.text = tidepoolUploader.connectionStatus.name _binding?.status?.text = tidepoolUploader.connectionStatus.name
binding.log.text = tidepoolPlugin.textLog _binding?.log?.text = tidepoolPlugin.textLog
binding.logscrollview.fullScroll(ScrollView.FOCUS_DOWN) _binding?.logScrollview?.fullScroll(ScrollView.FOCUS_DOWN)
}, fabricPrivacy::logException)
} }
@Synchronized @Synchronized
@ -77,5 +120,4 @@ class TidepoolFragment : DaggerFragment() {
super.onDestroyView() super.onDestroyView()
_binding = null _binding = null
} }
} }

View file

@ -10,11 +10,12 @@ import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.interfaces.sync.Sync import info.nightscout.interfaces.sync.Sync
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.interfaces.utils.HtmlHelper import info.nightscout.interfaces.utils.HtmlHelper
import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.nsShared.events.EventConnectivityOptionChanged
import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
import info.nightscout.plugins.sync.tidepool.comm.TidepoolUploader import info.nightscout.plugins.sync.tidepool.comm.TidepoolUploader
import info.nightscout.plugins.sync.tidepool.comm.UploadChunk import info.nightscout.plugins.sync.tidepool.comm.UploadChunk
import info.nightscout.plugins.sync.tidepool.events.EventTidepoolDoUpload import info.nightscout.plugins.sync.tidepool.events.EventTidepoolDoUpload
@ -24,7 +25,7 @@ import info.nightscout.plugins.sync.tidepool.events.EventTidepoolUpdateGUI
import info.nightscout.plugins.sync.tidepool.utils.RateLimit import info.nightscout.plugins.sync.tidepool.utils.RateLimit
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventNetworkChange import info.nightscout.rx.events.EventNSClientNewLog
import info.nightscout.rx.events.EventNewBG import info.nightscout.rx.events.EventNewBG
import info.nightscout.rx.events.EventPreferenceChange import info.nightscout.rx.events.EventPreferenceChange
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
@ -50,7 +51,7 @@ class TidepoolPlugin @Inject constructor(
private val uploadChunk: UploadChunk, private val uploadChunk: UploadChunk,
private val sp: SP, private val sp: SP,
private val rateLimit: RateLimit, private val rateLimit: RateLimit,
private val receiverStatusStore: ReceiverStatusStore, private val receiverDelegate: ReceiverDelegate,
private val uiInteraction: UiInteraction private val uiInteraction: UiInteraction
) : Sync, PluginBase( ) : Sync, PluginBase(
PluginDescription() PluginDescription()
@ -67,10 +68,18 @@ class TidepoolPlugin @Inject constructor(
private val listLog = ArrayList<EventTidepoolStatus>() private val listLog = ArrayList<EventTidepoolStatus>()
var textLog: Spanned = HtmlHelper.fromHtml("") var textLog: Spanned = HtmlHelper.fromHtml("")
private val isAllowed get() = receiverDelegate.allowed
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
disposable += rxBus
.toObservable(EventConnectivityOptionChanged::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({ ev ->
rxBus.send(EventNSClientNewLog("● CONNECTIVITY", ev.blockingReason))
tidepoolUploader.resetInstance()
if (isAllowed) doUpload()
}, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventTidepoolDoUpload::class.java) .toObservable(EventTidepoolDoUpload::class.java)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
@ -94,17 +103,13 @@ class TidepoolPlugin @Inject constructor(
disposable += rxBus disposable += rxBus
.toObservable(EventNewBG::class.java) .toObservable(EventNewBG::class.java)
.observeOn(aapsSchedulers.io) .observeOn(aapsSchedulers.io)
.filter { it.glucoseValueTimestamp != null } // better would be optional in API level >24 .subscribe({
.map { it.glucoseValueTimestamp!! } it.glucoseValueTimestamp?.let { bgReadingTimestamp ->
.subscribe({ bgReadingTimestamp ->
if (bgReadingTimestamp < uploadChunk.getLastEnd()) if (bgReadingTimestamp < uploadChunk.getLastEnd())
uploadChunk.setLastEnd(bgReadingTimestamp) uploadChunk.setLastEnd(bgReadingTimestamp)
if (isEnabled() if (isAllowed && rateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
&& (!sp.getBoolean(R.string.key_tidepool_only_while_charging, false) || receiverStatusStore.isCharging)
&& (!sp.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || receiverStatusStore.isWifiConnected)
&& rateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt())
)
doUpload() doUpload()
}
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
disposable += rxBus disposable += rxBus
.toObservable(EventPreferenceChange::class.java) .toObservable(EventPreferenceChange::class.java)
@ -116,11 +121,6 @@ class TidepoolPlugin @Inject constructor(
) )
tidepoolUploader.resetInstance() tidepoolUploader.resetInstance()
}, fabricPrivacy::logException) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNetworkChange::class.java)
.observeOn(aapsSchedulers.io)
.subscribe({}, fabricPrivacy::logException) // TODO start upload on wifi connect
} }
override fun onStop() { override fun onStop() {

View file

@ -5,8 +5,8 @@ import android.os.PowerManager
import android.os.SystemClock import android.os.SystemClock
import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.dialogs.OKDialog
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.plugins.sync.R import info.nightscout.plugins.sync.R
import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
import info.nightscout.plugins.sync.tidepool.events.EventTidepoolStatus import info.nightscout.plugins.sync.tidepool.events.EventTidepoolStatus
import info.nightscout.plugins.sync.tidepool.messages.AuthReplyMessage import info.nightscout.plugins.sync.tidepool.messages.AuthReplyMessage
import info.nightscout.plugins.sync.tidepool.messages.AuthRequestMessage import info.nightscout.plugins.sync.tidepool.messages.AuthRequestMessage
@ -37,11 +37,12 @@ class TidepoolUploader @Inject constructor(
private val rh: ResourceHelper, private val rh: ResourceHelper,
private val sp: SP, private val sp: SP,
private val uploadChunk: UploadChunk, private val uploadChunk: UploadChunk,
private val activePlugin: ActivePlugin,
private val dateUtil: DateUtil, private val dateUtil: DateUtil,
private val receiverDelegate: ReceiverDelegate,
private val config: Config private val config: Config
) { ) {
private val isAllowed get() = receiverDelegate.allowed
private var wl: PowerManager.WakeLock? = null private var wl: PowerManager.WakeLock? = null
companion object { companion object {
@ -57,7 +58,7 @@ class TidepoolUploader @Inject constructor(
private var session: Session? = null private var session: Session? = null
enum class ConnectionStatus { enum class ConnectionStatus {
DISCONNECTED, CONNECTING, CONNECTED, FAILED BLOCKED, DISCONNECTED, CONNECTING, CONNECTED, FAILED
} }
var connectionStatus: ConnectionStatus = ConnectionStatus.DISCONNECTED var connectionStatus: ConnectionStatus = ConnectionStatus.DISCONNECTED
@ -87,7 +88,6 @@ class TidepoolUploader @Inject constructor(
return Session(AuthRequestMessage.getAuthRequestHeader(sp), SESSION_TOKEN_HEADER, service) return Session(AuthRequestMessage.getAuthRequestHeader(sp), SESSION_TOKEN_HEADER, service)
} }
// TODO: call on preference change
fun resetInstance() { fun resetInstance() {
retrofit = null retrofit = null
aapsLogger.debug(LTag.TIDEPOOL, "Instance reset") aapsLogger.debug(LTag.TIDEPOOL, "Instance reset")
@ -96,6 +96,11 @@ class TidepoolUploader @Inject constructor(
@Synchronized @Synchronized
fun doLogin(doUpload: Boolean = false) { fun doLogin(doUpload: Boolean = false) {
if (!isAllowed) {
connectionStatus = ConnectionStatus.BLOCKED
aapsLogger.debug(LTag.TIDEPOOL, "Blocked by connectivity settings")
return
}
if (connectionStatus == ConnectionStatus.CONNECTED || connectionStatus == ConnectionStatus.CONNECTING) { if (connectionStatus == ConnectionStatus.CONNECTED || connectionStatus == ConnectionStatus.CONNECTING) {
aapsLogger.debug(LTag.TIDEPOOL, "Already connected") aapsLogger.debug(LTag.TIDEPOOL, "Already connected")
return return
@ -139,7 +144,6 @@ class TidepoolUploader @Inject constructor(
"Failed to log into Tidepool.\nCheck that your user name and password are correct." "Failed to log into Tidepool.\nCheck that your user name and password are correct."
) )
})) }))
} }
?: OKDialog.show(rootContext, rh.gs(R.string.tidepool), "Cannot do login as user credentials have not been set correctly") ?: OKDialog.show(rootContext, rh.gs(R.string.tidepool), "Cannot do login as user credentials have not been set correctly")
@ -197,6 +201,11 @@ class TidepoolUploader @Inject constructor(
@Synchronized @Synchronized
fun doUpload() { fun doUpload() {
if (!isAllowed) {
connectionStatus = ConnectionStatus.BLOCKED
aapsLogger.debug(LTag.TIDEPOOL, "Blocked by connectivity settings")
return
}
session.let { session -> session.let { session ->
if (session == null) { if (session == null) {
aapsLogger.error("Session is null, cannot proceed") aapsLogger.error("Session is null, cannot proceed")
@ -231,7 +240,7 @@ class TidepoolUploader @Inject constructor(
releaseWakeLock() releaseWakeLock()
uploadNext() uploadNext()
}, { }, {
connectionStatus = ConnectionStatus.FAILED connectionStatus = ConnectionStatus.DISCONNECTED
rxBus.send(EventTidepoolStatus(("Upload FAILED"))) rxBus.send(EventTidepoolStatus(("Upload FAILED")))
releaseWakeLock() releaseWakeLock()
})) }))
@ -242,6 +251,11 @@ class TidepoolUploader @Inject constructor(
} }
private fun uploadNext() { private fun uploadNext() {
if (!isAllowed) {
connectionStatus = ConnectionStatus.BLOCKED
aapsLogger.debug(LTag.TIDEPOOL, "Blocked by connectivity settings")
return
}
if (uploadChunk.getLastEnd() < dateUtil.now() - T.mins(1).msecs()) { if (uploadChunk.getLastEnd() < dateUtil.now() - T.mins(1).msecs()) {
SystemClock.sleep(3000) SystemClock.sleep(3000)
aapsLogger.debug(LTag.TIDEPOOL, "Restarting doUpload. Last: " + dateUtil.dateAndTimeString(uploadChunk.getLastEnd())) aapsLogger.debug(LTag.TIDEPOOL, "Restarting doUpload. Last: " + dateUtil.dateAndTimeString(uploadChunk.getLastEnd()))

View file

@ -69,15 +69,10 @@ class UploadChunk @Inject constructor(
val records = LinkedList<BaseElement>() val records = LinkedList<BaseElement>()
if (sp.getBoolean(R.string.key_tidepool_upload_bolus, true))
records.addAll(getTreatments(start, end)) records.addAll(getTreatments(start, end))
if (sp.getBoolean(R.string.key_tidepool_upload_bg, true))
records.addAll(getBloodTests(start, end)) records.addAll(getBloodTests(start, end))
if (sp.getBoolean(R.string.key_tidepool_upload_tbr, true))
records.addAll(getBasals(start, end)) records.addAll(getBasals(start, end))
if (sp.getBoolean(R.string.key_tidepool_upload_cgm, true))
records.addAll(getBgReadings(start, end)) records.addAll(getBgReadings(start, end))
if (sp.getBoolean(R.string.key_tidepool_upload_profile, true))
records.addAll(getProfiles(start, end)) records.addAll(getProfiles(start, end))
return GsonInstance.defaultGsonInstance().toJson(records) return GsonInstance.defaultGsonInstance().toJson(records)

View file

@ -35,14 +35,21 @@ class ProfileElement(ps: EffectiveProfileSwitch, serialNumber: String, dateUtil:
init { init {
type = "pumpSettings" type = "pumpSettings"
val profile: Profile = ProfileSealed.EPS(ps) val profile: Profile = ProfileSealed.EPS(ps)
for (br in profile.getBasalValues()) // for (br in profile.getBasalValues())
basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value)) // basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value))
for (target in profile.getSingleTargetsMgdl()) // for (target in profile.getSingleTargetsMgdl())
bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, target.value.toInt())) // bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, target.value.toInt()))
for (ic in profile.getIcsValues()) // for (ic in profile.getIcsValues())
carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value.toInt())) // carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value.toInt()))
for (isf in profile.getIsfsMgdlValues()) // for (isf in profile.getIsfsMgdlValues())
insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, isf.value.toInt())) // insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, isf.value.toInt()))
for (hour in 0..23) {
val seconds = hour * 3600
basalSchedules.Normal.add(BasalRate(seconds * 1000, profile.getBasalTimeFromMidnight(seconds)))
bgTargets.Normal.add(Target(seconds * 1000, Profile.toMgdl((((profile.getTargetLowMgdlTimeFromMidnight(seconds) + profile.getTargetLowMgdlTimeFromMidnight(seconds))) / 2)).toInt()))
carbRatios.Normal.add(Ratio(seconds * 1000, profile.getIcTimeFromMidnight(seconds).toInt()))
insulinSensitivities.Normal.add(Ratio(seconds * 1000, profile.getIsfMgdlTimeFromMidnight(seconds).toInt()))
}
} }
inner class BasalProfile internal constructor( inner class BasalProfile internal constructor(

View file

@ -3,7 +3,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
tools:context=".sync.nsShared.NSClientFragment"> tools:context="info.nightscout.plugins.sync.nsShared.NSClientFragment">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -1,82 +1,46 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
tools:context="info.nightscout.plugins.sync.tidepool.TidepoolFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:text="@string/status"
tools:ignore="RtlHardcoded" />
<TextView <TextView
android:id="@+id/status" android:id="@+id/status"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="1dp"
android:layout_marginTop="32dp"
android:text="-"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<com.google.android.material.button.MaterialButton
android:id="@+id/login"
style="@style/GrayButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:textStyle="normal|bold" />
android:text="@string/login"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/status" />
<com.google.android.material.button.MaterialButton </LinearLayout>
android:id="@+id/uploadnow"
style="@style/GrayButton"
android:layout_width="113dp"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:text="@string/upload_now"
app:layout_constraintStart_toEndOf="@+id/login"
app:layout_constraintTop_toBottomOf="@+id/status" />
<com.google.android.material.button.MaterialButton
android:id="@+id/removeall"
style="@style/GrayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:text="@string/remove_all"
app:layout_constraintStart_toEndOf="@+id/uploadnow"
app:layout_constraintTop_toBottomOf="@+id/status" />
<com.google.android.material.button.MaterialButton
android:id="@+id/resertstart"
style="@style/GrayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="8dp"
android:text="@string/reset_start"
app:layout_constraintStart_toEndOf="@+id/removeall"
app:layout_constraintTop_toBottomOf="@+id/status" />
<ScrollView <ScrollView
android:id="@+id/logscrollview" android:id="@+id/log_scrollview"
android:layout_width="0dp" android:layout_width="fill_parent"
android:layout_height="0dp" android:layout_height="fill_parent"
android:layout_marginStart="8dp" android:layout_marginStart="5dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="5dp">
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/login"
app:layout_constraintVertical_bias="0.023">
<TextView <TextView
android:id="@+id/log" android:id="@+id/log"
android:layout_width="match_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="-- logs --" android:text="" />
tools:ignore="HardcodedText" />
</ScrollView> </ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>

View file

@ -115,14 +115,7 @@
<string name="key_tidepool_password" translatable="false">tidepool_password</string> <string name="key_tidepool_password" translatable="false">tidepool_password</string>
<string name="key_tidepool_dev_servers" translatable="false">tidepool_dev_servers</string> <string name="key_tidepool_dev_servers" translatable="false">tidepool_dev_servers</string>
<string name="key_tidepool_test_login" translatable="false">tidepool_test_login</string> <string name="key_tidepool_test_login" translatable="false">tidepool_test_login</string>
<string name="key_tidepool_only_while_charging" translatable="false">tidepool_only_while_charging</string>
<string name="key_tidepool_only_while_unmetered" translatable="false">tidepool_only_while_unmetered</string>
<string name="key_tidepool_last_end" translatable="false">tidepool_last_end</string> <string name="key_tidepool_last_end" translatable="false">tidepool_last_end</string>
<string name="key_tidepool_upload_profile" translatable="false">tidepool_upload_profile</string>
<string name="key_tidepool_upload_tbr" translatable="false">tidepool_upload_tbr</string>
<string name="key_tidepool_upload_cgm" translatable="false">tidepool_upload_cgm</string>
<string name="key_tidepool_upload_bolus" translatable="false">tidepool_upload_bolus</string>
<string name="key_tidepool_upload_bg" translatable="false">tidepool_upload_bg</string>
<string name="summary_tidepool_username">Your Tidepool login user name, normally your email address</string> <string name="summary_tidepool_username">Your Tidepool login user name, normally your email address</string>
<string name="title_tidepool_username">Login User Name</string> <string name="title_tidepool_username">Login User Name</string>

View file

@ -178,14 +178,13 @@
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="nsclient_advanced" android:key="nsclient_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advanced_settings_title">
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/key_ns_log_app_started_event" android:key="@string/key_ns_log_app_started_event"
android:title="@string/ns_log_app_started_event" android:title="@string/ns_log_app_started_event"
android:summary="@string/ns_log_app_started_event" android:summary="@string/ns_log_app_started_event" />
/>
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"

View file

@ -184,14 +184,13 @@
<androidx.preference.PreferenceScreen <androidx.preference.PreferenceScreen
android:key="nsclient_advanced" android:key="nsclient_advanced"
android:title="@string/advancedsettings_title"> android:title="@string/advanced_settings_title">
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/key_ns_log_app_started_event" android:key="@string/key_ns_log_app_started_event"
android:title="@string/ns_log_app_started_event" android:title="@string/ns_log_app_started_event"
android:summary="@string/ns_log_app_started_event" android:summary="@string/ns_log_app_started_event" />
/>
<SwitchPreference <SwitchPreference
android:defaultValue="true" android:defaultValue="true"

View file

@ -24,49 +24,57 @@
android:key="@string/key_tidepool_test_login" android:key="@string/key_tidepool_test_login"
android:title="@string/title_tidepool_test_login" /> android:title="@string/title_tidepool_test_login" />
<CheckBoxPreference <androidx.preference.PreferenceScreen
android:key="@string/connection_settings_title"
android:title="@string/connection_settings_title">
<SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="@string/key_tidepool_upload_cgm" android:key="@string/key_ns_cellular"
android:title="@string/tidepool_upload_cgm" /> android:title="@string/ns_cellular" />
<SwitchPreference
android:defaultValue="true"
android:dependency="@string/key_ns_cellular"
android:key="@string/key_ns_allow_roaming"
android:title="@string/ns_allow_roaming" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/key_ns_wifi"
android:title="@string/ns_wifi" />
<EditTextPreference
android:dialogMessage="@string/ns_wifi_allowed_ssids"
android:dependency="@string/key_ns_wifi"
android:inputType="text"
android:key="@string/key_ns_wifi_ssids"
android:title="@string/ns_wifi_ssids" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/key_ns_battery"
android:title="@string/ns_battery" />
<SwitchPreference
android:defaultValue="true"
android:key="@string/key_ns_charging"
android:title="@string/ns_charging" />
</androidx.preference.PreferenceScreen>
<androidx.preference.PreferenceScreen
android:key="nsclient_advanced"
android:title="@string/advanced_settings_title">
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="false"
android:key="@string/key_tidepool_upload_bolus"
android:title="@string/tidepool_upload_bolus" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_tidepool_upload_bg"
android:title="@string/tidepool_upload_bg" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_tidepool_upload_tbr"
android:title="@string/tidepool_upload_tbr" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_tidepool_upload_profile"
android:title="@string/tidepool_upload_profile" />
<CheckBoxPreference
android:defaultValue="true"
android:enabled="false"
android:key="@string/key_tidepool_dev_servers" android:key="@string/key_tidepool_dev_servers"
android:summary="@string/summary_tidepool_dev_servers" android:summary="@string/summary_tidepool_dev_servers"
android:title="@string/title_tidepool_dev_servers" /> android:title="@string/title_tidepool_dev_servers" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_tidepool_only_while_charging"
android:summary="Upload data only when charging"
android:title="Only when charging" />
<CheckBoxPreference </androidx.preference.PreferenceScreen>
android:defaultValue="false"
android:key="@string/key_tidepool_only_while_unmetered"
android:summary="Upload data only when connected to an unmetered network like Wifi"
android:title="Only on Wifi" />
</PreferenceCategory> </PreferenceCategory>

View file

@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
class NsClientReceiverDelegateTest : TestBase() { class ReceiverDelegateTest : TestBase() {
@Mock lateinit var sp: SP @Mock lateinit var sp: SP
@Mock lateinit var rh: ResourceHelper @Mock lateinit var rh: ResourceHelper
@ -23,12 +23,12 @@ class NsClientReceiverDelegateTest : TestBase() {
private val rxBus = RxBus(aapsSchedulers, aapsLogger) private val rxBus = RxBus(aapsSchedulers, aapsLogger)
@Mock private lateinit var receiverStatusStore: ReceiverStatusStore @Mock private lateinit var receiverStatusStore: ReceiverStatusStore
private lateinit var sut: NsClientReceiverDelegate private lateinit var sut: ReceiverDelegate
@BeforeEach @BeforeEach
fun prepare() { fun prepare() {
//receiverStatusStore = ReceiverStatusStore(context, rxBus) //receiverStatusStore = ReceiverStatusStore(context, rxBus)
sut = NsClientReceiverDelegate(rxBus, rh, sp, receiverStatusStore, aapsSchedulers, fabricPrivacy) sut = ReceiverDelegate(rxBus, rh, sp, receiverStatusStore, aapsSchedulers, fabricPrivacy)
} }
@Test @Test

View file

@ -30,7 +30,7 @@ import info.nightscout.interfaces.sync.DataSyncSelector
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.interfaces.workflow.WorkerClasses import info.nightscout.interfaces.workflow.WorkerClasses
import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl
import info.nightscout.plugins.sync.nsclient.NsClientReceiverDelegate import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
import info.nightscout.plugins.sync.nsclient.extensions.fromConstant import info.nightscout.plugins.sync.nsclient.extensions.fromConstant
import info.nightscout.sdk.interfaces.NSAndroidClient import info.nightscout.sdk.interfaces.NSAndroidClient
@ -49,7 +49,7 @@ import org.mockito.internal.verification.Times
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
internal class NSClientV3PluginTest : TestBaseWithProfile() { internal class NSClientV3PluginTest : TestBaseWithProfile() {
@Mock lateinit var nsClientReceiverDelegate: NsClientReceiverDelegate @Mock lateinit var receiverDelegate: ReceiverDelegate
@Mock lateinit var uiInteraction: UiInteraction @Mock lateinit var uiInteraction: UiInteraction
@Mock lateinit var dataSyncSelector: DataSyncSelector @Mock lateinit var dataSyncSelector: DataSyncSelector
@Mock lateinit var nsAndroidClient: NSAndroidClient @Mock lateinit var nsAndroidClient: NSAndroidClient
@ -77,7 +77,7 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
sut = sut =
NSClientV3Plugin( NSClientV3Plugin(
injector, aapsLogger, aapsSchedulers, rxBus, rh, context, fabricPrivacy, injector, aapsLogger, aapsSchedulers, rxBus, rh, context, fabricPrivacy,
sp, nsClientReceiverDelegate, config, dateUtil, uiInteraction, dataSyncSelector, mockedProfileFunction, repository, sp, receiverDelegate, config, dateUtil, uiInteraction, dataSyncSelector, mockedProfileFunction, repository,
nsDeviceStatusHandler, workManager, workerClasses, dataWorkerStorage, nsClientSource nsDeviceStatusHandler, workManager, workerClasses, dataWorkerStorage, nsClientSource
) )
sut.nsAndroidClient = nsAndroidClient sut.nsAndroidClient = nsAndroidClient

View file

@ -22,7 +22,7 @@ import info.nightscout.interfaces.source.NSClientSource
import info.nightscout.interfaces.sync.DataSyncSelector import info.nightscout.interfaces.sync.DataSyncSelector
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.interfaces.workflow.WorkerClasses import info.nightscout.interfaces.workflow.WorkerClasses
import info.nightscout.plugins.sync.nsclient.NsClientReceiverDelegate import info.nightscout.plugins.sync.nsclient.ReceiverDelegate
import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin
import info.nightscout.plugins.sync.nsclientV3.extensions.toNSSvgV3 import info.nightscout.plugins.sync.nsclientV3.extensions.toNSSvgV3
@ -66,7 +66,7 @@ internal class LoadBgWorkerTest : TestBase() {
private val rxBus: RxBus = RxBus(aapsSchedulers, aapsLogger) private val rxBus: RxBus = RxBus(aapsSchedulers, aapsLogger)
private lateinit var nsClientV3Plugin: NSClientV3Plugin private lateinit var nsClientV3Plugin: NSClientV3Plugin
private lateinit var nsClientReceiverDelegate: NsClientReceiverDelegate private lateinit var receiverDelegate: ReceiverDelegate
private lateinit var dataWorkerStorage: DataWorkerStorage private lateinit var dataWorkerStorage: DataWorkerStorage
private lateinit var sut: LoadBgWorker private lateinit var sut: LoadBgWorker
@ -97,10 +97,10 @@ internal class LoadBgWorkerTest : TestBase() {
Mockito.`when`(dateUtil.now()).thenReturn(now) Mockito.`when`(dateUtil.now()).thenReturn(now)
Mockito.`when`(nsClientSource.isEnabled()).thenReturn(true) Mockito.`when`(nsClientSource.isEnabled()).thenReturn(true)
dataWorkerStorage = DataWorkerStorage(context) dataWorkerStorage = DataWorkerStorage(context)
nsClientReceiverDelegate = NsClientReceiverDelegate(rxBus, rh, sp, receiverStatusStore, aapsSchedulers, fabricPrivacy) receiverDelegate = ReceiverDelegate(rxBus, rh, sp, receiverStatusStore, aapsSchedulers, fabricPrivacy)
nsClientV3Plugin = NSClientV3Plugin( nsClientV3Plugin = NSClientV3Plugin(
injector, aapsLogger, aapsSchedulers, rxBus, rh, context, fabricPrivacy, injector, aapsLogger, aapsSchedulers, rxBus, rh, context, fabricPrivacy,
sp, nsClientReceiverDelegate, config, dateUtil, uiInteraction, dataSyncSelector, profileFunction, repository, sp, receiverDelegate, config, dateUtil, uiInteraction, dataSyncSelector, profileFunction, repository,
nsDeviceStatusHandler, workManager, workerClasses, dataWorkerStorage, nsClientSource nsDeviceStatusHandler, workManager, workerClasses, dataWorkerStorage, nsClientSource
) )
nsClientV3Plugin.newestDataOnServer = LastModified(LastModified.Collections()) nsClientV3Plugin.newestDataOnServer = LastModified(LastModified.Collections())