ActionProfileSwitch, ActionFragment improvement

This commit is contained in:
Milos Kozak 2019-12-22 14:18:36 +01:00
parent 648b09717e
commit 06d2a2cfc5
5 changed files with 47 additions and 11 deletions

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.general.automation package info.nightscout.androidaps.plugins.general.automation
import android.os.Bundle import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup 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.EventAutomationDataChanged
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationUpdateGui
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.plusAssign import info.nightscout.androidaps.utils.plusAssign
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.automation_fragment.* import kotlinx.android.synthetic.main.automation_fragment.*
class AutomationFragment : Fragment(), OnStartDragListener { class AutomationFragment : Fragment(), OnStartDragListener {
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
@ -40,6 +41,8 @@ class AutomationFragment : Fragment(), OnStartDragListener {
automation_eventListView.layoutManager = LinearLayoutManager(context) automation_eventListView.layoutManager = LinearLayoutManager(context)
automation_eventListView.adapter = eventListAdapter automation_eventListView.adapter = eventListAdapter
automation_logView.setMovementMethod(ScrollingMovementMethod())
automation_fabAddEvent.setOnClickListener { automation_fabAddEvent.setOnClickListener {
val dialog = EditEventDialog() val dialog = EditEventDialog()
val args = Bundle() val args = Bundle()
@ -88,8 +91,8 @@ class AutomationFragment : Fragment(), OnStartDragListener {
eventListAdapter?.notifyDataSetChanged() eventListAdapter?.notifyDataSetChanged()
val sb = StringBuilder() val sb = StringBuilder()
for (l in AutomationPlugin.executionLog.reversed()) for (l in AutomationPlugin.executionLog.reversed())
sb.append(l).append("\n") sb.append(l).append("<br>")
automation_logView?.text = sb.toString() automation_logView?.text = HtmlHelper.fromHtml(sb.toString())
} }
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) { override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {

View file

@ -178,10 +178,10 @@ object AutomationPlugin : PluginBase(PluginDescription()
val sb = StringBuilder() val sb = StringBuilder()
sb.append(DateUtil.timeString(DateUtil.now())) sb.append(DateUtil.timeString(DateUtil.now()))
sb.append(" ") sb.append(" ")
sb.append(if (result.success) "" else "X") sb.append(if (result.success) "" else "")
sb.append(" ") sb.append(" <b>")
sb.append(event.title) sb.append(event.title)
sb.append(": ") sb.append(":</b> ")
sb.append(action.shortDescription()) sb.append(action.shortDescription())
sb.append(": ") sb.append(": ")
sb.append(result.comment) sb.append(result.comment)

View file

@ -26,13 +26,24 @@ import info.nightscout.androidaps.utils.JsonHelper;
public class ActionProfileSwitch extends Action { public class ActionProfileSwitch extends Action {
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION); private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
public InputProfileName inputProfileName = new InputProfileName(ProfileFunctions.getInstance().getProfileName()); InputProfileName inputProfileName;
String profileName = ""; String profileName = "";
public ActionProfileSwitch() { public ActionProfileSwitch() {
// Prevent action if active profile is already active // Prevent action if active profile is already active
// but we don't have a trigger IS_NOT_EQUAL // but we don't have a trigger IS_NOT_EQUAL
// so check is in the doRun() // 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 @Override
@ -51,19 +62,39 @@ public class ActionProfileSwitch extends Action {
String activeProfileName = ProfileFunctions.getInstance().getProfileName(); String activeProfileName = ProfileFunctions.getInstance().getProfileName();
//Check for uninitialized profileName //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)) { 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; return;
} }
ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface(); 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(); ProfileStore profileStore = activeProfile.getProfile();
if (profileStore == null) return; if (profileStore == null) return;
if(profileStore.getSpecificProfile(profileName) == null) { if(profileStore.getSpecificProfile(profileName) == null) {
if (L.isEnabled(L.AUTOMATION)) if (L.isEnabled(L.AUTOMATION))
log.error("Selected profile does not exist! - "+ profileName); log.error("Selected profile does not exist! - "+ profileName);
if (callback != null)
callback.result(new PumpEnactResult().success(false).comment(R.string.notexists)).run();
return; return;
} }

View file

@ -18,6 +18,7 @@
android:id="@+id/automation_logView" android:id="@+id/automation_logView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="100dp" android:layout_height="100dp"
android:scrollbars = "vertical"
android:layout_alignParentBottom="true" /> android:layout_alignParentBottom="true" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton

View file

@ -1690,5 +1690,6 @@
<string name="timeformat12h">12h</string> <string name="timeformat12h">12h</string>
<string name="timeformat24h">24h</string> <string name="timeformat24h">24h</string>
<string name="automation_event">Automation event</string> <string name="automation_event">Automation event</string>
<string name="alreadyset">Already set</string>
</resources> </resources>