allow revert objective

This commit is contained in:
Milos Kozak 2019-11-30 22:15:15 +01:00
parent 034c16690f
commit c23794fa6e
4 changed files with 29 additions and 17 deletions

View file

@ -225,8 +225,9 @@ class ObjectivesFragment : Fragment() {
SntpClient.ntpTime(object : SntpClient.Callback() { SntpClient.ntpTime(object : SntpClient.Callback() {
override fun run() { override fun run() {
log.debug("NTP time: $time System time: ${DateUtil.now()}") log.debug("NTP time: $time System time: ${DateUtil.now()}")
SystemClock.sleep(300)
if (!networkConnected) { if (!networkConnected) {
RxBus.send(EventNtpStatus(MainApp.gs(R.string.notconnected), 100)) RxBus.send(EventNtpStatus(MainApp.gs(R.string.notconnected), 99))
} else if (success) { } else if (success) {
if (objective.isCompleted(time)) { if (objective.isCompleted(time)) {
objective.accomplishedOn = time objective.accomplishedOn = time
@ -236,10 +237,10 @@ class ObjectivesFragment : Fragment() {
SystemClock.sleep(100) SystemClock.sleep(100)
scrollToCurrentObjective() scrollToCurrentObjective()
} else { } else {
RxBus.send(EventNtpStatus(MainApp.gs(R.string.requirementnotmet), 100)) RxBus.send(EventNtpStatus(MainApp.gs(R.string.requirementnotmet), 99))
} }
} else { } else {
RxBus.send(EventNtpStatus(MainApp.gs(R.string.failedretrievetime), 100)) RxBus.send(EventNtpStatus(MainApp.gs(R.string.failedretrievetime), 99))
} }
} }
}, NetworkChangeReceiver.isConnected()) }, NetworkChangeReceiver.isConnected())
@ -261,26 +262,29 @@ class ObjectivesFragment : Fragment() {
SntpClient.ntpTime(object : SntpClient.Callback() { SntpClient.ntpTime(object : SntpClient.Callback() {
override fun run() { override fun run() {
log.debug("NTP time: $time System time: ${DateUtil.now()}") log.debug("NTP time: $time System time: ${DateUtil.now()}")
SystemClock.sleep(300)
if (!networkConnected) { if (!networkConnected) {
RxBus.send(EventNtpStatus(MainApp.gs(R.string.notconnected), 100)) RxBus.send(EventNtpStatus(MainApp.gs(R.string.notconnected), 99))
} else if (success) { } else if (success) {
objective.startedOn = time objective.startedOn = time
RxBus.send(EventNtpStatus(MainApp.gs(R.string.success), 100)) RxBus.send(EventNtpStatus(MainApp.gs(R.string.success), 100))
SystemClock.sleep(1000) SystemClock.sleep(1000)
RxBus.send(EventObjectivesUpdateGui()) RxBus.send(EventObjectivesUpdateGui())
SystemClock.sleep(100) SystemClock.sleep(100)
scrollToCurrentObjective() scrollToCurrentObjective()
} else { } else {
RxBus.send(EventNtpStatus(MainApp.gs(R.string.failedretrievetime), 100)) RxBus.send(EventNtpStatus(MainApp.gs(R.string.failedretrievetime), 99))
} }
} }
}, NetworkChangeReceiver.isConnected()) }, NetworkChangeReceiver.isConnected())
}.start() }.start()
} }
holder.unStart.setOnClickListener { holder.unStart.setOnClickListener {
objective.startedOn = 0 OKDialog.showConfirmation(activity, MainApp.gs(R.string.doyouwantresetstart)) {
scrollToCurrentObjective() objective.startedOn = 0
RxBus.send(EventObjectivesUpdateGui()) scrollToCurrentObjective()
RxBus.send(EventObjectivesUpdateGui())
}
} }
holder.unFinish.setOnClickListener { holder.unFinish.setOnClickListener {
objective.accomplishedOn = 0 objective.accomplishedOn = 0

View file

@ -42,6 +42,7 @@ class NtpProgressDialog : DialogFragment() {
overview_bolusprogress_status.setText(state) overview_bolusprogress_status.setText(state)
overview_bolusprogress_progressbar.setMax(100) overview_bolusprogress_progressbar.setMax(100)
overview_bolusprogress_progressbar.setProgress(percent) overview_bolusprogress_progressbar.setProgress(percent)
overview_bolusprogress_stop.text = MainApp.gs(R.string.close)
} }
override fun onResume() { override fun onResume() {

View file

@ -16,12 +16,16 @@ package info.nightscout.androidaps.utils;
*/ */
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.DatagramPacket; import java.net.DatagramPacket;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import info.nightscout.androidaps.logging.L;
/** /**
* {@hide} * {@hide}
* <p> * <p>
@ -35,7 +39,7 @@ import java.net.InetAddress;
* </pre> * </pre>
*/ */
public class SntpClient { public class SntpClient {
private static final String TAG = "SntpClient"; private static Logger log = LoggerFactory.getLogger(L.CORE);
//private static final int REFERENCE_TIME_OFFSET = 16; //private static final int REFERENCE_TIME_OFFSET = 16;
private static final int ORIGINATE_TIME_OFFSET = 24; private static final int ORIGINATE_TIME_OFFSET = 24;
@ -76,8 +80,10 @@ public class SntpClient {
} }
static void doNtpTime(final Callback callback) { static void doNtpTime(final Callback callback) {
log.debug("Time detection started");
callback.success = requestTime("time.google.com", 5000); callback.success = requestTime("time.google.com", 5000);
callback.time = getNtpTime() + SystemClock.elapsedRealtime() - getNtpTimeReference(); callback.time = getNtpTime() + SystemClock.elapsedRealtime() - getNtpTimeReference();
log.debug("Time detection ended: " + callback.success + " " + DateUtil.dateAndTimeString(getNtpTime()));
callback.run(); callback.run();
} }
@ -138,7 +144,7 @@ public class SntpClient {
mNtpTimeReference = responseTicks; mNtpTimeReference = responseTicks;
mRoundTripTime = roundTripTime; mRoundTripTime = roundTripTime;
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG, "request time failed: " + e); log.debug("request time failed: " + e);
return false; return false;
} }

View file

@ -1634,5 +1634,6 @@
<string name="objectives_button_unfinish">Clear finished</string> <string name="objectives_button_unfinish">Clear finished</string>
<string name="objectives_button_unstart">Clear started</string> <string name="objectives_button_unstart">Clear started</string>
<string name="timedetection">Time detection</string> <string name="timedetection">Time detection</string>
<string name="doyouwantresetstart">Do you want reset objective start? You may lose your progress.</string>
</resources> </resources>