eliminate NSCleintService interface
This commit is contained in:
parent
479ceabe9d
commit
3a29e8d4f2
|
@ -11,7 +11,6 @@ interface NsClient : Sync {
|
|||
|
||||
val version: Version
|
||||
val address: String
|
||||
val nsClientService: NSClientService?
|
||||
|
||||
fun pause(newState: Boolean)
|
||||
fun resend(reason: String)
|
||||
|
@ -24,9 +23,6 @@ interface NsClient : Sync {
|
|||
|
||||
fun resetToFullSync()
|
||||
|
||||
interface NSClientService {
|
||||
|
||||
fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String)
|
||||
fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String)
|
||||
}
|
||||
fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String)
|
||||
fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String)
|
||||
}
|
|
@ -159,7 +159,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
bolus.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd(
|
||||
activePlugin.activeNsClient?.dbAdd(
|
||||
"treatments",
|
||||
bolus.first.toJson(true, dateUtil),
|
||||
DataSyncSelector.PairBolus(bolus.first, bolus.second.id),
|
||||
|
@ -167,7 +167,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
)
|
||||
// with nsId = update if it's modified record
|
||||
bolus.first.interfaceIDs.nightscoutId != null && bolus.first.id != bolus.second.id ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
bolus.first.interfaceIDs.nightscoutId,
|
||||
bolus.first.toJson(false, dateUtil),
|
||||
|
@ -222,10 +222,10 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
carb.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd("treatments", carb.first.toJson(true, dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second.id), "$startId/$lastDbId")
|
||||
activePlugin.activeNsClient?.dbAdd("treatments", carb.first.toJson(true, dateUtil), DataSyncSelector.PairCarbs(carb.first, carb.second.id), "$startId/$lastDbId")
|
||||
// with nsId = update if it's modified record
|
||||
carb.first.interfaceIDs.nightscoutId != null && carb.first.id != carb.second.id ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
carb.first.interfaceIDs.nightscoutId,
|
||||
carb.first.toJson(false, dateUtil),
|
||||
|
@ -280,7 +280,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
bolusCalculatorResult.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd(
|
||||
activePlugin.activeNsClient?.dbAdd(
|
||||
"treatments",
|
||||
bolusCalculatorResult.first.toJson(true, dateUtil, profileFunction),
|
||||
DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id),
|
||||
|
@ -288,7 +288,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
)
|
||||
// with nsId = update if it's modified record
|
||||
bolusCalculatorResult.first.interfaceIDs.nightscoutId != null && bolusCalculatorResult.first.id != bolusCalculatorResult.second.id ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments", bolusCalculatorResult.first.interfaceIDs.nightscoutId, bolusCalculatorResult.first.toJson(false, dateUtil, profileFunction),
|
||||
DataSyncSelector.PairBolusCalculatorResult(bolusCalculatorResult.first, bolusCalculatorResult.second.id), "$startId/$lastDbId"
|
||||
)
|
||||
|
@ -340,7 +340,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
tt.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd(
|
||||
activePlugin.activeNsClient?.dbAdd(
|
||||
"treatments",
|
||||
tt.first.toJson(true, profileFunction.getUnits(), dateUtil),
|
||||
DataSyncSelector.PairTemporaryTarget(tt.first, tt.second.id),
|
||||
|
@ -348,7 +348,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
)
|
||||
// existing with nsId = update
|
||||
tt.first.interfaceIDs.nightscoutId != null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
tt.first.interfaceIDs.nightscoutId,
|
||||
tt.first.toJson(false, profileFunction.getUnits(), dateUtil),
|
||||
|
@ -403,10 +403,10 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
food.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd("food", food.first.toJson(true), DataSyncSelector.PairFood(food.first, food.second.id), "$startId/$lastDbId")
|
||||
activePlugin.activeNsClient?.dbAdd("food", food.first.toJson(true), DataSyncSelector.PairFood(food.first, food.second.id), "$startId/$lastDbId")
|
||||
// with nsId = update
|
||||
food.first.interfaceIDs.nightscoutId != null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"food",
|
||||
food.first.interfaceIDs.nightscoutId,
|
||||
food.first.toJson(false),
|
||||
|
@ -462,10 +462,10 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
gv.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd("entries", gv.first.toJson(true, dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second.id), "$startId/$lastDbId")
|
||||
activePlugin.activeNsClient?.dbAdd("entries", gv.first.toJson(true, dateUtil), DataSyncSelector.PairGlucoseValue(gv.first, gv.second.id), "$startId/$lastDbId")
|
||||
// with nsId = update
|
||||
else -> // gv.first.interfaceIDs.nightscoutId != null
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"entries",
|
||||
gv.first.interfaceIDs.nightscoutId,
|
||||
gv.first.toJson(false, dateUtil),
|
||||
|
@ -524,10 +524,10 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
te.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd("treatments", te.first.toJson(true, dateUtil), DataSyncSelector.PairTherapyEvent(te.first, te.second.id), "$startId/$lastDbId")
|
||||
activePlugin.activeNsClient?.dbAdd("treatments", te.first.toJson(true, dateUtil), DataSyncSelector.PairTherapyEvent(te.first, te.second.id), "$startId/$lastDbId")
|
||||
// nsId = update
|
||||
te.first.interfaceIDs.nightscoutId != null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
te.first.interfaceIDs.nightscoutId,
|
||||
te.first.toJson(false, dateUtil),
|
||||
|
@ -567,7 +567,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
when {
|
||||
// without nsId = create new
|
||||
deviceStatus.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd("devicestatus", deviceStatus.toJson(dateUtil), deviceStatus, "$startId/$lastDbId")
|
||||
activePlugin.activeNsClient?.dbAdd("devicestatus", deviceStatus.toJson(dateUtil), deviceStatus, "$startId/$lastDbId")
|
||||
// with nsId = ignore
|
||||
deviceStatus.interfaceIDs.nightscoutId != null -> Any()
|
||||
}
|
||||
|
@ -620,7 +620,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
tb.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd(
|
||||
activePlugin.activeNsClient?.dbAdd(
|
||||
"treatments",
|
||||
tb.first.toJson(true, profile, dateUtil),
|
||||
DataSyncSelector.PairTemporaryBasal(tb.first, tb.second.id),
|
||||
|
@ -628,7 +628,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
)
|
||||
// with nsId = update
|
||||
tb.first.interfaceIDs.nightscoutId != null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
tb.first.interfaceIDs.nightscoutId,
|
||||
tb.first.toJson(false, profile, dateUtil),
|
||||
|
@ -691,7 +691,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
eb.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd(
|
||||
activePlugin.activeNsClient?.dbAdd(
|
||||
"treatments",
|
||||
eb.first.toJson(true, profile, dateUtil),
|
||||
DataSyncSelector.PairExtendedBolus(eb.first, eb.second.id),
|
||||
|
@ -699,7 +699,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
)
|
||||
// with nsId = update
|
||||
eb.first.interfaceIDs.nightscoutId != null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
eb.first.interfaceIDs.nightscoutId,
|
||||
eb.first.toJson(false, profile, dateUtil),
|
||||
|
@ -759,10 +759,10 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
ps.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd("treatments", ps.first.toJson(true, dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second.id), "$startId/$lastDbId")
|
||||
activePlugin.activeNsClient?.dbAdd("treatments", ps.first.toJson(true, dateUtil), DataSyncSelector.PairProfileSwitch(ps.first, ps.second.id), "$startId/$lastDbId")
|
||||
// with nsId = update
|
||||
ps.first.interfaceIDs.nightscoutId != null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
ps.first.interfaceIDs.nightscoutId,
|
||||
ps.first.toJson(false, dateUtil),
|
||||
|
@ -816,7 +816,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
ps.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd(
|
||||
activePlugin.activeNsClient?.dbAdd(
|
||||
"treatments",
|
||||
ps.first.toJson(true, dateUtil),
|
||||
DataSyncSelector.PairEffectiveProfileSwitch(ps.first, ps.second.id),
|
||||
|
@ -824,7 +824,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
)
|
||||
// with nsId = update
|
||||
ps.first.interfaceIDs.nightscoutId != null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
ps.first.interfaceIDs.nightscoutId,
|
||||
ps.first.toJson(false, dateUtil),
|
||||
|
@ -879,10 +879,10 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
}
|
||||
// without nsId = create new
|
||||
oe.first.interfaceIDs.nightscoutId == null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd("treatments", oe.first.toJson(true, dateUtil), DataSyncSelector.PairOfflineEvent(oe.first, oe.second.id), "$startId/$lastDbId")
|
||||
activePlugin.activeNsClient?.dbAdd("treatments", oe.first.toJson(true, dateUtil), DataSyncSelector.PairOfflineEvent(oe.first, oe.second.id), "$startId/$lastDbId")
|
||||
// existing with nsId = update
|
||||
oe.first.interfaceIDs.nightscoutId != null ->
|
||||
activePlugin.activeNsClient?.nsClientService?.dbUpdate(
|
||||
activePlugin.activeNsClient?.dbUpdate(
|
||||
"treatments",
|
||||
oe.first.interfaceIDs.nightscoutId,
|
||||
oe.first.toJson(false, dateUtil),
|
||||
|
@ -905,7 +905,7 @@ class DataSyncSelectorImplementation @Inject constructor(
|
|||
if (lastChange > lastSync) {
|
||||
if (activePlugin.activeProfileSource.profile?.allProfilesValid != true) return
|
||||
val profileJson = activePlugin.activeProfileSource.profile?.data ?: return
|
||||
activePlugin.activeNsClient?.nsClientService?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now()), "")
|
||||
activePlugin.activeNsClient?.dbAdd("profile", profileJson, DataSyncSelector.PairProfileStore(profileJson, dateUtil.now()), "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import info.nightscout.shared.interfaces.ResourceHelper
|
|||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
@ -81,7 +82,7 @@ class NSClientPlugin @Inject constructor(
|
|||
private val handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
|
||||
private val listLog: MutableList<EventNSClientNewLog> = ArrayList()
|
||||
override var status = ""
|
||||
override var nsClientService: NSClientService? = null
|
||||
var nsClientService: NSClientService? = null
|
||||
val isAllowed: Boolean
|
||||
get() = nsClientReceiverDelegate.allowed
|
||||
val blockingReason: String
|
||||
|
@ -235,4 +236,12 @@ class NSClientPlugin @Inject constructor(
|
|||
override fun resetToFullSync() {
|
||||
dataSyncSelector.resetToNextFullSync()
|
||||
}
|
||||
|
||||
override fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) {
|
||||
nsClientService?.dbAdd(collection, data, originalObject, progress)
|
||||
}
|
||||
|
||||
override fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) {
|
||||
nsClientService?.dbUpdate(collection, _id, data, originalObject, progress)
|
||||
}
|
||||
}
|
|
@ -25,7 +25,6 @@ import info.nightscout.interfaces.notifications.Notification
|
|||
import info.nightscout.interfaces.nsclient.NSAlarm
|
||||
import info.nightscout.interfaces.nsclient.NSSettingsStatus
|
||||
import info.nightscout.interfaces.sync.DataSyncSelector
|
||||
import info.nightscout.interfaces.sync.NsClient
|
||||
import info.nightscout.interfaces.ui.UiInteraction
|
||||
import info.nightscout.interfaces.utils.JsonHelper.safeGetString
|
||||
import info.nightscout.interfaces.utils.JsonHelper.safeGetStringAllowNull
|
||||
|
@ -72,7 +71,7 @@ import java.net.URISyntaxException
|
|||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
class NSClientService : DaggerService(), NsClient.NSClientService {
|
||||
class NSClientService : DaggerService() {
|
||||
|
||||
@Inject lateinit var injector: HasAndroidInjector
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
|
@ -598,7 +597,7 @@ class NSClientService : DaggerService(), NsClient.NSClientService {
|
|||
}
|
||||
}
|
||||
|
||||
override fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) {
|
||||
fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) {
|
||||
try {
|
||||
if (_id == null) return
|
||||
if (!isConnected || !hasWriteAuth) return
|
||||
|
@ -618,7 +617,7 @@ class NSClientService : DaggerService(), NsClient.NSClientService {
|
|||
}
|
||||
}
|
||||
|
||||
override fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) {
|
||||
fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) {
|
||||
try {
|
||||
if (!isConnected || !hasWriteAuth) return
|
||||
val message = JSONObject()
|
||||
|
|
|
@ -53,6 +53,7 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable
|
|||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlin.math.max
|
||||
|
@ -104,7 +105,6 @@ class NSClientV3Plugin @Inject constructor(
|
|||
nsAndroidClient.lastStatus?.apiPermissions?.isRead() == true -> rh.gs(R.string.read_only)
|
||||
else -> rh.gs(info.nightscout.core.ui.R.string.unknown)
|
||||
}
|
||||
override val nsClientService: NSClientService? = null // service not needed
|
||||
|
||||
internal lateinit var nsAndroidClient: NSAndroidClient
|
||||
// private lateinit var nsAndroidRxClient: NSAndroidRxClient
|
||||
|
@ -251,7 +251,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun resend(reason: String) {
|
||||
nsClientService?.resend(reason)
|
||||
// nsClientService?.resend(reason)
|
||||
}
|
||||
|
||||
override fun pause(newState: Boolean) {
|
||||
|
@ -269,12 +269,12 @@ class NSClientV3Plugin @Inject constructor(
|
|||
aapsLogger.debug(LTag.NSCLIENT, "Upload disabled. Message dropped")
|
||||
return
|
||||
}
|
||||
nsClientService?.sendAlarmAck(
|
||||
AlarmAck().also { ack ->
|
||||
ack.level = originalAlarm.level()
|
||||
ack.group = originalAlarm.group()
|
||||
ack.silenceTime = silenceTimeInMilliseconds
|
||||
})
|
||||
// nsClientService?.sendAlarmAck(
|
||||
// AlarmAck().also { ack ->
|
||||
// ack.level = originalAlarm.level()
|
||||
// ack.group = originalAlarm.group()
|
||||
// ack.silenceTime = silenceTimeInMilliseconds
|
||||
// })
|
||||
}
|
||||
|
||||
override fun updateLatestBgReceivedIfNewer(latestReceived: Long) {
|
||||
|
@ -301,6 +301,14 @@ class NSClientV3Plugin @Inject constructor(
|
|||
storeLastFetched()
|
||||
}
|
||||
|
||||
override fun dbAdd(collection: String, data: JSONObject, originalObject: Any, progress: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun dbUpdate(collection: String, _id: String?, data: JSONObject?, originalObject: Any, progress: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
private fun storeLastFetched() {
|
||||
sp.putString(R.string.key_ns_client_v3_last_modified, Json.encodeToString(LastModified.serializer(), lastFetched))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue