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