Merge branch 'dev' into ns15
This commit is contained in:
commit
bfabe464c0
9 changed files with 45 additions and 38 deletions
|
@ -126,7 +126,7 @@ class NSAndroidClientImpl(
|
||||||
throw UnsuccessfullNightscoutException()
|
throw UnsuccessfullNightscoutException()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getSgvsModifiedSince(from: Long, limit: Long): NSAndroidClient.ReadResponse<List<NSSgvV3>> = callWrapper(dispatcher) {
|
override suspend fun getSgvsModifiedSince(from: Long, limit: Int): NSAndroidClient.ReadResponse<List<NSSgvV3>> = callWrapper(dispatcher) {
|
||||||
|
|
||||||
val response = api.getSgvsModifiedSince(from, limit)
|
val response = api.getSgvsModifiedSince(from, limit)
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
|
@ -139,7 +139,7 @@ class NSAndroidClientImpl(
|
||||||
throw UnsuccessfullNightscoutException()
|
throw UnsuccessfullNightscoutException()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getSgvsNewerThan(from: Long, limit: Long): NSAndroidClient.ReadResponse<List<NSSgvV3>> = callWrapper(dispatcher) {
|
override suspend fun getSgvsNewerThan(from: Long, limit: Int): NSAndroidClient.ReadResponse<List<NSSgvV3>> = callWrapper(dispatcher) {
|
||||||
|
|
||||||
val response = api.getSgvsNewerThan(from, limit)
|
val response = api.getSgvsNewerThan(from, limit)
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
|
@ -230,7 +230,7 @@ class NSAndroidClientImpl(
|
||||||
throw UnsuccessfullNightscoutException(response.errorBody()?.string() ?: response.message())
|
throw UnsuccessfullNightscoutException(response.errorBody()?.string() ?: response.message())
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getTreatmentsNewerThan(createdAt: String, limit: Long): NSAndroidClient.ReadResponse<List<NSTreatment>> = callWrapper(dispatcher) {
|
override suspend fun getTreatmentsNewerThan(createdAt: String, limit: Int): NSAndroidClient.ReadResponse<List<NSTreatment>> = callWrapper(dispatcher) {
|
||||||
|
|
||||||
val response = api.getTreatmentsNewerThan(createdAt, limit)
|
val response = api.getTreatmentsNewerThan(createdAt, limit)
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
|
@ -241,7 +241,7 @@ class NSAndroidClientImpl(
|
||||||
throw UnsuccessfullNightscoutException()
|
throw UnsuccessfullNightscoutException()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getTreatmentsModifiedSince(from: Long, limit: Long): NSAndroidClient.ReadResponse<List<NSTreatment>> = callWrapper(dispatcher) {
|
override suspend fun getTreatmentsModifiedSince(from: Long, limit: Int): NSAndroidClient.ReadResponse<List<NSTreatment>> = callWrapper(dispatcher) {
|
||||||
|
|
||||||
val response = api.getTreatmentsModifiedSince(from, limit)
|
val response = api.getTreatmentsModifiedSince(from, limit)
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
|
@ -380,7 +380,7 @@ class NSAndroidClientImpl(
|
||||||
throw UnsuccessfullNightscoutException(response.errorBody()?.string() ?: response.message())
|
throw UnsuccessfullNightscoutException(response.errorBody()?.string() ?: response.message())
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getFoods(limit: Long): NSAndroidClient.ReadResponse<List<NSFood>> = callWrapper(dispatcher) {
|
override suspend fun getFoods(limit: Int): NSAndroidClient.ReadResponse<List<NSFood>> = callWrapper(dispatcher) {
|
||||||
|
|
||||||
val response = api.getFoods(limit)
|
val response = api.getFoods(limit)
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
|
@ -392,7 +392,7 @@ class NSAndroidClientImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
override suspend fun getFoodsModifiedSince(from: Long, limit: Long): NSAndroidClient.ReadResponse<List<NSFood>> = callWrapper(dispatcher) {
|
override suspend fun getFoodsModifiedSince(from: Long, limit: Int): NSAndroidClient.ReadResponse<List<NSFood>> = callWrapper(dispatcher) {
|
||||||
|
|
||||||
val response = api.getFoodsModifiedSince(from, limit)
|
val response = api.getFoodsModifiedSince(from, limit)
|
||||||
val eTagString = response.headers()["ETag"]
|
val eTagString = response.headers()["ETag"]
|
||||||
|
|
|
@ -23,13 +23,13 @@ interface NSAndroidClient {
|
||||||
suspend fun getLastModified(): LastModified
|
suspend fun getLastModified(): LastModified
|
||||||
|
|
||||||
suspend fun getSgvs(): ReadResponse<List<NSSgvV3>>
|
suspend fun getSgvs(): ReadResponse<List<NSSgvV3>>
|
||||||
suspend fun getSgvsModifiedSince(from: Long, limit: Long): ReadResponse<List<NSSgvV3>>
|
suspend fun getSgvsModifiedSince(from: Long, limit: Int): ReadResponse<List<NSSgvV3>>
|
||||||
suspend fun getSgvsNewerThan(from: Long, limit: Long): ReadResponse<List<NSSgvV3>>
|
suspend fun getSgvsNewerThan(from: Long, limit: Int): ReadResponse<List<NSSgvV3>>
|
||||||
suspend fun createSvg(nsSgvV3: NSSgvV3): CreateUpdateResponse
|
suspend fun createSvg(nsSgvV3: NSSgvV3): CreateUpdateResponse
|
||||||
suspend fun updateSvg(nsSgvV3: NSSgvV3): CreateUpdateResponse
|
suspend fun updateSvg(nsSgvV3: NSSgvV3): CreateUpdateResponse
|
||||||
|
|
||||||
suspend fun getTreatmentsNewerThan(createdAt: String, limit: Long): ReadResponse<List<NSTreatment>>
|
suspend fun getTreatmentsNewerThan(createdAt: String, limit: Int): ReadResponse<List<NSTreatment>>
|
||||||
suspend fun getTreatmentsModifiedSince(from: Long, limit: Long): ReadResponse<List<NSTreatment>>
|
suspend fun getTreatmentsModifiedSince(from: Long, limit: Int): ReadResponse<List<NSTreatment>>
|
||||||
|
|
||||||
suspend fun createDeviceStatus(nsDeviceStatus: NSDeviceStatus): CreateUpdateResponse
|
suspend fun createDeviceStatus(nsDeviceStatus: NSDeviceStatus): CreateUpdateResponse
|
||||||
suspend fun getDeviceStatusModifiedSince(from: Long): List<NSDeviceStatus>
|
suspend fun getDeviceStatusModifiedSince(from: Long): List<NSDeviceStatus>
|
||||||
|
@ -40,9 +40,9 @@ interface NSAndroidClient {
|
||||||
|
|
||||||
suspend fun createTreatment(nsTreatment: NSTreatment): CreateUpdateResponse
|
suspend fun createTreatment(nsTreatment: NSTreatment): CreateUpdateResponse
|
||||||
suspend fun updateTreatment(nsTreatment: NSTreatment): CreateUpdateResponse
|
suspend fun updateTreatment(nsTreatment: NSTreatment): CreateUpdateResponse
|
||||||
suspend fun getFoods(limit: Long): ReadResponse<List<NSFood>>
|
suspend fun getFoods(limit: Int): ReadResponse<List<NSFood>>
|
||||||
|
|
||||||
//suspend fun getFoodsModifiedSince(from: Long, limit: Long): ReadResponse<List<NSFood>>
|
//suspend fun getFoodsModifiedSince(from: Long, limit: Int): ReadResponse<List<NSFood>>
|
||||||
suspend fun createFood(nsFood: NSFood): CreateUpdateResponse
|
suspend fun createFood(nsFood: NSFood): CreateUpdateResponse
|
||||||
suspend fun updateFood(nsFood: NSFood): CreateUpdateResponse
|
suspend fun updateFood(nsFood: NSFood): CreateUpdateResponse
|
||||||
}
|
}
|
|
@ -42,10 +42,10 @@ internal interface NightscoutRemoteService {
|
||||||
suspend fun getSgvs(): Response<NSResponse<List<RemoteEntry>>>
|
suspend fun getSgvs(): Response<NSResponse<List<RemoteEntry>>>
|
||||||
|
|
||||||
@GET("v3/entries")
|
@GET("v3/entries")
|
||||||
suspend fun getSgvsNewerThan(@Query(value = "date\$gt", encoded = true) date: Long, @Query("limit") limit: Long): Response<NSResponse<List<RemoteEntry>>>
|
suspend fun getSgvsNewerThan(@Query(value = "date\$gt", encoded = true) date: Long, @Query("limit") limit: Int): Response<NSResponse<List<RemoteEntry>>>
|
||||||
|
|
||||||
@GET("v3/entries/history/{from}")
|
@GET("v3/entries/history/{from}")
|
||||||
suspend fun getSgvsModifiedSince(@Path("from") from: Long, @Query("limit") limit: Long): Response<NSResponse<List<RemoteEntry>>>
|
suspend fun getSgvsModifiedSince(@Path("from") from: Long, @Query("limit") limit: Int): Response<NSResponse<List<RemoteEntry>>>
|
||||||
|
|
||||||
@POST("v3/entries")
|
@POST("v3/entries")
|
||||||
suspend fun createEntry(@Body remoteEntry: RemoteEntry): Response<NSResponse<RemoteCreateUpdateResponse>>
|
suspend fun createEntry(@Body remoteEntry: RemoteEntry): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||||
|
@ -57,10 +57,10 @@ internal interface NightscoutRemoteService {
|
||||||
suspend fun deleteEntry(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
suspend fun deleteEntry(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||||
|
|
||||||
@GET("v3/treatments")
|
@GET("v3/treatments")
|
||||||
suspend fun getTreatmentsNewerThan(@Query(value = "created_at\$gt", encoded = true) createdAt: String, @Query("limit") limit: Long): Response<NSResponse<List<RemoteTreatment>>>
|
suspend fun getTreatmentsNewerThan(@Query(value = "created_at\$gt", encoded = true) createdAt: String, @Query("limit") limit: Int): Response<NSResponse<List<RemoteTreatment>>>
|
||||||
|
|
||||||
@GET("v3/treatments/history/{from}")
|
@GET("v3/treatments/history/{from}")
|
||||||
suspend fun getTreatmentsModifiedSince(@Path("from") from: Long, @Query("limit") limit: Long): Response<NSResponse<List<RemoteTreatment>>>
|
suspend fun getTreatmentsModifiedSince(@Path("from") from: Long, @Query("limit") limit: Int): Response<NSResponse<List<RemoteTreatment>>>
|
||||||
|
|
||||||
@POST("v3/treatments")
|
@POST("v3/treatments")
|
||||||
suspend fun createTreatment(@Body remoteTreatment: RemoteTreatment): Response<NSResponse<RemoteCreateUpdateResponse>>
|
suspend fun createTreatment(@Body remoteTreatment: RemoteTreatment): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||||
|
@ -78,11 +78,11 @@ internal interface NightscoutRemoteService {
|
||||||
suspend fun getDeviceStatusModifiedSince(@Path("from") from: Long): Response<NSResponse<List<RemoteDeviceStatus>>>
|
suspend fun getDeviceStatusModifiedSince(@Path("from") from: Long): Response<NSResponse<List<RemoteDeviceStatus>>>
|
||||||
|
|
||||||
@GET("v3/food")
|
@GET("v3/food")
|
||||||
suspend fun getFoods(@Query("limit") limit: Long): Response<NSResponse<List<RemoteFood>>>
|
suspend fun getFoods(@Query("limit") limit: Int): Response<NSResponse<List<RemoteFood>>>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@GET("v3/food/history/{from}")
|
@GET("v3/food/history/{from}")
|
||||||
suspend fun getFoodsModifiedSince(@Path("from") from: Long, @Query("limit") limit: Long): Response<NSResponse<List<RemoteFood>>>
|
suspend fun getFoodsModifiedSince(@Path("from") from: Long, @Query("limit") limit: Int): Response<NSResponse<List<RemoteFood>>>
|
||||||
*/
|
*/
|
||||||
@POST("v3/food")
|
@POST("v3/food")
|
||||||
suspend fun createFood(@Body remoteFood: RemoteFood): Response<NSResponse<RemoteCreateUpdateResponse>>
|
suspend fun createFood(@Body remoteFood: RemoteFood): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||||
|
@ -94,7 +94,7 @@ internal interface NightscoutRemoteService {
|
||||||
suspend fun deleteFood(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
suspend fun deleteFood(@Path("identifier") identifier: String): Response<NSResponse<RemoteCreateUpdateResponse>>
|
||||||
|
|
||||||
@GET("v3/profile/history/{from}")
|
@GET("v3/profile/history/{from}")
|
||||||
suspend fun getProfileModifiedSince(@Path("from") from: Long, @Query("limit") limit: Long = 10): Response<NSResponse<List<JSONObject>>>
|
suspend fun getProfileModifiedSince(@Path("from") from: Long, @Query("limit") limit: Int = 10): Response<NSResponse<List<JSONObject>>>
|
||||||
|
|
||||||
|
|
||||||
@GET("v3/profile?sort\$desc=date&limit=1")
|
@GET("v3/profile?sort\$desc=date&limit=1")
|
||||||
|
|
|
@ -137,10 +137,12 @@ class NSClientV3Plugin @Inject constructor(
|
||||||
aapsLogger, rh, injector
|
aapsLogger, rh, injector
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@Suppress("PropertyName")
|
||||||
|
val JOB_NAME: String = this::class.java.simpleName
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
val JOB_NAME: String = this::class.java.simpleName
|
const val RECORDS_TO_LOAD = 500
|
||||||
const val RECORDS_TO_LOAD = 500L
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
|
|
@ -43,7 +43,7 @@ class LoadBgWorker(
|
||||||
if (!nsClientSource.isEnabled() && !sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_cgm, false)) {
|
if (!nsClientSource.isEnabled() && !sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_cgm, false)) {
|
||||||
workManager
|
workManager
|
||||||
.enqueueUniqueWork(
|
.enqueueUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(LoadTreatmentsWorker::class.java).build()
|
OneTimeWorkRequest.Builder(LoadTreatmentsWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
@ -62,6 +62,7 @@ class LoadBgWorker(
|
||||||
if (isFirstLoad) response = nsAndroidClient.getSgvsNewerThan(lastLoaded, NSClientV3Plugin.RECORDS_TO_LOAD)
|
if (isFirstLoad) response = nsAndroidClient.getSgvsNewerThan(lastLoaded, NSClientV3Plugin.RECORDS_TO_LOAD)
|
||||||
else {
|
else {
|
||||||
response = nsAndroidClient.getSgvsModifiedSince(lastLoaded, NSClientV3Plugin.RECORDS_TO_LOAD)
|
response = nsAndroidClient.getSgvsModifiedSince(lastLoaded, NSClientV3Plugin.RECORDS_TO_LOAD)
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "lastLoadedSrvModified: ${response.lastServerModified}")
|
||||||
response.lastServerModified?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.entries = it }
|
response.lastServerModified?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.entries = it }
|
||||||
nsClientV3Plugin.storeLastLoadedSrvModified()
|
nsClientV3Plugin.storeLastLoadedSrvModified()
|
||||||
nsClientV3Plugin.scheduleIrregularExecution() // Idea is to run after 5 min after last BG
|
nsClientV3Plugin.scheduleIrregularExecution() // Idea is to run after 5 min after last BG
|
||||||
|
@ -74,15 +75,16 @@ class LoadBgWorker(
|
||||||
// Objective0
|
// Objective0
|
||||||
sp.putBoolean(info.nightscout.core.utils.R.string.key_objectives_bg_is_available_in_ns, true)
|
sp.putBoolean(info.nightscout.core.utils.R.string.key_objectives_bg_is_available_in_ns, true)
|
||||||
// Schedule processing of fetched data and continue of loading
|
// Schedule processing of fetched data and continue of loading
|
||||||
|
val stopLoading = sgvs.size != NSClientV3Plugin.RECORDS_TO_LOAD || response.code == 304
|
||||||
workManager
|
workManager
|
||||||
.beginUniqueWork(
|
.beginUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(workerClasses.nsClientSourceWorker).setInputData(dataWorkerStorage.storeInputData(sgvs)).build()
|
OneTimeWorkRequest.Builder(workerClasses.nsClientSourceWorker).setInputData(dataWorkerStorage.storeInputData(sgvs)).build()
|
||||||
)
|
)
|
||||||
// response 304 == Not modified (happens when date > srvModified => bad time on phone or server during upload
|
// response 304 == Not modified (happens when date > srvModified => bad time on phone or server during upload
|
||||||
.then(response.code != 304, OneTimeWorkRequest.Builder(LoadBgWorker::class.java).build())
|
.then(!stopLoading, OneTimeWorkRequest.Builder(LoadBgWorker::class.java).build())
|
||||||
.then(response.code == 304, OneTimeWorkRequest.Builder(LoadTreatmentsWorker::class.java).build())
|
.then(stopLoading, OneTimeWorkRequest.Builder(LoadTreatmentsWorker::class.java).build())
|
||||||
.enqueue()
|
.enqueue()
|
||||||
} else {
|
} else {
|
||||||
// End first load
|
// End first load
|
||||||
|
@ -93,7 +95,7 @@ class LoadBgWorker(
|
||||||
rxBus.send(EventNSClientNewLog("◄ RCV BG END", "No data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
rxBus.send(EventNSClientNewLog("◄ RCV BG END", "No data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||||
workManager
|
workManager
|
||||||
.beginUniqueWork(
|
.beginUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(StoreDataForDbImpl.StoreBgWorker::class.java).build()
|
OneTimeWorkRequest.Builder(StoreDataForDbImpl.StoreBgWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
@ -109,7 +111,7 @@ class LoadBgWorker(
|
||||||
rxBus.send(EventNSClientNewLog("◄ RCV BG END", "No new data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
rxBus.send(EventNSClientNewLog("◄ RCV BG END", "No new data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||||
workManager
|
workManager
|
||||||
.beginUniqueWork(
|
.beginUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(StoreDataForDbImpl.StoreBgWorker::class.java).build()
|
OneTimeWorkRequest.Builder(StoreDataForDbImpl.StoreBgWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
|
|
@ -48,7 +48,7 @@ class LoadDeviceStatusWorker(
|
||||||
}
|
}
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.enqueueUniqueWork(
|
.enqueueUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(DataSyncWorker::class.java).build()
|
OneTimeWorkRequest.Builder(DataSyncWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
|
|
@ -44,7 +44,7 @@ class LoadFoodsWorker(
|
||||||
// Schedule processing of fetched data
|
// Schedule processing of fetched data
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(
|
.beginUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(ProcessFoodWorker::class.java)
|
OneTimeWorkRequest.Builder(ProcessFoodWorker::class.java)
|
||||||
.setInputData(dataWorkerStorage.storeInputData(foods))
|
.setInputData(dataWorkerStorage.storeInputData(foods))
|
||||||
|
@ -56,7 +56,7 @@ class LoadFoodsWorker(
|
||||||
rxBus.send(EventNSClientNewLog("● RCV FOOD", "skipped"))
|
rxBus.send(EventNSClientNewLog("● RCV FOOD", "skipped"))
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.enqueueUniqueWork(
|
.enqueueUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(LoadProfileStoreWorker::class.java).build()
|
OneTimeWorkRequest.Builder(LoadProfileStoreWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
|
|
@ -48,6 +48,7 @@ class LoadProfileStoreWorker(
|
||||||
if (profiles.isNotEmpty()) {
|
if (profiles.isNotEmpty()) {
|
||||||
val profile = profiles[profiles.size - 1]
|
val profile = profiles[profiles.size - 1]
|
||||||
// if srvModified found in response
|
// if srvModified found in response
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "lastLoadedSrvModified: ${response.lastServerModified}")
|
||||||
response.lastServerModified?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.profile = it } ?:
|
response.lastServerModified?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.profile = it } ?:
|
||||||
// if srvModified found in record
|
// if srvModified found in record
|
||||||
JsonHelper.safeGetLongAllowNull(profile, "srvModified")?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.profile = it } ?:
|
JsonHelper.safeGetLongAllowNull(profile, "srvModified")?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.profile = it } ?:
|
||||||
|
@ -60,7 +61,7 @@ class LoadProfileStoreWorker(
|
||||||
rxBus.send(EventNSClientNewLog("◄ RCV", "1 PROFILE from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
rxBus.send(EventNSClientNewLog("◄ RCV", "1 PROFILE from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(
|
.beginUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder((workerClasses.nsProfileWorker))
|
OneTimeWorkRequest.Builder((workerClasses.nsProfileWorker))
|
||||||
.setInputData(dataWorkerStorage.storeInputData(profile))
|
.setInputData(dataWorkerStorage.storeInputData(profile))
|
||||||
|
@ -71,7 +72,7 @@ class LoadProfileStoreWorker(
|
||||||
rxBus.send(EventNSClientNewLog("◄ RCV PROFILE END", "No new data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
rxBus.send(EventNSClientNewLog("◄ RCV PROFILE END", "No new data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.enqueueUniqueWork(
|
.enqueueUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(LoadDeviceStatusWorker::class.java).build()
|
OneTimeWorkRequest.Builder(LoadDeviceStatusWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
@ -80,7 +81,7 @@ class LoadProfileStoreWorker(
|
||||||
rxBus.send(EventNSClientNewLog("◄ RCV PROFILE END", "No data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
rxBus.send(EventNSClientNewLog("◄ RCV PROFILE END", "No data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.enqueueUniqueWork(
|
.enqueueUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(LoadDeviceStatusWorker::class.java).build()
|
OneTimeWorkRequest.Builder(LoadDeviceStatusWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
|
|
@ -51,6 +51,7 @@ class LoadTreatmentsWorker(
|
||||||
response = nsAndroidClient.getTreatmentsNewerThan(lastLoadedIso, NSClientV3Plugin.RECORDS_TO_LOAD)
|
response = nsAndroidClient.getTreatmentsNewerThan(lastLoadedIso, NSClientV3Plugin.RECORDS_TO_LOAD)
|
||||||
} else {
|
} else {
|
||||||
response = nsAndroidClient.getTreatmentsModifiedSince(lastLoaded, NSClientV3Plugin.RECORDS_TO_LOAD)
|
response = nsAndroidClient.getTreatmentsModifiedSince(lastLoaded, NSClientV3Plugin.RECORDS_TO_LOAD)
|
||||||
|
aapsLogger.debug(LTag.NSCLIENT, "lastLoadedSrvModified: ${response.lastServerModified}")
|
||||||
response.lastServerModified?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.treatments = it }
|
response.lastServerModified?.let { nsClientV3Plugin.lastLoadedSrvModified.collections.treatments = it }
|
||||||
nsClientV3Plugin.storeLastLoadedSrvModified()
|
nsClientV3Plugin.storeLastLoadedSrvModified()
|
||||||
}
|
}
|
||||||
|
@ -60,17 +61,18 @@ class LoadTreatmentsWorker(
|
||||||
val action = if (isFirstLoad) "RCV-FIRST" else "RCV"
|
val action = if (isFirstLoad) "RCV-FIRST" else "RCV"
|
||||||
rxBus.send(EventNSClientNewLog("◄ $action", "${treatments.size} TRs from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
rxBus.send(EventNSClientNewLog("◄ $action", "${treatments.size} TRs from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||||
// Schedule processing of fetched data and continue of loading
|
// Schedule processing of fetched data and continue of loading
|
||||||
|
val stopLoading = treatments.size != NSClientV3Plugin.RECORDS_TO_LOAD || response.code == 304
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(
|
.beginUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(ProcessTreatmentsWorker::class.java)
|
OneTimeWorkRequest.Builder(ProcessTreatmentsWorker::class.java)
|
||||||
.setInputData(dataWorkerStorage.storeInputData(response.values))
|
.setInputData(dataWorkerStorage.storeInputData(response.values))
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
// response 304 == Not modified (happens when date > srvModified => bad time on phone or server during upload
|
// response 304 == Not modified (happens when date > srvModified => bad time on phone or server during upload
|
||||||
.then(response.code != 304, OneTimeWorkRequest.Builder(LoadTreatmentsWorker::class.java).build())
|
.then(!stopLoading, OneTimeWorkRequest.Builder(LoadTreatmentsWorker::class.java).build())
|
||||||
.then(response.code == 304, OneTimeWorkRequest.Builder(LoadFoodsWorker::class.java).build())
|
.then(stopLoading, OneTimeWorkRequest.Builder(LoadFoodsWorker::class.java).build())
|
||||||
.enqueue()
|
.enqueue()
|
||||||
} else {
|
} else {
|
||||||
// End first load
|
// End first load
|
||||||
|
@ -81,7 +83,7 @@ class LoadTreatmentsWorker(
|
||||||
rxBus.send(EventNSClientNewLog("◄ RCV TR END", "No data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
rxBus.send(EventNSClientNewLog("◄ RCV TR END", "No data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(
|
.beginUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(StoreDataForDbImpl.StoreTreatmentsWorker::class.java).build()
|
OneTimeWorkRequest.Builder(StoreDataForDbImpl.StoreTreatmentsWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
@ -97,7 +99,7 @@ class LoadTreatmentsWorker(
|
||||||
rxBus.send(EventNSClientNewLog("◄ RCV TR END", "No new data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
rxBus.send(EventNSClientNewLog("◄ RCV TR END", "No new data from ${dateUtil.dateAndTimeAndSecondsString(lastLoaded)}"))
|
||||||
WorkManager.getInstance(context)
|
WorkManager.getInstance(context)
|
||||||
.beginUniqueWork(
|
.beginUniqueWork(
|
||||||
NSClientV3Plugin.JOB_NAME,
|
nsClientV3Plugin.JOB_NAME,
|
||||||
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
ExistingWorkPolicy.APPEND_OR_REPLACE,
|
||||||
OneTimeWorkRequest.Builder(StoreDataForDbImpl.StoreTreatmentsWorker::class.java).build()
|
OneTimeWorkRequest.Builder(StoreDataForDbImpl.StoreTreatmentsWorker::class.java).build()
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue