Merge branch 'adrian/glif-objective' into devmerge

This commit is contained in:
AdrianLxM 2019-10-24 19:46:24 +02:00
commit 2a7a004afd
9 changed files with 32 additions and 13 deletions

View file

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

View file

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

View file

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

View file

@ -199,6 +199,11 @@ public class Objective2 extends Objective {
.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)
Collections.shuffle(((ExamTask)task).options);
}

View file

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

View file

@ -24,6 +24,17 @@ public class NetworkChangeReceiver extends BroadcastReceiver {
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
public void onReceive(final Context context, final Intent intent) {
EventNetworkChange event = grabNetworkStatus(context);
@ -72,7 +83,7 @@ public class NetworkChangeReceiver extends BroadcastReceiver {
return lastEvent != null && lastEvent.getWifiConnected();
}
public static boolean isConnected() {
public static boolean isConnected() {
return lastEvent != null && (lastEvent.getWifiConnected() || lastEvent.getMobileConnected());
}

View file

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

View file

@ -162,5 +162,8 @@
<string name="basalhelp_diabetesteam">Your diabetes team</string>
<string name="basalhelp_google">Google</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 in BG 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 promise that I will not take such drugs when using AAPS or will deactivate the loop before using these drugs.</string>
</resources>

View file

@ -52,7 +52,7 @@
<string name="codeinvalid">Code invalid</string>
<string name="objectives_exam_objective">Prove your knowledge</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="unfinshed_button">Next unfinished</string>
<string name="requestcode">Request code: %1$s</string>