more profile tweaking

This commit is contained in:
Milos Kozak 2021-11-02 12:45:34 +01:00
parent ca39802e6d
commit b4dec7195c
4 changed files with 15 additions and 16 deletions

View file

@ -23,11 +23,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction
import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged
import info.nightscout.androidaps.receivers.DataWorker
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.JsonHelper
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
@ -127,8 +123,8 @@ class LocalProfilePlugin @Inject constructor(
val low = blockFromJsonArray(targetLow, dateUtil)
val high = blockFromJsonArray(targetHigh, dateUtil)
if (mgdl) {
if (blockFromJsonArray(isf, dateUtil)?.any { it.amount < HardLimits.MIN_ISF || it.amount > HardLimits.MAX_ISF } != false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_isf_values))
if (blockFromJsonArray(isf, dateUtil)?.any { hardLimits.isInRange(it.amount, HardLimits.MIN_ISF, HardLimits.MAX_ISF) } == false) {
ToastUtils.errorToast(activity, resourceHelper.gs(R.string.error_in_isf_values))
return false
}
if (blockFromJsonArray(basal, dateUtil)?.any { it.amount < pumpDescription.basalMinimumRate || it.amount > 10.0 } != false) {
@ -144,8 +140,7 @@ class LocalProfilePlugin @Inject constructor(
return false
}
} else {
if (blockFromJsonArray(isf, dateUtil)?.any { it.amount < Profile.toMgdl(HardLimits.MIN_ISF, GlucoseUnit.MMOL) || it.amount > Profile.toMgdl(HardLimits.MAX_ISF, GlucoseUnit.MMOL)
} != false) {
if (blockFromJsonArray(isf, dateUtil)?.any { hardLimits.isInRange(Profile.toMgdl(it.amount, GlucoseUnit.MMOL), HardLimits.MIN_ISF, HardLimits.MAX_ISF) } == false) {
ToastUtils.errorToast(activity,resourceHelper.gs(R.string.error_in_isf_values))
return false
}
@ -482,7 +477,7 @@ class LocalProfilePlugin @Inject constructor(
?: return Result.failure(workDataOf("Error" to "missing input data"))
if (sp.getBoolean(R.string.key_ns_receive_profile_store, true) || config.NSCLIENT) {
val store = ProfileStore(injector, profileJson, dateUtil)
val createdAt = store.getCreatedAt()
val createdAt = store.getStartDate()
val lastLocalChange = sp.getLong(R.string.key_local_profile_last_change, 0)
aapsLogger.debug(LTag.PROFILE, "Received profileStore: createdAt: $createdAt Local last modification: $lastLocalChange")
@Suppress("LiftReturnOrAssignment")

View file

@ -212,6 +212,7 @@ sealed class ProfileSealed(
if (getTargetLowMgdlTimeFromMidnight(seconds) != profile.getTargetLowMgdlTimeFromMidnight(seconds)) return false
if (getTargetHighMgdlTimeFromMidnight(seconds) != profile.getTargetHighMgdlTimeFromMidnight(seconds)) return false
if (dia != profile.dia) return false
if ((profile is EPS) && profileName != profile.value.originalProfileName) return false // handle profile name change too
}
return true
}

View file

@ -31,8 +31,8 @@ class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject, val d
return null
}
fun getCreatedAt(): Long {
val iso = JsonHelper.safeGetString(data, "created_at") ?: return 0
fun getStartDate(): Long {
val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0
return try {
dateUtil.fromISODateString(iso)
} catch (e: Exception) {

View file

@ -22,6 +22,8 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
public class ToastUtils {
private static Toast lastToast = null;
public static class Long {
public static void warnToast(final Context ctx, final String string) {
@ -76,10 +78,11 @@ public class ToastUtils {
ImageView toastIcon = toastRoot.findViewById(android.R.id.icon);
toastIcon.setImageResource(iconId);
Toast toast = new Toast(ctx);
toast.setDuration(isShort ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
toast.setView(toastRoot);
toast.show();
if (lastToast != null) lastToast.cancel();
lastToast = new Toast(ctx);
lastToast.setDuration(isShort ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG);
lastToast.setView(toastRoot);
lastToast.show();
});
}