postpone EventAutosensCalculationFinished

This commit is contained in:
Milos Kozak 2018-07-20 22:40:44 +02:00
parent ab70d5b67d
commit b52c1f3aa6
2 changed files with 14 additions and 4 deletions

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.IobCobCalculator;
import android.content.Context;
import android.os.PowerManager;
import android.os.SystemClock;
import android.support.v4.util.LongSparseArray;
import com.crashlytics.android.answers.CustomEvent;
@ -69,6 +70,7 @@ public class IobCobOref1Thread extends Thread {
public final void run() {
mWakeLock.acquire();
try {
log.debug("AUTOSENSDATA thread started: " + from);
if (MainApp.getConfigBuilder() == null) {
log.debug("Aborting calculation thread (ConfigBuilder not ready): " + from);
return; // app still initializing
@ -346,11 +348,14 @@ public class IobCobOref1Thread extends Thread {
log.debug(autosensData.toString());
}
}
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
log.debug("Finishing calculation thread: " + from);
new Thread(() -> {
SystemClock.sleep(1000);
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
}).start();
} finally {
mWakeLock.release();
MainApp.bus().post(new EventIobCalculationProgress(""));
log.debug("AUTOSENSDATA thread ended: " + from);
}
}

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.IobCobCalculator;
import android.content.Context;
import android.os.PowerManager;
import android.os.SystemClock;
import android.support.v4.util.LongSparseArray;
import com.crashlytics.android.answers.CustomEvent;
@ -68,6 +69,7 @@ public class IobCobThread extends Thread {
public final void run() {
mWakeLock.acquire();
try {
log.debug("AUTOSENSDATA thread started: " + from);
if (MainApp.getConfigBuilder() == null) {
log.debug("Aborting calculation thread (ConfigBuilder not ready): " + from);
return; // app still initializing
@ -273,11 +275,14 @@ public class IobCobThread extends Thread {
log.debug(autosensData.toString());
}
}
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
log.debug("Finishing calculation thread: " + from);
new Thread(() -> {
SystemClock.sleep(1000);
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
}).start();
} finally {
mWakeLock.release();
MainApp.bus().post(new EventIobCalculationProgress(""));
log.debug("AUTOSENSDATA thread ended: " + from);
}
}