network status before time

This commit is contained in:
AdrianLxM 2019-10-13 17:58:45 +02:00
parent 14dd29befd
commit fa20af4440
9 changed files with 33 additions and 13 deletions

View file

@ -51,7 +51,6 @@ class ObjectivesFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
objectives_recyclerview.layoutManager = LinearLayoutManager(view.context) objectives_recyclerview.layoutManager = LinearLayoutManager(view.context)
objectives_recyclerview.adapter = objectivesAdapter objectives_recyclerview.adapter = objectivesAdapter
objectives_fake.setOnClickListener { updateGUI() } objectives_fake.setOnClickListener { updateGUI() }
@ -208,15 +207,16 @@ class ObjectivesFragment : Fragment() {
holder.accomplished.setTextColor(-0x3e3e3f) holder.accomplished.setTextColor(-0x3e3e3f)
holder.verify.setOnClickListener { holder.verify.setOnClickListener {
holder.verify.visibility = View.INVISIBLE holder.verify.visibility = View.INVISIBLE
NetworkChangeReceiver.fetch()
SntpClient.ntpTime(object : SntpClient.Callback() { SntpClient.ntpTime(object : SntpClient.Callback() {
override fun run() { override fun run() {
activity?.runOnUiThread { activity?.runOnUiThread {
holder.verify.visibility = View.VISIBLE holder.verify.visibility = View.VISIBLE
log.debug("NTP time: $time System time: ${DateUtil.now()}") log.debug("NTP time: $time System time: ${DateUtil.now()}")
if (!networkConnected) { if (!networkConnected && !objectives_fake.isChecked) {
ToastUtils.showToastInUiThread(context, R.string.notconnected) ToastUtils.showToastInUiThread(context, R.string.notconnected)
} else if (success) { } else if (success) {
if (objective.isCompleted(time)) { if (objective.isCompleted(time) || objectives_fake.isChecked) {
objective.accomplishedOn = time objective.accomplishedOn = time
notifyDataSetChanged() notifyDataSetChanged()
scrollToCurrentObjective() scrollToCurrentObjective()
@ -233,12 +233,13 @@ class ObjectivesFragment : Fragment() {
} }
holder.start.setOnClickListener { holder.start.setOnClickListener {
holder.start.visibility = View.INVISIBLE holder.start.visibility = View.INVISIBLE
NetworkChangeReceiver.fetch()
SntpClient.ntpTime(object : SntpClient.Callback() { SntpClient.ntpTime(object : SntpClient.Callback() {
override fun run() { override fun run() {
activity?.runOnUiThread { activity?.runOnUiThread {
holder.start.visibility = View.VISIBLE holder.start.visibility = View.VISIBLE
log.debug("NTP time: $time System time: ${DateUtil.now()}") log.debug("NTP time: $time System time: ${DateUtil.now()}")
if (!networkConnected) { if (!networkConnected && !objectives_fake.isChecked) {
ToastUtils.showToastInUiThread(context, R.string.notconnected) ToastUtils.showToastInUiThread(context, R.string.notconnected)
} else if (success) { } else if (success) {
objective.startedOn = time objective.startedOn = time

View file

@ -57,12 +57,11 @@ class ObjectivesExamDialog : DialogFragment() {
objectives_exam_question.setText(task.question) objectives_exam_question.setText(task.question)
// Options // Options
objectives_exam_options.removeAllViews() objectives_exam_options.removeAllViews()
for (o in task.options) { task.options.forEach {
val option: Option = o as Option; val cb = it.generate(context)
val cb = option.generate(context)
if (task.answered) { if (task.answered) {
cb.isEnabled = false cb.isEnabled = false
if (option.isCorrect) if (it.isCorrect)
cb.isChecked = true cb.isChecked = true
} }
objectives_exam_options.addView(cb) objectives_exam_options.addView(cb)

View file

@ -230,7 +230,7 @@ public abstract class Objective {
return question; return question;
} }
public List getOptions() { public List<Objective.Option> getOptions() {
return options; return options;
} }

View file

@ -199,6 +199,11 @@ public class Objective2 extends Objective {
.hint(new Hint(R.string.profileswitchtime_hint1)) .hint(new Hint(R.string.profileswitchtime_hint1))
); );
tasks.add(new ExamTask(R.string.other_medication_label, R.string.other_medication_text,"otherMedicationWarning")
.option(new Option(R.string.yes, true))
.option(new Option(R.string.no, false))
);
for (Task task : tasks) for (Task task : tasks)
Collections.shuffle(((ExamTask)task).options); Collections.shuffle(((ExamTask)task).options);
} }

View file

@ -23,7 +23,7 @@ class NsClientReceiverDelegate {
private final Context context; private final Context context;
private final Bus bus; private final Bus bus;
private NetworkChangeReceiver networkChangeReceiver = new NetworkChangeReceiver(); private NetworkChangeReceiver networkChangeReceiver = NetworkChangeReceiver.instance;
private ChargingStateReceiver chargingStateReceiver = new ChargingStateReceiver(); private ChargingStateReceiver chargingStateReceiver = new ChargingStateReceiver();
private boolean allowedChargingState = true; private boolean allowedChargingState = true;

View file

@ -8,6 +8,7 @@ import android.net.NetworkInfo;
import android.net.wifi.SupplicantState; import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo; import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -23,6 +24,17 @@ public class NetworkChangeReceiver extends BroadcastReceiver {
private static EventNetworkChange lastEvent = null; private static EventNetworkChange lastEvent = null;
public static final NetworkChangeReceiver instance = new NetworkChangeReceiver();
// TODO: Split NSClient into network state component that can be used by several plugins and logic for plugin
public static void fetch() {
NetworkChangeReceiver.instance.grabNetworkStatus(MainApp.instance().getApplicationContext());
}
private NetworkChangeReceiver() {
super();
}
@Override @Override
public void onReceive(final Context context, final Intent intent) { public void onReceive(final Context context, final Intent intent) {
EventNetworkChange event = grabNetworkStatus(context); EventNetworkChange event = grabNetworkStatus(context);
@ -71,7 +83,7 @@ public class NetworkChangeReceiver extends BroadcastReceiver {
return lastEvent != null && lastEvent.wifiConnected; return lastEvent != null && lastEvent.wifiConnected;
} }
public static boolean isConnected() { public static boolean isConnected() {
return lastEvent != null && (lastEvent.wifiConnected || lastEvent.mobileConnected); return lastEvent != null && (lastEvent.wifiConnected || lastEvent.mobileConnected);
} }

View file

@ -105,7 +105,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="Disabled to:" android:text="Disabled until:"
android:textColor="#FF5722" android:textColor="#FF5722"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

View file

@ -162,5 +162,8 @@
<string name="basalhelp_diabetesteam">Your diabetes team</string> <string name="basalhelp_diabetesteam">Your diabetes team</string>
<string name="basalhelp_google">Google</string> <string name="basalhelp_google">Google</string>
<string name="basalhelp_facebook">Facebook</string> <string name="basalhelp_facebook">Facebook</string>
<string name="other_medication_label">Other Medication</string>
<string name="other_medication_text">AAPS reduces BR to raise blood sugar. Drugs from the group of SGLT2 inhibitors (gliflozins) can prevent the expected increase and thus may produce a dangerous insulin deficiency (DKA).
\nCommon brand names are: Invokana®, Forxiga®, Jardiance®, Steglatro®, Suglat®, Apleway®, Deberza®, Synjardy®, Vokanamet®, Xigduo®.\n\nI hereby confirm that I will not take such drugs when using AAPS or will deactivate the loop before using these drugs.</string>
</resources> </resources>

View file

@ -52,7 +52,7 @@
<string name="codeinvalid">Code invalid</string> <string name="codeinvalid">Code invalid</string>
<string name="objectives_exam_objective">Prove your knowledge</string> <string name="objectives_exam_objective">Prove your knowledge</string>
<string name="objectives_exam_gate">Study and answer questions correctly</string> <string name="objectives_exam_gate">Study and answer questions correctly</string>
<string name="answerdisabledto">Answering disabled to: %1$s</string> <string name="answerdisabledto">Answering disabled until: %1$s</string>
<string name="wronganswer">Wrong answer!</string> <string name="wronganswer">Wrong answer!</string>
<string name="unfinshed_button">Next unfinished</string> <string name="unfinshed_button">Next unfinished</string>
<string name="requestcode">Request code: %1$s</string> <string name="requestcode">Request code: %1$s</string>