diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt
index 5266c0781c..1db87f6472 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationFragment.kt
@@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.general.automation
import android.os.Bundle
+import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -16,12 +17,12 @@ import info.nightscout.androidaps.plugins.general.automation.dragHelpers.SimpleI
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui
import info.nightscout.androidaps.utils.FabricPrivacy
+import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.plusAssign
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.automation_fragment.*
-
class AutomationFragment : Fragment(), OnStartDragListener {
private var disposable: CompositeDisposable = CompositeDisposable()
@@ -40,6 +41,8 @@ class AutomationFragment : Fragment(), OnStartDragListener {
automation_eventListView.layoutManager = LinearLayoutManager(context)
automation_eventListView.adapter = eventListAdapter
+ automation_logView.setMovementMethod(ScrollingMovementMethod())
+
automation_fabAddEvent.setOnClickListener {
val dialog = EditEventDialog()
val args = Bundle()
@@ -88,8 +91,8 @@ class AutomationFragment : Fragment(), OnStartDragListener {
eventListAdapter?.notifyDataSetChanged()
val sb = StringBuilder()
for (l in AutomationPlugin.executionLog.reversed())
- sb.append(l).append("\n")
- automation_logView?.text = sb.toString()
+ sb.append(l).append("
")
+ automation_logView?.text = HtmlHelper.fromHtml(sb.toString())
}
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt
index b559311f9d..0d220c2dd4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt
@@ -178,10 +178,10 @@ object AutomationPlugin : PluginBase(PluginDescription()
val sb = StringBuilder()
sb.append(DateUtil.timeString(DateUtil.now()))
sb.append(" ")
- sb.append(if (result.success) "☺" else "X")
- sb.append(" ")
+ sb.append(if (result.success) "☺" else "▼")
+ sb.append(" ")
sb.append(event.title)
- sb.append(": ")
+ sb.append(": ")
sb.append(action.shortDescription())
sb.append(": ")
sb.append(result.comment)
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.java
index 7171368124..63c923fdcf 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitch.java
@@ -26,13 +26,24 @@ import info.nightscout.androidaps.utils.JsonHelper;
public class ActionProfileSwitch extends Action {
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
- public InputProfileName inputProfileName = new InputProfileName(ProfileFunctions.getInstance().getProfileName());
+ InputProfileName inputProfileName;
String profileName = "";
public ActionProfileSwitch() {
// Prevent action if active profile is already active
// but we don't have a trigger IS_NOT_EQUAL
// so check is in the doRun()
+ ProfileInterface profileInterface = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
+ if (profileInterface != null) {
+ ProfileStore profileStore = profileInterface.getProfile();
+ if (profileStore != null) {
+ String name = profileStore.getDefaultProfileName();
+ if (name != null) {
+ profileName = name;
+ }
+ }
+ }
+ inputProfileName = new InputProfileName(profileName);
}
@Override
@@ -51,19 +62,39 @@ public class ActionProfileSwitch extends Action {
String activeProfileName = ProfileFunctions.getInstance().getProfileName();
//Check for uninitialized profileName
- if ( profileName.equals("")){ profileName = activeProfileName; }
-
+ if ( profileName.equals("")){
+ log.error("Selected profile not initialized");
+ if (callback != null)
+ callback.result(new PumpEnactResult().success(false).comment(R.string.error_field_must_not_be_empty)).run();
+ return;
+ }
+ if ( ProfileFunctions.getInstance().getProfile() == null){
+ log.error("ProfileFunctions not initialized");
+ if (callback != null)
+ callback.result(new PumpEnactResult().success(false).comment(R.string.noprofile)).run();
+ return;
+ }
if (profileName.equals(activeProfileName)) {
- // Profile is already switched
+ if (L.isEnabled(L.AUTOMATION))
+ log.debug("Profile is already switched");
+ if (callback != null)
+ callback.result(new PumpEnactResult().success(true).comment(R.string.alreadyset)).run();
return;
}
ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
- if (activeProfile == null) return;
+ if (activeProfile == null) {
+ log.error("ProfileInterface not initialized");
+ if (callback != null)
+ callback.result(new PumpEnactResult().success(false).comment(R.string.noprofile)).run();
+ return;
+ }
ProfileStore profileStore = activeProfile.getProfile();
if (profileStore == null) return;
if(profileStore.getSpecificProfile(profileName) == null) {
if (L.isEnabled(L.AUTOMATION))
log.error("Selected profile does not exist! - "+ profileName);
+ if (callback != null)
+ callback.result(new PumpEnactResult().success(false).comment(R.string.notexists)).run();
return;
}
diff --git a/app/src/main/res/layout/automation_fragment.xml b/app/src/main/res/layout/automation_fragment.xml
index 2f24e1b70c..57ba8c60e0 100644
--- a/app/src/main/res/layout/automation_fragment.xml
+++ b/app/src/main/res/layout/automation_fragment.xml
@@ -18,6 +18,7 @@
android:id="@+id/automation_logView"
android:layout_width="match_parent"
android:layout_height="100dp"
+ android:scrollbars = "vertical"
android:layout_alignParentBottom="true" />
12h
24h
Automation event
+ Already set