Also upload APS data
This commit is contained in:
parent
3fc2aede23
commit
5533f87bbc
|
@ -379,7 +379,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
BgReading old = getDaoBgReadings().queryForId(bgReading.date);
|
||||
if (old == null) {
|
||||
getDaoBgReadings().create(bgReading);
|
||||
OpenHumansUploader.INSTANCE.queueBGReading(bgReading);
|
||||
OpenHumansUploader.INSTANCE.enqueueBGReading(bgReading);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("BG: New record from: " + from + " " + bgReading.toString());
|
||||
scheduleBgChange(bgReading);
|
||||
|
@ -390,7 +390,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
log.debug("BG: Similiar found: " + old.toString());
|
||||
old.copyFrom(bgReading);
|
||||
getDaoBgReadings().update(old);
|
||||
OpenHumansUploader.INSTANCE.queueBGReading(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueBGReading(old);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
|
||||
scheduleBgChange(bgReading);
|
||||
|
@ -406,7 +406,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
bgReading.date = roundDateToSec(bgReading.date);
|
||||
try {
|
||||
getDaoBgReadings().update(bgReading);
|
||||
OpenHumansUploader.INSTANCE.queueBGReading(bgReading);
|
||||
OpenHumansUploader.INSTANCE.enqueueBGReading(bgReading);
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
@ -530,7 +530,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
try {
|
||||
Dao<TDD, String> dao = getDaoTDD();
|
||||
dao.createOrUpdate(tdd);
|
||||
OpenHumansUploader.INSTANCE.queueTotalDailyDose(tdd);
|
||||
OpenHumansUploader.INSTANCE.enqueueTotalDailyDose(tdd);
|
||||
} catch (SQLException e) {
|
||||
ToastUtils.showToastInUiThread(MainApp.instance(), "createOrUpdate-Exception");
|
||||
log.error("Unhandled exception", e);
|
||||
|
@ -706,7 +706,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
getDaoTempTargets().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(tempTarget);
|
||||
getDaoTempTargets().create(old);
|
||||
OpenHumansUploader.INSTANCE.queueTempTarget(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueTempTarget(old);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("TEMPTARGET: Updating record by date from: " + Source.getString(tempTarget.source) + " " + old.toString());
|
||||
scheduleTemporaryTargetChange();
|
||||
|
@ -727,7 +727,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
getDaoTempTargets().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(tempTarget);
|
||||
getDaoTempTargets().create(old);
|
||||
OpenHumansUploader.INSTANCE.queueTempTarget(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueTempTarget(old);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("TEMPTARGET: Updating record by _id from: " + Source.getString(tempTarget.source) + " " + old.toString());
|
||||
scheduleTemporaryTargetChange();
|
||||
|
@ -743,7 +743,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
if (tempTarget.source == Source.USER) {
|
||||
getDaoTempTargets().create(tempTarget);
|
||||
OpenHumansUploader.INSTANCE.queueTempTarget(tempTarget);
|
||||
OpenHumansUploader.INSTANCE.enqueueTempTarget(tempTarget);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("TEMPTARGET: New record from: " + Source.getString(tempTarget.source) + " " + tempTarget.toString());
|
||||
scheduleTemporaryTargetChange();
|
||||
|
@ -758,7 +758,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public void delete(TempTarget tempTarget) {
|
||||
try {
|
||||
getDaoTempTargets().delete(tempTarget);
|
||||
OpenHumansUploader.INSTANCE.queueTempTarget(tempTarget, true);
|
||||
OpenHumansUploader.INSTANCE.enqueueTempTarget(tempTarget, true);
|
||||
scheduleTemporaryTargetChange();
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
@ -941,7 +941,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
log.debug("TEMPBASAL: Updated record with Pump Data : " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
|
||||
getDaoTemporaryBasal().update(old);
|
||||
OpenHumansUploader.INSTANCE.queueTemporaryBasal(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(old);
|
||||
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
scheduleTemporaryBasalChange();
|
||||
|
@ -950,7 +950,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
|
||||
getDaoTemporaryBasal().create(tempBasal);
|
||||
OpenHumansUploader.INSTANCE.queueTemporaryBasal(tempBasal);
|
||||
OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(tempBasal);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
|
@ -969,7 +969,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(tempBasal);
|
||||
getDaoTemporaryBasal().create(old);
|
||||
OpenHumansUploader.INSTANCE.queueTemporaryBasal(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(old);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("TEMPBASAL: Updating record by date from: " + Source.getString(tempBasal.source) + " " + old.toString());
|
||||
updateEarliestDataChange(oldDate);
|
||||
|
@ -993,7 +993,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(tempBasal);
|
||||
getDaoTemporaryBasal().create(old);
|
||||
OpenHumansUploader.INSTANCE.queueTemporaryBasal(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(old);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("TEMPBASAL: Updating record by _id from: " + Source.getString(tempBasal.source) + " " + old.toString());
|
||||
updateEarliestDataChange(oldDate);
|
||||
|
@ -1004,7 +1004,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
}
|
||||
getDaoTemporaryBasal().create(tempBasal);
|
||||
OpenHumansUploader.INSTANCE.queueTemporaryBasal(tempBasal);
|
||||
OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(tempBasal);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
|
@ -1013,7 +1013,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
if (tempBasal.source == Source.USER) {
|
||||
getDaoTemporaryBasal().create(tempBasal);
|
||||
OpenHumansUploader.INSTANCE.queueTemporaryBasal(tempBasal);
|
||||
OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(tempBasal);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
|
@ -1029,7 +1029,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public void delete(TemporaryBasal tempBasal) {
|
||||
try {
|
||||
getDaoTemporaryBasal().delete(tempBasal);
|
||||
OpenHumansUploader.INSTANCE.queueTemporaryBasal(tempBasal, true);
|
||||
OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(tempBasal, true);
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
@ -1244,7 +1244,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
// and then is record updated with pumpId
|
||||
if (extendedBolus.pumpId == 0) {
|
||||
getDaoExtendedBolus().createOrUpdate(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus);
|
||||
} else {
|
||||
QueryBuilder<ExtendedBolus, Long> queryBuilder = getDaoExtendedBolus().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
|
@ -1256,7 +1256,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
return false;
|
||||
}
|
||||
getDaoExtendedBolus().createOrUpdate(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus);
|
||||
}
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log());
|
||||
|
@ -1272,7 +1272,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
getDaoExtendedBolus().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(extendedBolus);
|
||||
getDaoExtendedBolus().create(old);
|
||||
OpenHumansUploader.INSTANCE.queueExtendedBolus(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueExtendedBolus(old);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("EXTENDEDBOLUS: Updating record by date from: " + Source.getString(extendedBolus.source) + " " + old.log());
|
||||
updateEarliestDataChange(oldDate);
|
||||
|
@ -1296,7 +1296,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
getDaoExtendedBolus().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(extendedBolus);
|
||||
getDaoExtendedBolus().create(old);
|
||||
OpenHumansUploader.INSTANCE.queueExtendedBolus(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueExtendedBolus(old);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("EXTENDEDBOLUS: Updating record by _id from: " + Source.getString(extendedBolus.source) + " " + old.log());
|
||||
updateEarliestDataChange(oldDate);
|
||||
|
@ -1307,7 +1307,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
}
|
||||
getDaoExtendedBolus().create(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log());
|
||||
updateEarliestDataChange(extendedBolus.date);
|
||||
|
@ -1316,7 +1316,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
if (extendedBolus.source == Source.USER) {
|
||||
getDaoExtendedBolus().create(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log());
|
||||
updateEarliestDataChange(extendedBolus.date);
|
||||
|
@ -1352,7 +1352,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public void delete(ExtendedBolus extendedBolus) {
|
||||
try {
|
||||
getDaoExtendedBolus().delete(extendedBolus);
|
||||
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus, true);
|
||||
OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus, true);
|
||||
updateEarliestDataChange(extendedBolus.date);
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
@ -1459,7 +1459,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
careportalEvent.date = careportalEvent.date - careportalEvent.date % 1000;
|
||||
try {
|
||||
getDaoCareportalEvents().createOrUpdate(careportalEvent);
|
||||
OpenHumansUploader.INSTANCE.queueCareportalEvent(careportalEvent);
|
||||
OpenHumansUploader.INSTANCE.enqueueCareportalEvent(careportalEvent);
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
@ -1469,7 +1469,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public void delete(CareportalEvent careportalEvent) {
|
||||
try {
|
||||
getDaoCareportalEvents().delete(careportalEvent);
|
||||
OpenHumansUploader.INSTANCE.queueCareportalEvent(careportalEvent, true);
|
||||
OpenHumansUploader.INSTANCE.enqueueCareportalEvent(careportalEvent, true);
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
@ -1776,7 +1776,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
profileSwitch.profileName = old.profileName; // preserver profileName to prevent multiple CPP extension
|
||||
getDaoProfileSwitch().delete(old); // need to delete/create because date may change too
|
||||
getDaoProfileSwitch().create(profileSwitch);
|
||||
OpenHumansUploader.INSTANCE.queueProfileSwitch(profileSwitch);
|
||||
OpenHumansUploader.INSTANCE.enqueueProfileSwitch(profileSwitch);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("PROFILESWITCH: Updating record by date from: " + Source.getString(profileSwitch.source) + " " + old.toString());
|
||||
scheduleProfileSwitchChange();
|
||||
|
@ -1797,7 +1797,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
getDaoProfileSwitch().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(profileSwitch);
|
||||
getDaoProfileSwitch().create(old);
|
||||
OpenHumansUploader.INSTANCE.queueProfileSwitch(old);
|
||||
OpenHumansUploader.INSTANCE.enqueueProfileSwitch(old);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("PROFILESWITCH: Updating record by _id from: " + Source.getString(profileSwitch.source) + " " + old.toString());
|
||||
scheduleProfileSwitchChange();
|
||||
|
@ -1808,7 +1808,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
// look for already added percentage from NS
|
||||
profileSwitch.profileName = PercentageSplitter.pureName(profileSwitch.profileName);
|
||||
getDaoProfileSwitch().create(profileSwitch);
|
||||
OpenHumansUploader.INSTANCE.queueProfileSwitch(profileSwitch);
|
||||
OpenHumansUploader.INSTANCE.enqueueProfileSwitch(profileSwitch);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString());
|
||||
scheduleProfileSwitchChange();
|
||||
|
@ -1816,7 +1816,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
if (profileSwitch.source == Source.USER) {
|
||||
getDaoProfileSwitch().create(profileSwitch);
|
||||
OpenHumansUploader.INSTANCE.queueProfileSwitch(profileSwitch);
|
||||
OpenHumansUploader.INSTANCE.enqueueProfileSwitch(profileSwitch);
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString());
|
||||
scheduleProfileSwitchChange();
|
||||
|
@ -1831,7 +1831,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public void delete(ProfileSwitch profileSwitch) {
|
||||
try {
|
||||
getDaoProfileSwitch().delete(profileSwitch);
|
||||
OpenHumansUploader.INSTANCE.queueProfileSwitch(profileSwitch, true);
|
||||
OpenHumansUploader.INSTANCE.enqueueProfileSwitch(profileSwitch, true);
|
||||
scheduleProfileSwitchChange();
|
||||
} catch (SQLException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.Constants;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.MealData;
|
||||
|
@ -127,7 +128,9 @@ public class DetermineBasalAdapterAMAJS {
|
|||
if (L.isEnabled(L.APS))
|
||||
log.debug("Result: " + result);
|
||||
try {
|
||||
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result));
|
||||
JSONObject resultJson = new JSONObject(result);
|
||||
OpenHumansUploader.INSTANCE.enqueueAMAData(mProfile, mGlucoseStatus, mIobData, mMealData, mCurrentTemp, mAutosensData, resultJson);
|
||||
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, resultJson);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import javax.annotation.Nullable;
|
|||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.MealData;
|
||||
|
@ -104,7 +105,9 @@ public class DetermineBasalAdapterMAJS {
|
|||
if (L.isEnabled(L.APS))
|
||||
log.debug("Result: " + result);
|
||||
try {
|
||||
determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result));
|
||||
JSONObject resultJson = new JSONObject(result);
|
||||
OpenHumansUploader.INSTANCE.enqueueAMAData(mProfile, mGlucoseStatus, mIobData, mMealData, mCurrentTemp, resultJson);
|
||||
determineBasalResultMA = new DetermineBasalResultMA(jsResult, resultJson);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.Constants;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.MealData;
|
||||
|
@ -144,7 +145,9 @@ public class DetermineBasalAdapterSMBJS {
|
|||
if (L.isEnabled(L.APS))
|
||||
log.debug("Result: " + result);
|
||||
try {
|
||||
determineBasalResultSMB = new DetermineBasalResultSMB(new JSONObject(result));
|
||||
JSONObject resultJson = new JSONObject(result);
|
||||
OpenHumansUploader.INSTANCE.enqueueSMBData(mProfile, mGlucoseStatus, mIobData, mMealData, mCurrentTemp, mAutosensData, mMicrobolusAllowed, mSMBAlwaysAllowed, resultJson);
|
||||
determineBasalResultSMB = new DetermineBasalResultSMB(resultJson);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -14,11 +14,13 @@ class OHUploadWorker(
|
|||
|
||||
override fun createWork() = Single.defer {
|
||||
val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
|
||||
if (SP.getBoolean("key_oh_wifi_only", true) && wifiManager.isWifiEnabled && wifiManager.connectionInfo.networkId != -1)
|
||||
if (SP.getBoolean("key_oh_wifi_only", true) && wifiManager.isWifiEnabled && wifiManager.connectionInfo.networkId != -1) {
|
||||
OpenHumansUploader.uploadData()
|
||||
.andThen(Single.just(Result.success()))
|
||||
.onErrorResumeNext { Single.just(Result.retry()) }
|
||||
else Single.just(Result.retry())
|
||||
} else {
|
||||
Single.just(Result.retry())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,6 @@ import org.json.JSONObject
|
|||
import java.io.IOException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import okhttp3.RequestBody.Companion
|
||||
import okio.BufferedSink
|
||||
|
||||
class OpenHumansAPI(
|
||||
|
@ -24,13 +23,13 @@ class OpenHumansAPI(
|
|||
private val authHeader = "Basic " + Base64.encodeToString("$clientId:$clientSecret".toByteArray(), Base64.NO_WRAP)
|
||||
private val client = OkHttpClient()
|
||||
|
||||
fun exchangeAuthToken(code: String) = sendTokenRequest(FormBody.Builder()
|
||||
fun exchangeAuthToken(code: String): Single<OAuthTokens> = sendTokenRequest(FormBody.Builder()
|
||||
.add("grant_type", "authorization_code")
|
||||
.add("redirect_uri", redirectUri)
|
||||
.add("code", code)
|
||||
.build())
|
||||
|
||||
fun refreshAccessToken(refreshToken: String) = sendTokenRequest(FormBody.Builder()
|
||||
fun refreshAccessToken(refreshToken: String): Single<OAuthTokens> = sendTokenRequest(FormBody.Builder()
|
||||
.add("grant_type", "refresh_token")
|
||||
.add("redirect_uri", redirectUri)
|
||||
.add("code", refreshToken)
|
||||
|
@ -57,14 +56,14 @@ class OpenHumansAPI(
|
|||
}
|
||||
}
|
||||
|
||||
fun getProjectMemberId(accessToken: String) = Request.Builder()
|
||||
fun getProjectMemberId(accessToken: String): Single<String> = Request.Builder()
|
||||
.url("$baseUrl/api/direct-sharing/project/exchange-member/?access_token=$accessToken")
|
||||
.get()
|
||||
.build()
|
||||
.toSingle()
|
||||
.map { it.jsonBody.getString("project_member_id") ?: throw OHMissingFieldException("project_member_id") }
|
||||
|
||||
fun prepareFileUpload(accessToken: String, fileName: String, metadata: FileMetadata) = Request.Builder()
|
||||
fun prepareFileUpload(accessToken: String, fileName: String, metadata: FileMetadata): Single<PreparedUpload> = Request.Builder()
|
||||
.url("$baseUrl/api/direct-sharing/project/files/upload/direct/?access_token=$accessToken")
|
||||
.post(FormBody.Builder()
|
||||
.add("filename", fileName)
|
||||
|
@ -80,7 +79,7 @@ class OpenHumansAPI(
|
|||
)
|
||||
}
|
||||
|
||||
fun uploadFile(url: String, content: ByteArray) = Request.Builder()
|
||||
fun uploadFile(url: String, content: ByteArray): Completable = Request.Builder()
|
||||
.url(url)
|
||||
.put(object : RequestBody() {
|
||||
override fun contentType(): MediaType? = null
|
||||
|
@ -100,7 +99,7 @@ class OpenHumansAPI(
|
|||
}
|
||||
.ignoreElement()
|
||||
|
||||
fun completeFileUpload(accessToken: String, fileId: String) = Request.Builder()
|
||||
fun completeFileUpload(accessToken: String, fileId: String): Completable = Request.Builder()
|
||||
.url("$baseUrl/api/direct-sharing/project/files/upload/complete/?access_token=$accessToken")
|
||||
.post(FormBody.Builder()
|
||||
.add("file_id", fileId)
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.general.openhumans
|
|||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
|
@ -10,11 +9,7 @@ import android.widget.Button
|
|||
import android.widget.CheckBox
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.browser.customtabs.CustomTabsCallback
|
||||
import androidx.browser.customtabs.CustomTabsClient
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.browser.customtabs.CustomTabsServiceConnection
|
||||
import androidx.browser.customtabs.CustomTabsSession
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
|
||||
|
@ -22,32 +17,16 @@ import io.reactivex.disposables.Disposable
|
|||
import io.reactivex.schedulers.Schedulers
|
||||
|
||||
class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
|
||||
/*
|
||||
private lateinit var customTabsClient: CustomTabsClient
|
||||
private lateinit var customTabsSession: CustomTabsSession
|
||||
|
||||
private val connection = object : CustomTabsServiceConnection() {
|
||||
override fun onCustomTabsServiceConnected(name: ComponentName, client: CustomTabsClient) {
|
||||
customTabsClient = client
|
||||
customTabsClient.warmup(0)
|
||||
customTabsSession = customTabsClient.newSession(CustomTabsCallback())!!
|
||||
customTabsSession.mayLaunchUrl(Uri.parse(OpenHumansUploader.AUTH_URL), null, null)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
//CustomTabsClient.bindCustomTabsService(this, "com.android.chrome", connection)
|
||||
setContentView(R.layout.activity_open_humans_login)
|
||||
val button = findViewById<Button>(R.id.button)
|
||||
val checkbox = findViewById<CheckBox>(R.id.checkbox)
|
||||
|
||||
button.setOnClickListener { _ ->
|
||||
if (checkbox.isChecked) {
|
||||
CustomTabsIntent.Builder()/*.setSession(customTabsSession)*/.build().launchUrl(this, Uri.parse(OpenHumansUploader.AUTH_URL))
|
||||
CustomTabsIntent.Builder().build().launchUrl(this, Uri.parse(OpenHumansUploader.AUTH_URL))
|
||||
} else {
|
||||
Toast.makeText(this, R.string.you_need_to_accept_the_of_use_first, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
@ -62,7 +41,6 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
class ExchangeAuthTokenDialog : DialogFragment() {
|
||||
|
||||
private var disposable: Disposable? = null
|
||||
|
@ -89,7 +67,6 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
override fun onDestroy() {
|
||||
disposable?.dispose()
|
||||
super.onDestroy()
|
||||
|
@ -108,8 +85,6 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ErrorDialog : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
|
|
|
@ -39,7 +39,6 @@ import java.util.*
|
|||
import java.util.concurrent.TimeUnit
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
import kotlin.math.max
|
||||
|
||||
object OpenHumansUploader : PluginBase(
|
||||
PluginDescription()
|
||||
|
@ -134,7 +133,7 @@ object OpenHumansUploader : PluginBase(
|
|||
super.onStop()
|
||||
}
|
||||
|
||||
fun queueBGReading(bgReading: BgReading) = insertQueueItem("BgReadings") {
|
||||
fun enqueueBGReading(bgReading: BgReading) = insertQueueItem("BgReadings") {
|
||||
put("date", bgReading.date)
|
||||
put("isValid", bgReading.isValid)
|
||||
put("value", bgReading.value)
|
||||
|
@ -145,7 +144,7 @@ object OpenHumansUploader : PluginBase(
|
|||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun queueCareportalEvent(careportalEvent: CareportalEvent, deleted: Boolean = false) = insertQueueItem("CareportalEvents") {
|
||||
fun enqueueCareportalEvent(careportalEvent: CareportalEvent, deleted: Boolean = false) = insertQueueItem("CareportalEvents") {
|
||||
put("date", careportalEvent.date)
|
||||
put("isValid", careportalEvent.isValid)
|
||||
put("source", careportalEvent.source)
|
||||
|
@ -166,7 +165,7 @@ object OpenHumansUploader : PluginBase(
|
|||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun queueExtendedBolus(extendedBolus: ExtendedBolus, deleted: Boolean = false) = insertQueueItem("ExtendedBoluses") {
|
||||
fun enqueueExtendedBolus(extendedBolus: ExtendedBolus, deleted: Boolean = false) = insertQueueItem("ExtendedBoluses") {
|
||||
put("date", extendedBolus.date)
|
||||
put("isValid", extendedBolus.isValid)
|
||||
put("source", extendedBolus.source)
|
||||
|
@ -178,7 +177,7 @@ object OpenHumansUploader : PluginBase(
|
|||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun queueProfileSwitch(profileSwitch: ProfileSwitch, deleted: Boolean = false) = insertQueueItem("ProfileSwitches") {
|
||||
fun enqueueProfileSwitch(profileSwitch: ProfileSwitch, deleted: Boolean = false) = insertQueueItem("ProfileSwitches") {
|
||||
put("date", profileSwitch.date)
|
||||
put("isValid", profileSwitch.isValid)
|
||||
put("source", profileSwitch.source)
|
||||
|
@ -192,7 +191,7 @@ object OpenHumansUploader : PluginBase(
|
|||
put("isDeletion", deleted)
|
||||
}
|
||||
|
||||
fun queueTotalDailyDose(tdd: TDD) = insertQueueItem("TotalDailyDoses") {
|
||||
fun enqueueTotalDailyDose(tdd: TDD) = insertQueueItem("TotalDailyDoses") {
|
||||
put("double", tdd.date)
|
||||
put("double", tdd.bolus)
|
||||
put("double", tdd.basal)
|
||||
|
@ -200,7 +199,7 @@ object OpenHumansUploader : PluginBase(
|
|||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun queueTemporaryBasal(temporaryBasal: TemporaryBasal, deleted: Boolean = false) = insertQueueItem("TemporaryBasals") {
|
||||
fun enqueueTemporaryBasal(temporaryBasal: TemporaryBasal, deleted: Boolean = false) = insertQueueItem("TemporaryBasals") {
|
||||
put("date", temporaryBasal.date)
|
||||
put("isValid", temporaryBasal.isValid)
|
||||
put("source", temporaryBasal.source)
|
||||
|
@ -215,7 +214,7 @@ object OpenHumansUploader : PluginBase(
|
|||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun queueTempTarget(tempTarget: TempTarget, deleted: Boolean = false) = insertQueueItem("TempTargets") {
|
||||
fun enqueueTempTarget(tempTarget: TempTarget, deleted: Boolean = false) = insertQueueItem("TempTargets") {
|
||||
put("date", tempTarget.date)
|
||||
put("isValid", tempTarget.isValid)
|
||||
put("source", tempTarget.source)
|
||||
|
@ -227,6 +226,40 @@ object OpenHumansUploader : PluginBase(
|
|||
put("isDeletion", deleted)
|
||||
}
|
||||
|
||||
fun enqueueSMBData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONArray, mealData: JSONObject, currentTemp: JSONObject, autosensData: JSONObject, smbAllowed: Boolean, smbAlwaysAllowed: Boolean, result: JSONObject) = insertQueueItem("APSData") {
|
||||
put("algorithm", "SMB")
|
||||
put("profile", profile)
|
||||
put("glucoseStatus", glucoseStatus)
|
||||
put("iobData", iobData)
|
||||
put("mealData", mealData)
|
||||
put("currentTemp", currentTemp)
|
||||
put("autosensData", autosensData)
|
||||
put("smbAllowed", smbAllowed)
|
||||
put("smbAlwaysAllowed", smbAlwaysAllowed)
|
||||
put("result", result)
|
||||
}
|
||||
|
||||
fun enqueueAMAData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONArray, mealData: JSONObject, currentTemp: JSONObject, autosensData: JSONObject, result: JSONObject) = insertQueueItem("APSData") {
|
||||
put("algorithm", "AMA")
|
||||
put("profile", profile)
|
||||
put("glucoseStatus", glucoseStatus)
|
||||
put("iobData", iobData)
|
||||
put("mealData", mealData)
|
||||
put("currentTemp", currentTemp)
|
||||
put("autosensData", autosensData)
|
||||
put("result", result)
|
||||
}
|
||||
|
||||
fun enqueueAMAData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONObject, mealData: JSONObject, currentTemp: JSONObject, result: JSONObject) = insertQueueItem("APSData") {
|
||||
put("algorithm", "MA")
|
||||
put("profile", profile)
|
||||
put("glucoseStatus", glucoseStatus)
|
||||
put("iobData", iobData)
|
||||
put("mealData", mealData)
|
||||
put("currentTemp", currentTemp)
|
||||
put("result", result)
|
||||
}
|
||||
|
||||
private fun insertQueueItem(file: String, structureVersion: Int = 1, generator: JSONObject.() -> Unit) {
|
||||
if (oAuthTokens != null && this.isEnabled(PluginType.GENERAL)) {
|
||||
try {
|
||||
|
@ -282,25 +315,25 @@ object OpenHumansUploader : PluginBase(
|
|||
.andThen(Single.defer { Single.just(MainApp.getDbHelper().countOfAllRows) })
|
||||
.doOnSuccess { maxProgress = it }
|
||||
.flatMapObservable { Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allBgReadings) } }
|
||||
.map { queueBGReading(it); increaseCounter() }
|
||||
.map { enqueueBGReading(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allCareportalEvents) })
|
||||
.map { queueCareportalEvent(it); increaseCounter() }
|
||||
.map { enqueueCareportalEvent(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allExtendedBoluses) })
|
||||
.map { queueExtendedBolus(it); increaseCounter() }
|
||||
.map { enqueueExtendedBolus(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allProfileSwitches) })
|
||||
.map { queueProfileSwitch(it); increaseCounter() }
|
||||
.map { enqueueProfileSwitch(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTDDs) })
|
||||
.map { queueTotalDailyDose(it); increaseCounter() }
|
||||
.map { enqueueTotalDailyDose(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTemporaryBasals) })
|
||||
.map { queueTemporaryBasal(it); increaseCounter() }
|
||||
.map { enqueueTemporaryBasal(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTempTargets) })
|
||||
.map { queueTempTarget(it); increaseCounter() }
|
||||
.map { enqueueTempTarget(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.doOnSubscribe {
|
||||
wakeLock.acquire(TimeUnit.MINUTES.toMillis(20))
|
||||
|
|
Loading…
Reference in a new issue