reset time button

This commit is contained in:
Milos Kozak 2019-06-05 00:22:57 +02:00
parent e32801ca6b
commit 8ea5968f4d
4 changed files with 39 additions and 20 deletions

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader; import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader;
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload; import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload;
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData; import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData;
import info.nightscout.androidaps.utils.SP;
public class TidepoolJavaFragment extends SubscriberFragment { public class TidepoolJavaFragment extends SubscriberFragment {
@Override @Override
@ -20,17 +21,19 @@ public class TidepoolJavaFragment extends SubscriberFragment {
View view = inflater.inflate(R.layout.tidepool_fragment, container, false); View view = inflater.inflate(R.layout.tidepool_fragment, container, false);
Button login = view.findViewById(R.id.tidepool_login); Button login = view.findViewById(R.id.tidepool_login);
login.setOnClickListener(v -> { login.setOnClickListener(v1 -> {
TidepoolUploader.INSTANCE.doLogin(); TidepoolUploader.INSTANCE.doLogin();
}); });
Button uploadnow = view.findViewById(R.id.tidepool_uploadnow); Button uploadnow = view.findViewById(R.id.tidepool_uploadnow);
uploadnow.setOnClickListener(v -> { uploadnow.setOnClickListener(v2 -> MainApp.bus().post(new EventTidepoolDoUpload()));
MainApp.bus().post(new EventTidepoolDoUpload());
});
Button removeall = view.findViewById(R.id.tidepool_removeall); Button removeall = view.findViewById(R.id.tidepool_removeall);
removeall.setOnClickListener(v -> { removeall.setOnClickListener(v3 -> {
MainApp.bus().post(new EventTidepoolResetData()); MainApp.bus().post(new EventTidepoolResetData());
}); });
Button resetStart = view.findViewById(R.id.tidepool_resertstart);
resetStart.setOnClickListener(v4 -> {
SP.putLong(R.string.key_tidepool_last_end, 0);
});
return view; return view;
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.general.tidepool package info.nightscout.androidaps.plugins.general.tidepool
import android.text.Html
import com.squareup.otto.Subscribe import com.squareup.otto.Subscribe
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
@ -11,13 +12,14 @@ import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.general.tidepool.comm.Session import info.nightscout.androidaps.plugins.general.tidepool.comm.Session
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader
import info.nightscout.androidaps.plugins.general.tidepool.comm.UploadChunk
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolResetData
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
import info.nightscout.androidaps.plugins.general.tidepool.utils.RateLimit import info.nightscout.androidaps.plugins.general.tidepool.utils.RateLimit
import info.nightscout.androidaps.receivers.ChargingStateReceiver import info.nightscout.androidaps.receivers.ChargingStateReceiver
import info.nightscout.androidaps.utils.SP import info.nightscout.androidaps.utils.SP
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.util.*
object TidepoolPlugin : PluginBase(PluginDescription() object TidepoolPlugin : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL) .mainType(PluginType.GENERAL)
@ -32,6 +34,13 @@ object TidepoolPlugin : PluginBase(PluginDescription()
var session: Session? = null var session: Session? = null
private val listLog = ArrayList<EventTidepoolStatus>()
internal var textLog = Html.fromHtml("")
var paused: Boolean = false
internal var autoscroll: Boolean = false
var status = ""
override fun onStart() { override fun onStart() {
MainApp.bus().register(this) MainApp.bus().register(this)
super.onStart() super.onStart()

View file

@ -30,7 +30,7 @@ object UploadChunk {
val result = get(session.start, session.end) val result = get(session.start, session.end)
if (result != null && result.length < 3) { if (result != null && result.length < 3) {
if (L.isEnabled(L.TIDEPOOL)) log.debug("No records in this time period, setting start to best end time") if (L.isEnabled(L.TIDEPOOL)) log.debug("No records in this time period, setting start to best end time")
setLastEnd(Math.max(session.end, getOldestRecordTimeStamp())) setLastEnd(Math.max(session.end, getOldestRecordTimeStamp()))
} }
return result return result
@ -38,13 +38,13 @@ object UploadChunk {
operator fun get(start: Long, end: Long): String? { operator fun get(start: Long, end: Long): String? {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Syncing data between: " + DateUtil.dateAndTimeFullString(start) + " -> " + DateUtil.dateAndTimeFullString(end)) if (L.isEnabled(L.TIDEPOOL)) log.debug("Syncing data between: " + DateUtil.dateAndTimeFullString(start) + " -> " + DateUtil.dateAndTimeFullString(end))
if (end <= start) { if (end <= start) {
if (L.isEnabled(L.TIDEPOOL)) log.debug("End is <= start: " + DateUtil.dateAndTimeFullString(start) + " " + DateUtil.dateAndTimeFullString(end)) if (L.isEnabled(L.TIDEPOOL)) log.debug("End is <= start: " + DateUtil.dateAndTimeFullString(start) + " " + DateUtil.dateAndTimeFullString(end))
return null return null
} }
if (end - start > MAX_UPLOAD_SIZE) { if (end - start > MAX_UPLOAD_SIZE) {
if (L.isEnabled(L.TIDEPOOL)) log.debug("More than max range - rejecting") if (L.isEnabled(L.TIDEPOOL)) log.debug("More than max range - rejecting")
return null return null
} }
@ -63,7 +63,7 @@ object UploadChunk {
val value = getLatencySliderValue(SP.getInt(R.string.key_tidepool_window_latency, 0)).toLong() val value = getLatencySliderValue(SP.getInt(R.string.key_tidepool_window_latency, 0)).toLong()
return Math.max(T.mins(value).msecs(), DEFAULT_WINDOW_OFFSET) return Math.max(T.mins(value).msecs(), DEFAULT_WINDOW_OFFSET)
} catch (e: Exception) { } catch (e: Exception) {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Reverting to default of 15 minutes due to Window Size exception: $e") if (L.isEnabled(L.TIDEPOOL)) log.debug("Reverting to default of 15 minutes due to Window Size exception: $e")
return DEFAULT_WINDOW_OFFSET // default return DEFAULT_WINDOW_OFFSET // default
} }
@ -82,9 +82,9 @@ object UploadChunk {
fun setLastEnd(time: Long) { fun setLastEnd(time: Long) {
if (time > getLastEnd()) { if (time > getLastEnd()) {
SP.putLong(R.string.key_tidepool_last_end, time) SP.putLong(R.string.key_tidepool_last_end, time)
if (L.isEnabled(L.TIDEPOOL)) log.debug("Updating last end to: " + DateUtil.dateAndTimeFullString(time)) if (L.isEnabled(L.TIDEPOOL)) log.debug("Updating last end to: " + DateUtil.dateAndTimeFullString(time))
} else { } else {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot set last end to: " + DateUtil.dateAndTimeFullString(time) + " vs " + DateUtil.dateAndTimeFullString(getLastEnd())) if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot set last end to: " + DateUtil.dateAndTimeFullString(time) + " vs " + DateUtil.dateAndTimeFullString(getLastEnd()))
} }
} }
@ -113,9 +113,9 @@ object UploadChunk {
val end = DateUtil.now() val end = DateUtil.now()
val bgReadingList = MainApp.getDbHelper().getBgreadingsDataFromTime(start, end, false) val bgReadingList = MainApp.getDbHelper().getBgreadingsDataFromTime(start, end, false)
return if (bgReadingList != null && bgReadingList.size > 0) { return if (bgReadingList.size > 0)
bgReadingList[0].date bgReadingList[0].date
} else -1 else -1
} }
@Suppress("UNUSED_PARAMETER") @Suppress("UNUSED_PARAMETER")
@ -141,15 +141,15 @@ object UploadChunk {
if (current != null) { if (current != null) {
if (this_rate != current.rate) { if (this_rate != current.rate) {
current.duration = temporaryBasal.date - current.timestamp current.duration = temporaryBasal.date - current.timestamp
if (L.isEnabled(L.TIDEPOOL)) log.debug("Adding current: " + current.toS()) if (L.isEnabled(L.TIDEPOOL)) log.debug("Adding current: " + current.toS())
if (current.isValid()) { if (current.isValid()) {
basals.add(current) basals.add(current)
} else { } else {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Current basal is invalid: " + current.toS()) if (L.isEnabled(L.TIDEPOOL)) log.debug("Current basal is invalid: " + current.toS())
} }
current = null current = null
} else { } else {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Same rate as previous basal record: " + current.rate + " " + temporaryBasal.toStringFull()) if (L.isEnabled(L.TIDEPOOL)) log.debug("Same rate as previous basal record: " + current.rate + " " + temporaryBasal.toStringFull())
} }
} }
if (current == null) { if (current == null) {

View file

@ -18,7 +18,6 @@
android:id="@+id/tidepool_uploadnow" android:id="@+id/tidepool_uploadnow"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:text="Upload now" android:text="Upload now"
app:layout_constraintStart_toEndOf="@+id/tidepool_login" app:layout_constraintStart_toEndOf="@+id/tidepool_login"
tools:layout_editor_absoluteY="66dp" /> tools:layout_editor_absoluteY="66dp" />
@ -27,7 +26,6 @@
android:id="@+id/tidepool_removeall" android:id="@+id/tidepool_removeall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="Remove all" android:text="Remove all"
app:layout_constraintStart_toEndOf="@+id/tidepool_uploadnow" app:layout_constraintStart_toEndOf="@+id/tidepool_uploadnow"
tools:layout_editor_absoluteY="66dp" /> tools:layout_editor_absoluteY="66dp" />
@ -48,4 +46,13 @@
android:text="Login" android:text="Login"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="66dp" /> tools:layout_editor_absoluteY="66dp" />
<Button
android:id="@+id/tidepool_resertstart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="308dp"
android:text="Reset start"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="66dp" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>